Commit 7fdb94c2 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Remove static initializers in native_message_host_chromeos.cc.

Reduce the scope of |kBuiltInHost| so it is created on first use. Also
fix a bunch of nits in the file.

Bug: 537099
Change-Id: I5834a415fb26cd1b4cd071fbdb938453b1757d8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2430767Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811907}
parent cd8f50a4
......@@ -45,10 +45,10 @@ class EchoHost : public NativeMessageHost {
public:
static std::unique_ptr<NativeMessageHost> Create(
content::BrowserContext* browser_context) {
return std::unique_ptr<NativeMessageHost>(new EchoHost());
return std::make_unique<EchoHost>();
}
EchoHost() : message_number_(0), client_(NULL) {}
EchoHost() = default;
void Start(Client* client) override { client_ = client; }
......@@ -81,8 +81,8 @@ class EchoHost : public NativeMessageHost {
client_->PostMessageFromNativeHost(response_string);
}
int message_number_;
Client* client_;
int message_number_ = 0;
Client* client_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(EchoHost);
};
......@@ -112,24 +112,6 @@ const char* const kRemotingIt2MeOrigins[] = {
"chrome-extension://inomeogfingihgjfjlpeplalcfajhgai/",
"chrome-extension://hpodccmdligbeohchckkeajbfohibipg/"};
static const BuiltInHost kBuiltInHost[] = {
{"com.google.chrome.test.echo", // ScopedTestNativeMessagingHost::kHostName
kEchoHostOrigins, base::size(kEchoHostOrigins), &EchoHost::Create},
{"com.google.chrome.remote_assistance", kRemotingIt2MeOrigins,
base::size(kRemotingIt2MeOrigins), &CreateIt2MeHost},
{arc::ArcSupportMessageHost::kHostName,
arc::ArcSupportMessageHost::kHostOrigin, 1,
&arc::ArcSupportMessageHost::Create},
{chromeos::kWilcoDtcSupportdUiMessageHost,
chromeos::kWilcoDtcSupportdHostOrigins,
chromeos::kWilcoDtcSupportdHostOriginsSize,
&chromeos::CreateExtensionOwnedWilcoDtcSupportdMessageHost},
{drive::kDriveFsNativeMessageHostName,
drive::kDriveFsNativeMessageHostOrigins,
drive::kDriveFsNativeMessageHostOriginsSize,
&drive::CreateDriveFsNativeMessageHost},
};
bool MatchesSecurityOrigin(const BuiltInHost& host,
const std::string& extension_id) {
GURL origin(std::string(kExtensionScheme) + "://" + extension_id);
......@@ -151,10 +133,27 @@ std::unique_ptr<NativeMessageHost> NativeMessageHost::Create(
const std::string& native_host_name,
bool allow_user_level,
std::string* error) {
for (unsigned int i = 0; i < base::size(kBuiltInHost); i++) {
const BuiltInHost& host = kBuiltInHost[i];
std::string name(host.name);
if (name == native_host_name) {
static const BuiltInHost kBuiltInHosts[] = {
// ScopedTestNativeMessagingHost::kHostName
{"com.google.chrome.test.echo", kEchoHostOrigins,
base::size(kEchoHostOrigins), &EchoHost::Create},
{"com.google.chrome.remote_assistance", kRemotingIt2MeOrigins,
base::size(kRemotingIt2MeOrigins), &CreateIt2MeHost},
{arc::ArcSupportMessageHost::kHostName,
arc::ArcSupportMessageHost::kHostOrigin, 1,
&arc::ArcSupportMessageHost::Create},
{chromeos::kWilcoDtcSupportdUiMessageHost,
chromeos::kWilcoDtcSupportdHostOrigins,
chromeos::kWilcoDtcSupportdHostOriginsSize,
&chromeos::CreateExtensionOwnedWilcoDtcSupportdMessageHost},
{drive::kDriveFsNativeMessageHostName,
drive::kDriveFsNativeMessageHostOrigins,
drive::kDriveFsNativeMessageHostOriginsSize,
&drive::CreateDriveFsNativeMessageHost},
};
for (const BuiltInHost& host : kBuiltInHosts) {
if (host.name == native_host_name) {
if (MatchesSecurityOrigin(host, source_extension_id)) {
return (*host.create_function)(browser_context);
}
......
......@@ -37,7 +37,6 @@ _CROS_SI_FILE_ALLOWLIST = {
'iostream.cpp', # TODO(crbug.com/973554): Remove.
'spinlock.cc', # TODO(crbug.com/973556): Remove.
'int256.cc', # TODO(crbug.com/537099): Remove.
'native_message_host_chromeos.cc', # TODO(crbug.com/537099): Remove.
'protobuf_http_status.cc', # TODO(crbug.com/537099): Remove.
'rpc.pb.cc', # TODO(crbug.com/537099): Remove.
],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment