Updater: some minor code cleanups related to mojo usage. Bug: 1339108 Change-Id: If29aaba4cd84acbc846f2781d1c750e79a05a94c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4070126 Reviewed-by: Noah Rose Ledesma <noahrose@google.com> Commit-Queue: Joshua Pawlicki <waffles@chromium.org> Cr-Commit-Position: refs/heads/main@{#1080010}
diff --git a/chrome/updater/app/server/linux/update_service_stub.cc b/chrome/updater/app/server/linux/update_service_stub.cc index f8e0d7d..1edc8a17 100644 --- a/chrome/updater/app/server/linux/update_service_stub.cc +++ b/chrome/updater/app/server/linux/update_service_stub.cc
@@ -105,7 +105,7 @@ UpdateServiceStub::UpdateServiceStub(scoped_refptr<updater::UpdateService> impl, UpdaterScope scope) : server_( - GetActiveDutySocketPath(scope)->MaybeAsASCII(), + GetActiveDutySocketPath(scope).MaybeAsASCII(), named_mojo_ipc_server::NamedMojoIpcServerBase::kUseIsolatedConnection, this, base::BindRepeating(&IsTrustedIPCEndpoint)),
diff --git a/chrome/updater/ipc/ipc_names_linux.cc b/chrome/updater/ipc/ipc_names_linux.cc index d6bdc15..1813f68 100644 --- a/chrome/updater/ipc/ipc_names_linux.cc +++ b/chrome/updater/ipc/ipc_names_linux.cc
@@ -4,22 +4,15 @@ #include "chrome/updater/ipc/ipc_names.h" -#include "base/files/file_path.h" -#include "base/version.h" #include "chrome/updater/linux/ipc_constants.h" #include "chrome/updater/updater_scope.h" -#include "chrome/updater/updater_version.h" #include "mojo/public/cpp/platform/named_platform_channel.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace updater { mojo::NamedPlatformChannel::ServerName GetUpdateServiceInternalServerName( UpdaterScope scope) { - absl::optional<base::FilePath> socket = - GetActiveDutyInternalSocketPath(scope, base::Version(kUpdaterVersion)); - CHECK(socket); - return socket->MaybeAsASCII(); + return GetActiveDutyInternalSocketPath(scope).MaybeAsASCII(); } } // namespace updater
diff --git a/chrome/updater/ipc/ipc_names_mac.mm b/chrome/updater/ipc/ipc_names_mac.mm index 5bb17c8..9cc26a8 100644 --- a/chrome/updater/ipc/ipc_names_mac.mm +++ b/chrome/updater/ipc/ipc_names_mac.mm
@@ -4,16 +4,19 @@ #include "chrome/updater/ipc/ipc_names.h" -#include "base/strings/sys_string_conversions.h" -#import "chrome/updater/mac/xpc_service_names.h" +#include "base/strings/strcat.h" +#include "chrome/updater/updater_branding.h" #include "chrome/updater/updater_scope.h" +#include "chrome/updater/updater_version.h" #include "mojo/public/cpp/platform/named_platform_channel.h" namespace updater { mojo::NamedPlatformChannel::ServerName GetUpdateServiceInternalServerName( UpdaterScope scope) { - return base::SysNSStringToUTF8(GetUpdateServiceInternalMachName(scope)); + return base::StrCat( + {MAC_BUNDLE_IDENTIFIER_STRING ".update-internal.", kUpdaterVersion, + scope == UpdaterScope::kUser ? ".mach" : ".mach.system"}); } } // namespace updater
diff --git a/chrome/updater/linux/ipc_constants.cc b/chrome/updater/linux/ipc_constants.cc index fa82747..a6c8309 100644 --- a/chrome/updater/linux/ipc_constants.cc +++ b/chrome/updater/linux/ipc_constants.cc
@@ -5,50 +5,37 @@ #include "chrome/updater/linux/ipc_constants.h" #include "base/files/file_path.h" -#include "base/path_service.h" +#include "base/files/file_util.h" #include "base/strings/strcat.h" -#include "base/version.h" #include "chrome/updater/updater_branding.h" #include "chrome/updater/updater_scope.h" +#include "chrome/updater/updater_version.h" #include "third_party/abseil-cpp/absl/types/optional.h" namespace updater { namespace { -constexpr char kUserSocketsRelDir[] = - ".local/" COMPANY_SHORTNAME_STRING "/" PRODUCT_FULLNAME_STRING "/"; -constexpr char kSystemSocketsDir[] = - "/run/" COMPANY_SHORTNAME_STRING "/" PRODUCT_FULLNAME_STRING "/"; +constexpr base::FilePath::CharType kUserSocketsRelDir[] = FILE_PATH_LITERAL( + ".local/" COMPANY_SHORTNAME_STRING "/" PRODUCT_FULLNAME_STRING "/"); +constexpr base::FilePath::CharType kSystemSocketsDir[] = FILE_PATH_LITERAL( + "/run/" COMPANY_SHORTNAME_STRING "/" PRODUCT_FULLNAME_STRING "/"); -absl::optional<base::FilePath> GetSocketsDir(UpdaterScope scope) { - base::FilePath path; - switch (scope) { - case UpdaterScope::kUser: - if (!base::PathService::Get(base::DIR_HOME, &path)) { - return absl::nullopt; - } - return path.AppendASCII(kUserSocketsRelDir); - case UpdaterScope::kSystem: - return base::FilePath(kSystemSocketsDir); - } +base::FilePath GetSocketsDir(UpdaterScope scope) { + return scope == UpdaterScope::kSystem + ? base::FilePath(kSystemSocketsDir) + : base::GetHomeDir().Append(kUserSocketsRelDir); } } // namespace -absl::optional<base::FilePath> GetActiveDutySocketPath(UpdaterScope scope) { - absl::optional<base::FilePath> path = GetSocketsDir(scope); - return path ? absl::make_optional<base::FilePath>( - path->AppendASCII(PRODUCT_FULLNAME_STRING ".sk")) - : absl::nullopt; +base::FilePath GetActiveDutySocketPath(UpdaterScope scope) { + return GetSocketsDir(scope).Append( + FILE_PATH_LITERAL(PRODUCT_FULLNAME_STRING ".sk")); } -absl::optional<base::FilePath> GetActiveDutyInternalSocketPath( - UpdaterScope scope, - const base::Version& version) { - absl::optional<base::FilePath> path = GetSocketsDir(scope); - return path ? path->AppendASCII(base::StrCat( - {PRODUCT_FULLNAME_STRING, version.GetString(), ".sk"})) - : absl::optional<base::FilePath>(); +base::FilePath GetActiveDutyInternalSocketPath(UpdaterScope scope) { + return GetSocketsDir(scope).AppendASCII( + base::StrCat({PRODUCT_FULLNAME_STRING, kUpdaterVersion, ".sk"})); } } // namespace updater
diff --git a/chrome/updater/linux/ipc_constants.h b/chrome/updater/linux/ipc_constants.h index b07ff173..e76f7d90 100644 --- a/chrome/updater/linux/ipc_constants.h +++ b/chrome/updater/linux/ipc_constants.h
@@ -10,16 +10,13 @@ namespace base { class FilePath; -class Version; } // namespace base namespace updater { -absl::optional<base::FilePath> GetActiveDutySocketPath(UpdaterScope scope); +base::FilePath GetActiveDutySocketPath(UpdaterScope scope); -absl::optional<base::FilePath> GetActiveDutyInternalSocketPath( - UpdaterScope scope, - const base::Version& version); +base::FilePath GetActiveDutyInternalSocketPath(UpdaterScope scope); } // namespace updater
diff --git a/chrome/updater/linux/setup/setup.cc b/chrome/updater/linux/setup/setup.cc index 9138415..47f4dd96a 100644 --- a/chrome/updater/linux/setup/setup.cc +++ b/chrome/updater/linux/setup/setup.cc
@@ -12,7 +12,6 @@ #include "base/version.h" #include "chrome/updater/constants.h" #include "chrome/updater/linux/ipc_constants.h" -#include "chrome/updater/updater_version.h" #include "chrome/updater/util/posix_util.h" #include "chrome/updater/util/util.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -63,7 +62,7 @@ error = kErrorFailedToDeleteFolder; absl::optional<base::FilePath> versioned_socket = - GetActiveDutyInternalSocketPath(scope, base::Version(kUpdaterVersion)); + GetActiveDutyInternalSocketPath(scope); if (!versioned_socket || !base::DeleteFile(versioned_socket.value())) error = kErrorFailedToDeleteSocket;
diff --git a/chrome/updater/mac/xpc_service_names.h b/chrome/updater/mac/xpc_service_names.h index ac30482b..876e087 100644 --- a/chrome/updater/mac/xpc_service_names.h +++ b/chrome/updater/mac/xpc_service_names.h
@@ -16,21 +16,14 @@ namespace updater { std::string GetUpdateServiceLaunchdName(UpdaterScope scope); -std::string GetUpdateServiceInternalLaunchdName(UpdaterScope scope); base::ScopedCFTypeRef<CFStringRef> CopyUpdateServiceLaunchdName( UpdaterScope scope); base::ScopedCFTypeRef<CFStringRef> CopyWakeLaunchdName(UpdaterScope scope); -base::ScopedCFTypeRef<CFStringRef> CopyUpdateServiceInternalLaunchdName( - UpdaterScope scope); base::scoped_nsobject<NSString> GetUpdateServiceLaunchdLabel( UpdaterScope scope); base::scoped_nsobject<NSString> GetWakeLaunchdLabel(UpdaterScope scope); -base::scoped_nsobject<NSString> GetUpdateServiceInternalLaunchdLabel( - UpdaterScope scope); base::scoped_nsobject<NSString> GetUpdateServiceMachName(UpdaterScope scope); -base::scoped_nsobject<NSString> GetUpdateServiceInternalMachName( - UpdaterScope scope); } // namespace updater
diff --git a/chrome/updater/mac/xpc_service_names.mm b/chrome/updater/mac/xpc_service_names.mm index 5a21a61..59b0c68 100644 --- a/chrome/updater/mac/xpc_service_names.mm +++ b/chrome/updater/mac/xpc_service_names.mm
@@ -19,8 +19,6 @@ namespace { -const char kUpdateServiceInternalLaunchdPrefix[] = - MAC_BUNDLE_IDENTIFIER_STRING ".update-internal."; const char kUpdateServiceLaunchdName[] = MAC_BUNDLE_IDENTIFIER_STRING ".update"; const char kSystemLevelKeyword[] = ".system"; @@ -35,12 +33,6 @@ return GetNameWithScope(kUpdateServiceLaunchdName, scope); } -std::string GetUpdateServiceInternalLaunchdName(UpdaterScope scope) { - return GetNameWithScope( - base::StrCat({kUpdateServiceInternalLaunchdPrefix, kUpdaterVersion}), - scope); -} - base::ScopedCFTypeRef<CFStringRef> CopyUpdateServiceLaunchdName( UpdaterScope scope) { return base::SysUTF8ToCFStringRef(GetUpdateServiceLaunchdName(scope)); @@ -54,11 +46,6 @@ : base::StrCat({MAC_BUNDLE_IDENTIFIER_STRING ".wake"})); } -base::ScopedCFTypeRef<CFStringRef> CopyUpdateServiceInternalLaunchdName( - UpdaterScope scope) { - return base::SysUTF8ToCFStringRef(GetUpdateServiceInternalLaunchdName(scope)); -} - base::scoped_nsobject<NSString> GetUpdateServiceLaunchdLabel( UpdaterScope scope) { return base::scoped_nsobject<NSString>( @@ -70,12 +57,6 @@ base::mac::CFToNSCast(CopyWakeLaunchdName(scope).release())); } -base::scoped_nsobject<NSString> GetUpdateServiceInternalLaunchdLabel( - UpdaterScope scope) { - return base::scoped_nsobject<NSString>(base::mac::CFToNSCast( - CopyUpdateServiceInternalLaunchdName(scope).release())); -} - base::scoped_nsobject<NSString> GetUpdateServiceMachName( base::scoped_nsobject<NSString> name) { return base::scoped_nsobject<NSString>( @@ -86,9 +67,4 @@ return GetUpdateServiceMachName(GetUpdateServiceLaunchdLabel(scope)); } -base::scoped_nsobject<NSString> GetUpdateServiceInternalMachName( - UpdaterScope scope) { - return GetUpdateServiceMachName(GetUpdateServiceInternalLaunchdLabel(scope)); -} - } // namespace updater