diff --git a/chrome/app/BUILD.gn b/chrome/app/BUILD.gn
index 8896752d5b9faa..0ec8d4d949ede6 100644
--- a/chrome/app/BUILD.gn
+++ b/chrome/app/BUILD.gn
@@ -406,6 +406,10 @@ if (is_chromeos) {
[ "//chrome/browser/chromeos:ash_pref_connector_manifest" ]
}
+if (is_win) {
+ chrome_packaged_services += [ "//chrome/services/util_win:manifest" ]
+}
+
if (!is_android) {
chrome_packaged_services += [ "//chrome/utility:profile_import_manifest" ]
}
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 59974568b2d376..56ade3236133e9 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -11068,8 +11068,8 @@ read aloud to screenreader users to announce that a completion is available.">
-
- Shell Handler
+
+ Windows Utilities
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 2a917ee9fa96a2..1f5dc0de5037cd 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -2794,6 +2794,7 @@ split_static_library("browser") {
"//chrome/common:metrics_constants_util_win",
"//chrome/common:version_header",
"//chrome/install_static:install_static_util",
+ "//chrome/services/util_win/public/interfaces",
"//chrome_elf:blacklist",
"//chrome_elf:constants",
"//chrome_elf:dll_hash",
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 96753cb748ddcc..adc1c11a37c8a2 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -6,6 +6,7 @@ include_rules = [
"+chrome/grit",
"+chrome/install_static",
"+chrome/installer/util",
+ "+chrome/services/util_win/public/interfaces",
"+chrome_elf/blacklist",
"+chrome_elf/chrome_elf_constants.h",
"+chrome_elf/dll_hash",
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 865a0b98bd4771..2bdf4a2c552685 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -243,6 +243,7 @@
#include "chrome/browser/chrome_browser_main_win.h"
#include "chrome/browser/conflicts/module_database_win.h"
#include "chrome/browser/conflicts/module_event_sink_impl_win.h"
+#include "chrome/services/util_win/public/interfaces/constants.mojom.h"
#include "sandbox/win/src/sandbox_policy.h"
#elif defined(OS_MACOSX)
#include "chrome/browser/chrome_browser_main_mac.h"
@@ -3100,6 +3101,11 @@ void ChromeContentBrowserClient::RegisterOutOfProcessServices(
l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME);
#endif
+#if defined(OS_WIN)
+ (*services)[chrome::mojom::kUtilWinServiceName] =
+ l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_UTILITY_WIN_NAME);
+#endif
+
#if BUILDFLAG(ENABLE_PACKAGE_MASH_SERVICES)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kMash))
mash_service_registry::RegisterOutOfProcessServices(services);
diff --git a/chrome/browser/chrome_content_browser_manifest_overlay.json b/chrome/browser/chrome_content_browser_manifest_overlay.json
index c37af284f4165a..5354400ca46d72 100644
--- a/chrome/browser/chrome_content_browser_manifest_overlay.json
+++ b/chrome/browser/chrome_content_browser_manifest_overlay.json
@@ -53,7 +53,8 @@
"ime_registrar",
"input_device_controller",
"window_manager"
- ]
+ ],
+ "util_win" : [ "shell_util_win" ]
}
},
"navigation:frame": {
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
index edf93084013d97..78880e1547932f 100644
--- a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
@@ -25,6 +25,8 @@
#include "chrome/browser/shell_integration.h"
#include "components/flags_ui/pref_service_flags_storage.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/service_manager_connection.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/touch/touch_device.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/screen.h"
@@ -463,9 +465,10 @@ void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar) {
// Records the pinned state of the current executable into a histogram. Should
// be called on a background thread, with low priority, to avoid slowing down
// startup.
-void RecordIsPinnedToTaskbarHistogram() {
+void RecordIsPinnedToTaskbarHistogram(
+ std::unique_ptr connector) {
shell_integration::win::GetIsPinnedToTaskbarState(
- base::Bind(&OnShellHandlerConnectionError),
+ std::move(connector), base::Bind(&OnShellHandlerConnectionError),
base::Bind(&OnIsPinnedToTaskbarResult));
}
#endif // defined(OS_WIN)
@@ -548,10 +551,14 @@ void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
// TODO(isherman): The delay below is currently needed to avoid (flakily)
// breaking some tests, including all of the ProcessMemoryMetricsEmitterTest
// tests. Figure out why there is a dependency and fix the tests.
+ service_manager::Connector* connector =
+ content::ServiceManagerConnection::GetForProcess()->GetConnector();
+
base::CreateSequencedTaskRunnerWithTraits(background_task_traits)
- ->PostDelayedTask(FROM_HERE,
- base::BindOnce(&RecordIsPinnedToTaskbarHistogram),
- base::TimeDelta::FromSeconds(45));
+ ->PostDelayedTask(
+ FROM_HERE,
+ base::BindOnce(&RecordIsPinnedToTaskbarHistogram, connector->Clone()),
+ base::TimeDelta::FromSeconds(45));
#endif // defined(OS_WIN)
display_count_ = display::Screen::GetScreen()->GetNumDisplays();
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics_unittest.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics_unittest.cc
index 5508b99dbbc1c7..d286ec752b8176 100644
--- a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics_unittest.cc
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics_unittest.cc
@@ -9,7 +9,8 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/test/histogram_tester.h"
-#include "base/test/scoped_task_environment.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_service_manager_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/screen.h"
#include "ui/display/test/test_screen.h"
@@ -34,7 +35,8 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
private:
// Provides a message loop and allows the use of the task scheduler
- base::test::ScopedTaskEnvironment scoped_task_environment_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ content::TestServiceManagerContext service_manager_context_;
// Dummy screen required by a ChromeBrowserMainExtraPartsMetrics test target.
display::test::TestScreen test_screen_;
@@ -42,8 +44,8 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsMetricsTest);
};
-ChromeBrowserMainExtraPartsMetricsTest::ChromeBrowserMainExtraPartsMetricsTest()
- : device_data_manager_test_api_() {
+ChromeBrowserMainExtraPartsMetricsTest::
+ ChromeBrowserMainExtraPartsMetricsTest() {
display::Screen::SetScreenInstance(&test_screen_);
}
diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc
index 9615c149e0fb81..2e35d4a350bbbb 100644
--- a/chrome/browser/shell_integration_win.cc
+++ b/chrome/browser/shell_integration_win.cc
@@ -54,8 +54,11 @@
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/scoped_user_protocol_entry.h"
#include "chrome/installer/util/shell_util.h"
+#include "chrome/services/util_win/public/interfaces/constants.mojom.h"
+#include "chrome/services/util_win/public/interfaces/shell_util_win.mojom.h"
#include "components/variations/variations_associated_data.h"
-#include "content/public/browser/utility_process_mojo_client.h"
+#include "content/public/common/service_manager_connection.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/l10n/l10n_util.h"
namespace shell_integration {
@@ -451,22 +454,29 @@ class OpenSystemSettingsHelper {
OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr;
// Helper class to determine if Chrome is pinned to the taskbar. Hides the
-// complexity of managing the lifetime of a UtilityProcessMojoClient.
+// complexity of managing the lifetime of the connection to the ChromeWinUtil
+// service.
class IsPinnedToTaskbarHelper {
public:
using ResultCallback = win::IsPinnedToTaskbarCallback;
using ErrorCallback = win::ConnectionErrorCallback;
- static void GetState(const ErrorCallback& error_callback,
+ static void GetState(std::unique_ptr connector,
+ const ErrorCallback& error_callback,
const ResultCallback& result_callback);
private:
- IsPinnedToTaskbarHelper(const ErrorCallback& error_callback,
+ IsPinnedToTaskbarHelper(std::unique_ptr connector,
+ const ErrorCallback& error_callback,
const ResultCallback& result_callback);
void OnConnectionError();
void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar);
- content::UtilityProcessMojoClient shell_handler_;
+ chrome::mojom::ShellUtilWinPtr shell_util_win_ptr_;
+ // The connector used to retrieve the Patch service. We can't simply use
+ // content::ServiceManagerConnection::GetForProcess()->GetConnector() as this
+ // is called on a background thread.
+ std::unique_ptr connector_;
ErrorCallback error_callback_;
ResultCallback result_callback_;
@@ -477,37 +487,38 @@ class IsPinnedToTaskbarHelper {
};
// static
-void IsPinnedToTaskbarHelper::GetState(const ErrorCallback& error_callback,
- const ResultCallback& result_callback) {
+void IsPinnedToTaskbarHelper::GetState(
+ std::unique_ptr connector,
+ const ErrorCallback& error_callback,
+ const ResultCallback& result_callback) {
// Self-deleting when the ShellHandler completes.
- new IsPinnedToTaskbarHelper(error_callback, result_callback);
+ new IsPinnedToTaskbarHelper(std::move(connector), error_callback,
+ result_callback);
}
IsPinnedToTaskbarHelper::IsPinnedToTaskbarHelper(
+ std::unique_ptr connector,
const ErrorCallback& error_callback,
const ResultCallback& result_callback)
- : shell_handler_(
- l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)),
+ : connector_(std::move(connector)),
error_callback_(error_callback),
result_callback_(result_callback) {
DCHECK(error_callback_);
DCHECK(result_callback_);
- // |shell_handler_| owns the callbacks and is guaranteed to be destroyed
+ connector_->BindInterface(chrome::mojom::kUtilWinServiceName,
+ &shell_util_win_ptr_);
+ // |shell_util_win_ptr_| owns the callbacks and is guaranteed to be destroyed
// before |this|, therefore making base::Unretained() safe to use.
- shell_handler_.set_error_callback(base::Bind(
+ shell_util_win_ptr_.set_connection_error_handler(base::Bind(
&IsPinnedToTaskbarHelper::OnConnectionError, base::Unretained(this)));
- shell_handler_.set_disable_sandbox();
- shell_handler_.Start();
-
- shell_handler_.service()->IsPinnedToTaskbar(
+ shell_util_win_ptr_->IsPinnedToTaskbar(
base::Bind(&IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult,
base::Unretained(this)));
}
void IsPinnedToTaskbarHelper::OnConnectionError() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
error_callback_.Run();
delete this;
}
@@ -744,9 +755,11 @@ void MigrateTaskbarPins() {
}
void GetIsPinnedToTaskbarState(
+ std::unique_ptr connector,
const ConnectionErrorCallback& on_error_callback,
const IsPinnedToTaskbarCallback& result_callback) {
- IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback);
+ IsPinnedToTaskbarHelper::GetState(std::move(connector), on_error_callback,
+ result_callback);
}
int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
diff --git a/chrome/browser/shell_integration_win.h b/chrome/browser/shell_integration_win.h
index 5be0e0d4261adc..f3e168a25580af 100644
--- a/chrome/browser/shell_integration_win.h
+++ b/chrome/browser/shell_integration_win.h
@@ -5,12 +5,17 @@
#ifndef CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_
#define CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_
+#include
#include
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"
+namespace service_manager {
+class Connector;
+}
+
namespace shell_integration {
namespace win {
@@ -62,9 +67,11 @@ base::string16 GetChromiumModelIdForProfile(const base::FilePath& profile_path);
// is true if Chrome is pinned to the taskbar.
// The ConnectionErrorCallback is called instead if something wrong happened
// with the connection to the remote process.
+// |connector| should be a fresh connector unbound to any thread.
using ConnectionErrorCallback = base::Closure;
using IsPinnedToTaskbarCallback = base::Callback;
void GetIsPinnedToTaskbarState(
+ std::unique_ptr connector,
const ConnectionErrorCallback& on_error_callback,
const IsPinnedToTaskbarCallback& result_callback);
diff --git a/chrome/browser/ui/webui/welcome_win10_handler.cc b/chrome/browser/ui/webui/welcome_win10_handler.cc
index bb74e7d667fc51..6c28c935a59720 100644
--- a/chrome/browser/ui/webui/welcome_win10_handler.cc
+++ b/chrome/browser/ui/webui/welcome_win10_handler.cc
@@ -15,6 +15,8 @@
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/service_manager_connection.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "url/gurl.h"
namespace {
@@ -43,6 +45,13 @@ void RecordPinnedResult(const std::string& histogram_suffix,
is_pinned);
}
+// Returns a new Connector that can be used on a different thread.
+std::unique_ptr GetClonedConnector() {
+ return content::ServiceManagerConnection::GetForProcess()
+ ->GetConnector()
+ ->Clone();
+}
+
} // namespace
WelcomeWin10Handler::WelcomeWin10Handler(bool inline_style_variant)
@@ -72,7 +81,8 @@ WelcomeWin10Handler::~WelcomeWin10Handler() {
base::Closure error_callback =
base::Bind(&RecordPinnedResult, histogram_suffix, false, false);
shell_integration::win::GetIsPinnedToTaskbarState(
- error_callback, base::Bind(&RecordPinnedResult, histogram_suffix));
+ GetClonedConnector(), error_callback,
+ base::Bind(&RecordPinnedResult, histogram_suffix));
}
}
@@ -139,7 +149,7 @@ void WelcomeWin10Handler::StartIsPinnedToTaskbarCheck() {
weak_ptr_factory_.GetWeakPtr(), false, true);
shell_integration::win::GetIsPinnedToTaskbarState(
- error_callback,
+ GetClonedConnector(), error_callback,
base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarResult,
weak_ptr_factory_.GetWeakPtr()));
}
diff --git a/chrome/browser/win/chrome_select_file_dialog_factory.cc b/chrome/browser/win/chrome_select_file_dialog_factory.cc
index 66f7e35eda7f24..76c666e3789774 100644
--- a/chrome/browser/win/chrome_select_file_dialog_factory.cc
+++ b/chrome/browser/win/chrome_select_file_dialog_factory.cc
@@ -14,9 +14,11 @@
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/win/win_util.h"
-#include "chrome/common/shell_handler_win.mojom.h"
#include "chrome/grit/generated_resources.h"
-#include "content/public/browser/utility_process_mojo_client.h"
+#include "chrome/services/util_win/public/interfaces/constants.mojom.h"
+#include "chrome/services/util_win/public/interfaces/shell_util_win.mojom.h"
+#include "content/public/common/service_manager_connection.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/win/open_file_name_win.h"
#include "ui/shell_dialogs/select_file_dialog_win.h"
@@ -27,23 +29,12 @@ namespace {
constexpr base::Feature kIsolateShellOperations{
"IsolateShellOperations", base::FEATURE_DISABLED_BY_DEFAULT};
-using UtilityProcessClient =
- content::UtilityProcessMojoClient;
-
-std::unique_ptr StartUtilityProcess() {
- auto utility_process_client = base::MakeUnique(
- l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_FILE_DIALOG_NAME));
-
- // TODO(crbug.com/618459): should we change the mojo utility client
- // to allow an empty error callback? Currently, the client DCHECKs
- // if no error callback is set when Start() is called.
- utility_process_client->set_error_callback(base::Bind(&base::DoNothing));
-
- utility_process_client->set_disable_sandbox();
-
- utility_process_client->Start();
-
- return utility_process_client;
+chrome::mojom::ShellUtilWinPtr BindShellUtilWin() {
+ chrome::mojom::ShellUtilWinPtr shell_util_win_ptr;
+ content::ServiceManagerConnection::GetForProcess()
+ ->GetConnector()
+ ->BindInterface(chrome::mojom::kUtilWinServiceName, &shell_util_win_ptr);
+ return shell_util_win_ptr;
}
} // namespace
@@ -66,13 +57,14 @@ bool ChromeSelectFileDialogFactory::BlockingGetOpenFileName(OPENFILENAME* ofn) {
if (!base::FeatureList::IsEnabled(kIsolateShellOperations))
return ::GetOpenFileName(ofn) == TRUE;
- auto utility_process_client = StartUtilityProcess();
-
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
std::vector files;
base::FilePath directory;
- utility_process_client->service()->CallGetOpenFileName(
+ // Sync operation, it's OK for the shell_util_win_ptr to go out of scope right
+ // after the call.
+ chrome::mojom::ShellUtilWinPtr shell_util_win_ptr = BindShellUtilWin();
+ shell_util_win_ptr->CallGetOpenFileName(
base::win::HandleToUint32(ofn->hwndOwner),
static_cast(ofn->Flags & ~OFN_ENABLEHOOK),
ui::win::OpenFileName::GetFilters(ofn),
@@ -92,13 +84,15 @@ bool ChromeSelectFileDialogFactory::BlockingGetSaveFileName(OPENFILENAME* ofn) {
if (!base::FeatureList::IsEnabled(kIsolateShellOperations))
return ::GetSaveFileName(ofn) == TRUE;
- auto utility_process_client = StartUtilityProcess();
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
uint32_t filter_index = 0;
base::FilePath path;
- utility_process_client->service()->CallGetSaveFileName(
+ // Sync operation, it's OK for the shell_util_win_ptr to go out of scope right
+ // after the call.
+ chrome::mojom::ShellUtilWinPtr shell_util_win_ptr = BindShellUtilWin();
+ shell_util_win_ptr->CallGetSaveFileName(
base::win::HandleToUint32(ofn->hwndOwner),
static_cast(ofn->Flags & ~OFN_ENABLEHOOK),
ui::win::OpenFileName::GetFilters(ofn), ofn->nFilterIndex,
diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn
index cf16d532a8d663..eaf3792c00dd23 100644
--- a/chrome/common/BUILD.gn
+++ b/chrome/common/BUILD.gn
@@ -681,10 +681,7 @@ mojom("mojo_bindings") {
]
if (is_win) {
- sources += [
- "conflicts/module_event_sink_win.mojom",
- "shell_handler_win.mojom",
- ]
+ sources += [ "conflicts/module_event_sink_win.mojom" ]
}
if (is_chromeos) {
diff --git a/chrome/services/DEPS b/chrome/services/DEPS
new file mode 100644
index 00000000000000..ea32aa34dfacd0
--- /dev/null
+++ b/chrome/services/DEPS
@@ -0,0 +1,9 @@
+include_rules = [
+ "+mojo", # By definition.
+
+ # Services have to list which other services they depend on.
+ "-chrome/services",
+ "-services",
+
+ "+services/service_manager/public", # Every service talks to Service Manager.
+]
diff --git a/chrome/services/OWNERS b/chrome/services/OWNERS
new file mode 100644
index 00000000000000..92c84d9e8a8357
--- /dev/null
+++ b/chrome/services/OWNERS
@@ -0,0 +1,2 @@
+jcivelli@chromium.org
+rockot@chromium.org
diff --git a/chrome/services/util_win/BUILD.gn b/chrome/services/util_win/BUILD.gn
new file mode 100644
index 00000000000000..0213b4d432132c
--- /dev/null
+++ b/chrome/services/util_win/BUILD.gn
@@ -0,0 +1,30 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//services/service_manager/public/cpp/service.gni")
+import("//services/service_manager/public/service_manifest.gni")
+
+source_set("lib") {
+ sources = [
+ "shell_util_win_impl.cc",
+ "shell_util_win_impl.h",
+ "util_win_service.cc",
+ "util_win_service.h",
+ ]
+
+ deps = [
+ "//base",
+ "//mojo/public/cpp/bindings",
+ ]
+
+ public_deps = [
+ "//chrome/services/util_win/public/interfaces",
+ "//services/service_manager/public/cpp",
+ ]
+}
+
+service_manifest("manifest") {
+ name = "util_win"
+ source = "manifest.json"
+}
diff --git a/chrome/services/util_win/DEPS b/chrome/services/util_win/DEPS
new file mode 100644
index 00000000000000..b3447e48906cb6
--- /dev/null
+++ b/chrome/services/util_win/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+chrome/installer/util/install_util.h",
+ "+content/public/utility/utility_thread.h",
+]
diff --git a/chrome/services/util_win/OWNERS b/chrome/services/util_win/OWNERS
new file mode 100644
index 00000000000000..75ed53504f4969
--- /dev/null
+++ b/chrome/services/util_win/OWNERS
@@ -0,0 +1,5 @@
+pmonette@chromium.org
+noel@chromium.org
+
+per-file manifest.json=set noparent
+per-file manifest.json=file://ipc/SECURITY_OWNERS
diff --git a/chrome/services/util_win/manifest.json b/chrome/services/util_win/manifest.json
new file mode 100644
index 00000000000000..4ecc1edd9dd367
--- /dev/null
+++ b/chrome/services/util_win/manifest.json
@@ -0,0 +1,15 @@
+{
+ "name": "util_win",
+ "display_name": "Windows Utilities",
+ "sandbox_type": "none",
+ "interface_provider_specs": {
+ "service_manager:connector": {
+ "provides": {
+ "shell_util_win": [ "chrome::mojom::ShellUtilWin" ]
+ },
+ "requires": {
+ "service_manager": [ "service_manager:all_users" ]
+ }
+ }
+ }
+}
diff --git a/chrome/services/util_win/public/interfaces/BUILD.gn b/chrome/services/util_win/public/interfaces/BUILD.gn
new file mode 100644
index 00000000000000..a194859f65caa5
--- /dev/null
+++ b/chrome/services/util_win/public/interfaces/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("interfaces") {
+ sources = [
+ "shell_util_win.mojom",
+ ]
+
+ public_deps = [
+ ":constants",
+ "//mojo/common:common_custom_types",
+ ]
+}
+
+mojom("constants") {
+ sources = [
+ "constants.mojom",
+ ]
+}
diff --git a/chrome/services/util_win/public/interfaces/OWNERS b/chrome/services/util_win/public/interfaces/OWNERS
new file mode 100644
index 00000000000000..d28aad2179498a
--- /dev/null
+++ b/chrome/services/util_win/public/interfaces/OWNERS
@@ -0,0 +1,5 @@
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
+
+per-file *.typemap=set noparent
+per-file *.typemap=file://ipc/SECURITY_OWNERS
diff --git a/chrome/services/util_win/public/interfaces/constants.mojom b/chrome/services/util_win/public/interfaces/constants.mojom
new file mode 100644
index 00000000000000..0da35f4a4c367a
--- /dev/null
+++ b/chrome/services/util_win/public/interfaces/constants.mojom
@@ -0,0 +1,7 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module chrome.mojom;
+
+const string kUtilWinServiceName = "util_win";
diff --git a/chrome/common/shell_handler_win.mojom b/chrome/services/util_win/public/interfaces/shell_util_win.mojom
similarity index 99%
rename from chrome/common/shell_handler_win.mojom
rename to chrome/services/util_win/public/interfaces/shell_util_win.mojom
index 099e084d9a6292..550418f755d013 100644
--- a/chrome/common/shell_handler_win.mojom
+++ b/chrome/services/util_win/public/interfaces/shell_util_win.mojom
@@ -10,7 +10,7 @@ module chrome.mojom;
import "mojo/common/file_path.mojom";
import "mojo/common/string16.mojom";
-interface ShellHandler {
+interface ShellUtilWin {
// Returns the pinned state of the current executable.
IsPinnedToTaskbar() => (bool succeeded, bool is_pinned_to_taskbar);
diff --git a/chrome/common/shell_handler_win.typemap b/chrome/services/util_win/public/interfaces/shell_util_win.typemap
similarity index 83%
rename from chrome/common/shell_handler_win.typemap
rename to chrome/services/util_win/public/interfaces/shell_util_win.typemap
index 0a596ac2113991..54edafac4723db 100644
--- a/chrome/common/shell_handler_win.typemap
+++ b/chrome/services/util_win/public/interfaces/shell_util_win.typemap
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-mojom = "//chrome/common/shell_handler_win.mojom"
+mojom = "//chrome/services/util_win/public/interfaces/shell_util_win.mojom"
public_headers = [ "//base/strings/string16.h" ]
diff --git a/chrome/utility/shell_handler_impl_win.cc b/chrome/services/util_win/shell_util_win_impl.cc
similarity index 89%
rename from chrome/utility/shell_handler_impl_win.cc
rename to chrome/services/util_win/shell_util_win_impl.cc
index 4572f94e7d83e6..639f10c09401d6 100644
--- a/chrome/utility/shell_handler_impl_win.cc
+++ b/chrome/services/util_win/shell_util_win_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/utility/shell_handler_impl_win.h"
+#include "chrome/services/util_win/shell_util_win_impl.h"
#include
#include
@@ -20,10 +20,11 @@
#include "base/win/shortcut.h"
#include "base/win/win_util.h"
#include "chrome/installer/util/install_util.h"
-#include "content/public/utility/utility_thread.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "ui/base/win/open_file_name_win.h"
+namespace chrome {
+
namespace {
// This class checks if the current executable is pinned to the taskbar. It also
@@ -205,6 +206,7 @@ bool IsPinnedToTaskbarHelper::GetResult() {
base::FileEnumerator::DIRECTORIES);
for (base::FilePath directory = directory_enum.Next(); !directory.empty();
directory = directory_enum.Next()) {
+ current_exe.value();
if (DirectoryContainsPinnedShortcutForProgram(directory,
current_exe_compare)) {
return true;
@@ -215,31 +217,25 @@ bool IsPinnedToTaskbarHelper::GetResult() {
} // namespace
-ShellHandlerImpl::ShellHandlerImpl() = default;
-
-ShellHandlerImpl::~ShellHandlerImpl() = default;
+ShellUtilWinImpl::ShellUtilWinImpl(
+ std::unique_ptr service_ref)
+ : service_ref_(std::move(service_ref)) {}
-// static
-void ShellHandlerImpl::Create(
- chrome::mojom::ShellHandlerRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique(),
- std::move(request));
-}
+ShellUtilWinImpl::~ShellUtilWinImpl() = default;
-void ShellHandlerImpl::IsPinnedToTaskbar(
- const IsPinnedToTaskbarCallback& callback) {
+void ShellUtilWinImpl::IsPinnedToTaskbar(IsPinnedToTaskbarCallback callback) {
IsPinnedToTaskbarHelper helper;
bool is_pinned_to_taskbar = helper.GetResult();
- callback.Run(!helper.error_occured(), is_pinned_to_taskbar);
+ std::move(callback).Run(!helper.error_occured(), is_pinned_to_taskbar);
}
-void ShellHandlerImpl::CallGetOpenFileName(
+void ShellUtilWinImpl::CallGetOpenFileName(
uint32_t owner,
uint32_t flags,
const std::vector>& filters,
const base::FilePath& initial_directory,
const base::FilePath& initial_filename,
- const CallGetOpenFileNameCallback& callback) {
+ CallGetOpenFileNameCallback callback) {
ui::win::OpenFileName open_file_name(
reinterpret_cast(base::win::Uint32ToHandle(owner)), flags);
@@ -252,13 +248,13 @@ void ShellHandlerImpl::CallGetOpenFileName(
open_file_name.GetResult(&directory, &files);
if (!files.empty()) {
- callback.Run(directory, files);
+ std::move(callback).Run(directory, files);
} else {
- callback.Run(base::FilePath(), std::vector());
+ std::move(callback).Run(base::FilePath(), std::vector());
}
}
-void ShellHandlerImpl::CallGetSaveFileName(
+void ShellUtilWinImpl::CallGetSaveFileName(
uint32_t owner,
uint32_t flags,
const std::vector>& filters,
@@ -266,7 +262,7 @@ void ShellHandlerImpl::CallGetSaveFileName(
const base::FilePath& initial_directory,
const base::FilePath& suggested_filename,
const base::string16& default_extension,
- const CallGetSaveFileNameCallback& callback) {
+ CallGetSaveFileNameCallback callback) {
ui::win::OpenFileName open_file_name(
reinterpret_cast(base::win::Uint32ToHandle(owner)), flags);
@@ -276,8 +272,9 @@ void ShellHandlerImpl::CallGetSaveFileName(
open_file_name.GetOPENFILENAME()->lpstrDefExt = default_extension.c_str();
if (::GetSaveFileName(open_file_name.GetOPENFILENAME())) {
- callback.Run(base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile),
- open_file_name.GetOPENFILENAME()->nFilterIndex);
+ std::move(callback).Run(
+ base::FilePath(open_file_name.GetOPENFILENAME()->lpstrFile),
+ open_file_name.GetOPENFILENAME()->nFilterIndex);
return;
}
@@ -285,5 +282,7 @@ void ShellHandlerImpl::CallGetSaveFileName(
if (DWORD error_code = ::CommDlgExtendedError())
NOTREACHED() << "::GetSaveFileName() failed: error code " << error_code;
- callback.Run(base::FilePath(), 0);
+ std::move(callback).Run(base::FilePath(), 0);
}
+
+} // namespace chrome
diff --git a/chrome/services/util_win/shell_util_win_impl.h b/chrome/services/util_win/shell_util_win_impl.h
new file mode 100644
index 00000000000000..5aebbb09a8989e
--- /dev/null
+++ b/chrome/services/util_win/shell_util_win_impl.h
@@ -0,0 +1,49 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_SERVICES_UTIL_WIN_SHELL_UTIL_WIN_IMPL_H_
+#define CHROME_SERVICES_UTIL_WIN_SHELL_UTIL_WIN_IMPL_H_
+
+#include "base/macros.h"
+#include "chrome/services/util_win/public/interfaces/shell_util_win.mojom.h"
+#include "services/service_manager/public/cpp/service_context_ref.h"
+
+namespace chrome {
+
+class ShellUtilWinImpl : public chrome::mojom::ShellUtilWin {
+ public:
+ explicit ShellUtilWinImpl(
+ std::unique_ptr service_ref);
+ ~ShellUtilWinImpl() override;
+
+ private:
+ // chrome::mojom::ShellUtilWin:
+ void IsPinnedToTaskbar(IsPinnedToTaskbarCallback callback) override;
+
+ void CallGetOpenFileName(
+ uint32_t owner,
+ uint32_t flags,
+ const std::vector>& filters,
+ const base::FilePath& initial_directory,
+ const base::FilePath& initial_filename,
+ CallGetOpenFileNameCallback callback) override;
+
+ void CallGetSaveFileName(
+ uint32_t owner,
+ uint32_t flags,
+ const std::vector>& filters,
+ uint32_t one_based_filter_index,
+ const base::FilePath& initial_directory,
+ const base::FilePath& suggested_filename,
+ const base::string16& default_extension,
+ CallGetSaveFileNameCallback callback) override;
+
+ const std::unique_ptr service_ref_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellUtilWinImpl);
+};
+
+} // namespace chrome
+
+#endif // CHROME_SERVICES_UTIL_WIN_SHELL_UTIL_WIN_IMPL_H_
diff --git a/chrome/services/util_win/util_win_service.cc b/chrome/services/util_win/util_win_service.cc
new file mode 100644
index 00000000000000..e64feedab0e880
--- /dev/null
+++ b/chrome/services/util_win/util_win_service.cc
@@ -0,0 +1,51 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/services/util_win/util_win_service.h"
+
+#include
+
+#include "build/build_config.h"
+#include "chrome/services/util_win/public/interfaces/shell_util_win.mojom.h"
+#include "chrome/services/util_win/shell_util_win_impl.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+
+namespace chrome {
+
+namespace {
+
+void OnShellUtilWinRequest(
+ service_manager::ServiceContextRefFactory* ref_factory,
+ chrome::mojom::ShellUtilWinRequest request) {
+ mojo::MakeStrongBinding(
+ std::make_unique(ref_factory->CreateRef()),
+ std::move(request));
+}
+
+} // namespace
+
+UtilWinService::UtilWinService() = default;
+
+UtilWinService::~UtilWinService() = default;
+
+std::unique_ptr UtilWinService::CreateService() {
+ return std::unique_ptr(new UtilWinService());
+}
+
+void UtilWinService::OnStart() {
+ ref_factory_ = std::make_unique(
+ base::Bind(&service_manager::ServiceContext::RequestQuit,
+ base::Unretained(context())));
+ registry_.AddInterface(
+ base::Bind(&OnShellUtilWinRequest, ref_factory_.get()));
+}
+
+void UtilWinService::OnBindInterface(
+ const service_manager::BindSourceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) {
+ registry_.BindInterface(interface_name, std::move(interface_pipe));
+}
+
+} // namespace chrome
diff --git a/chrome/services/util_win/util_win_service.h b/chrome/services/util_win/util_win_service.h
new file mode 100644
index 00000000000000..3283d8d2e3750a
--- /dev/null
+++ b/chrome/services/util_win/util_win_service.h
@@ -0,0 +1,39 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_SERVICES_UTIL_WIN_UTIL_WIN_SERVICE_H_
+#define CHROME_SERVICES_UTIL_WIN_UTIL_WIN_SERVICE_H_
+
+#include "services/service_manager/public/cpp/binder_registry.h"
+#include "services/service_manager/public/cpp/service_context.h"
+#include "services/service_manager/public/cpp/service_context_ref.h"
+
+namespace chrome {
+
+class UtilWinService : public service_manager::Service {
+ public:
+ ~UtilWinService() override;
+
+ // Factory method for creating the service.
+ static std::unique_ptr CreateService();
+
+ // Lifescycle events that occur after the service has started to spinup.
+ void OnStart() override;
+ void OnBindInterface(const service_manager::BindSourceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override;
+
+ private:
+ UtilWinService();
+
+ // State needed to manage service lifecycle and lifecycle of bound clients.
+ std::unique_ptr ref_factory_;
+ service_manager::BinderRegistry registry_;
+
+ DISALLOW_COPY_AND_ASSIGN(UtilWinService);
+};
+
+} // namespace chrome
+
+#endif // CHROME_SERVICES_UTIL_WIN_UTIL_WIN_SERVICE_H_
diff --git a/chrome/typemaps.gni b/chrome/typemaps.gni
index 79a9ff16a46547..99bfa2bdee387f 100644
--- a/chrome/typemaps.gni
+++ b/chrome/typemaps.gni
@@ -5,5 +5,5 @@
typemaps = [
"//chrome/common/search.typemap",
"//chrome/common/safe_browsing/safe_archive_analyzer.typemap",
- "//chrome/common/shell_handler_win.typemap",
+ "//chrome/services/util_win/public/interfaces/shell_util_win.typemap",
]
diff --git a/chrome/utility/BUILD.gn b/chrome/utility/BUILD.gn
index 874ac9f22a4eef..21da6dd170722f 100644
--- a/chrome/utility/BUILD.gn
+++ b/chrome/utility/BUILD.gn
@@ -18,8 +18,6 @@ static_library("utility") {
"cloud_print/bitmap_image.h",
"cloud_print/pwg_encoder.cc",
"cloud_print/pwg_encoder.h",
- "shell_handler_impl_win.cc",
- "shell_handler_impl_win.h",
"utility_message_handler.h",
]
@@ -135,6 +133,8 @@ static_library("utility") {
# Add ESE library for Edge Import support.
libs = [ "esent.lib" ]
ldflags += [ "/DELAYLOAD:esent.dll" ]
+
+ deps += [ "//chrome/services/util_win:lib" ]
}
if (is_win || is_mac) {
diff --git a/chrome/utility/DEPS b/chrome/utility/DEPS
index c31c46e9dd9c0c..a389f51e32b2b1 100644
--- a/chrome/utility/DEPS
+++ b/chrome/utility/DEPS
@@ -2,6 +2,8 @@ include_rules = [
"+chrome/grit",
"+chrome/installer/util",
"+chrome/profiling",
+ "+chrome/services/util_win/util_win_service.h",
+ "+chrome/services/util_win/public/interfaces",
"+components/font_service/font_service_app.h",
"+components/payments/content/utility",
"+components/printing/service/public/cpp",
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 20c22c6758f1b3..a7697d25579510 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -50,7 +50,8 @@
#endif
#if defined(OS_WIN)
-#include "chrome/utility/shell_handler_impl_win.h"
+#include "chrome/services/util_win/public/interfaces/constants.mojom.h"
+#include "chrome/services/util_win/util_win_service.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
@@ -281,6 +282,7 @@ void ChromeContentUtilityClient::UtilityThreadStarted() {
if (!utility_process_running_elevated_) {
registry->AddInterface(base::Bind(&FilePatcherImpl::Create),
base::ThreadTaskRunnerHandle::Get());
+
#if !defined(OS_ANDROID)
registry->AddInterface(base::Bind(CreateResourceUsageReporter),
base::ThreadTaskRunnerHandle::Get());
@@ -288,10 +290,7 @@ void ChromeContentUtilityClient::UtilityThreadStarted() {
base::Bind(&media_router::DialDeviceDescriptionParserImpl::Create),
base::ThreadTaskRunnerHandle::Get());
#endif // !defined(OS_ANDROID)
-#if defined(OS_WIN)
- registry->AddInterface(base::Bind(&ShellHandlerImpl::Create),
- base::ThreadTaskRunnerHandle::Get());
-#endif
+
#if defined(OS_CHROMEOS)
registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create),
base::ThreadTaskRunnerHandle::Get());
@@ -358,6 +357,14 @@ void ChromeContentUtilityClient::RegisterServices(
profile_import_info);
#endif
+#if defined(OS_WIN)
+ {
+ service_manager::EmbeddedServiceInfo service_info;
+ service_info.factory = base::Bind(&chrome::UtilWinService::CreateService);
+ services->emplace(chrome::mojom::kUtilWinServiceName, service_info);
+ }
+#endif
+
#if BUILDFLAG(ENABLE_PACKAGE_MASH_SERVICES)
RegisterMashServices(services);
#endif
diff --git a/chrome/utility/shell_handler_impl_win.h b/chrome/utility/shell_handler_impl_win.h
deleted file mode 100644
index a8e5170869af96..00000000000000
--- a/chrome/utility/shell_handler_impl_win.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_UTILITY_SHELL_HANDLER_IMPL_WIN_H_
-#define CHROME_UTILITY_SHELL_HANDLER_IMPL_WIN_H_
-
-#include "base/macros.h"
-#include "chrome/common/shell_handler_win.mojom.h"
-
-class ShellHandlerImpl : public chrome::mojom::ShellHandler {
- public:
- ShellHandlerImpl();
- ~ShellHandlerImpl() override;
-
- static void Create(chrome::mojom::ShellHandlerRequest request);
-
- private:
- // chrome::mojom::ShellHandler:
- void IsPinnedToTaskbar(const IsPinnedToTaskbarCallback& callback) override;
-
- void CallGetOpenFileName(
- uint32_t owner,
- uint32_t flags,
- const std::vector>& filters,
- const base::FilePath& initial_directory,
- const base::FilePath& initial_filename,
- const CallGetOpenFileNameCallback& callback) override;
-
- void CallGetSaveFileName(
- uint32_t owner,
- uint32_t flags,
- const std::vector>& filters,
- uint32_t one_based_filter_index,
- const base::FilePath& initial_directory,
- const base::FilePath& suggested_filename,
- const base::string16& default_extension,
- const CallGetSaveFileNameCallback& callback) override;
-
- DISALLOW_COPY_AND_ASSIGN(ShellHandlerImpl);
-};
-
-#endif // CHROME_UTILITY_SHELL_HANDLER_IMPL_WIN_H_