Commit d4b8905f authored by Jay Civelli's avatar Jay Civelli Committed by Commit Bot

Relanding "Servicifying ShellHandlerWin."

Relanding "Servicifying ShellHandlerWin.".
It was breaking the Windows build due to a left over include for a file
that does not exist anymore.

This reverts commit c52f5bd4.
BUG=777032
TBR=sky@chromium.org,pmonette@chromium.org,tsepez@chromium.org

Change-Id: I0f495649aed6091ff287852f813cc10917c4e7f8
Reviewed-on: https://chromium-review.googlesource.com/745984Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512868}
parent bafe7888
......@@ -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" ]
}
......
......@@ -11068,8 +11068,8 @@ read aloud to screenreader users to announce that a completion is available.">
</message>
<if expr="is_win">
<message name="IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME" desc="The name of the utility process used to handle shell operations.">
Shell Handler
<message name="IDS_UTILITY_PROCESS_UTILITY_WIN_NAME" desc="The name of the utility process used to handle Windows utility operations.">
Windows Utilities
</message>
</if>
......
......@@ -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",
......
......@@ -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",
......
......@@ -244,6 +244,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"
......@@ -3123,6 +3124,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);
......
......@@ -52,7 +52,8 @@
"ime_registrar",
"input_device_controller",
"window_manager"
]
],
"util_win" : [ "shell_util_win" ]
}
},
"navigation:frame": {
......
......@@ -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<service_manager::Connector> 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();
......
......@@ -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_);
}
......
......@@ -47,15 +47,17 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/shell_handler_win.mojom.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/install_static/install_util.h"
#include "chrome/installer/util/browser_distribution.h"
#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 +453,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<service_manager::Connector> connector,
const ErrorCallback& error_callback,
const ResultCallback& result_callback);
private:
IsPinnedToTaskbarHelper(const ErrorCallback& error_callback,
IsPinnedToTaskbarHelper(std::unique_ptr<service_manager::Connector> connector,
const ErrorCallback& error_callback,
const ResultCallback& result_callback);
void OnConnectionError();
void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar);
content::UtilityProcessMojoClient<chrome::mojom::ShellHandler> 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<service_manager::Connector> connector_;
ErrorCallback error_callback_;
ResultCallback result_callback_;
......@@ -477,37 +486,38 @@ class IsPinnedToTaskbarHelper {
};
// static
void IsPinnedToTaskbarHelper::GetState(const ErrorCallback& error_callback,
const ResultCallback& result_callback) {
void IsPinnedToTaskbarHelper::GetState(
std::unique_ptr<service_manager::Connector> 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<service_manager::Connector> 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 +754,11 @@ void MigrateTaskbarPins() {
}
void GetIsPinnedToTaskbarState(
std::unique_ptr<service_manager::Connector> 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,
......
......@@ -5,12 +5,17 @@
#ifndef CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_
#define CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_
#include <memory>
#include <string>
#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(bool, bool)>;
void GetIsPinnedToTaskbarState(
std::unique_ptr<service_manager::Connector> connector,
const ConnectionErrorCallback& on_error_callback,
const IsPinnedToTaskbarCallback& result_callback);
......
......@@ -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<service_manager::Connector> 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()));
}
......
......@@ -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<chrome::mojom::ShellHandler>;
std::unique_ptr<UtilityProcessClient> StartUtilityProcess() {
auto utility_process_client = base::MakeUnique<UtilityProcessClient>(
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<base::FilePath> 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<uint32_t>(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<uint32_t>(ofn->Flags & ~OFN_ENABLEHOOK),
ui::win::OpenFileName::GetFilters(ofn), ofn->nFilterIndex,
......
......@@ -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) {
......
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.
]
jcivelli@chromium.org
rockot@chromium.org
# 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"
}
include_rules = [
"+chrome/installer/util/install_util.h",
"+content/public/utility/utility_thread.h",
]
pmonette@chromium.org
noel@chromium.org
per-file manifest.json=set noparent
per-file manifest.json=file://ipc/SECURITY_OWNERS
{
"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" ]
}
}
}
}
# 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",
]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
// 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";
......@@ -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);
......
......@@ -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" ]
......
......@@ -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 <objbase.h>
#include <shldisp.h>
......@@ -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_manager::ServiceContextRef> service_ref)
: service_ref_(std::move(service_ref)) {}
// static
void ShellHandlerImpl::Create(
chrome::mojom::ShellHandlerRequest request) {
mojo::MakeStrongBinding(base::MakeUnique<ShellHandlerImpl>(),
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<std::tuple<base::string16, base::string16>>& filters,
const base::FilePath& initial_directory,
const base::FilePath& initial_filename,
const CallGetOpenFileNameCallback& callback) {
CallGetOpenFileNameCallback callback) {
ui::win::OpenFileName open_file_name(
reinterpret_cast<HWND>(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<base::FilePath>());
std::move(callback).Run(base::FilePath(), std::vector<base::FilePath>());
}
}
void ShellHandlerImpl::CallGetSaveFileName(
void ShellUtilWinImpl::CallGetSaveFileName(
uint32_t owner,
uint32_t flags,
const std::vector<std::tuple<base::string16, base::string16>>& 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<HWND>(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
......@@ -2,22 +2,24 @@
// 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_
#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/common/shell_handler_win.mojom.h"
#include "chrome/services/util_win/public/interfaces/shell_util_win.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
class ShellHandlerImpl : public chrome::mojom::ShellHandler {
public:
ShellHandlerImpl();
~ShellHandlerImpl() override;
namespace chrome {
static void Create(chrome::mojom::ShellHandlerRequest request);
class ShellUtilWinImpl : public chrome::mojom::ShellUtilWin {
public:
explicit ShellUtilWinImpl(
std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~ShellUtilWinImpl() override;
private:
// chrome::mojom::ShellHandler:
void IsPinnedToTaskbar(const IsPinnedToTaskbarCallback& callback) override;
// chrome::mojom::ShellUtilWin:
void IsPinnedToTaskbar(IsPinnedToTaskbarCallback callback) override;
void CallGetOpenFileName(
uint32_t owner,
......@@ -25,7 +27,7 @@ class ShellHandlerImpl : public chrome::mojom::ShellHandler {
const std::vector<std::tuple<base::string16, base::string16>>& filters,
const base::FilePath& initial_directory,
const base::FilePath& initial_filename,
const CallGetOpenFileNameCallback& callback) override;
CallGetOpenFileNameCallback callback) override;
void CallGetSaveFileName(
uint32_t owner,
......@@ -35,9 +37,13 @@ class ShellHandlerImpl : public chrome::mojom::ShellHandler {
const base::FilePath& initial_directory,
const base::FilePath& suggested_filename,
const base::string16& default_extension,
const CallGetSaveFileNameCallback& callback) override;
CallGetSaveFileNameCallback callback) override;
DISALLOW_COPY_AND_ASSIGN(ShellHandlerImpl);
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
DISALLOW_COPY_AND_ASSIGN(ShellUtilWinImpl);
};
#endif // CHROME_UTILITY_SHELL_HANDLER_IMPL_WIN_H_
} // namespace chrome
#endif // CHROME_SERVICES_UTIL_WIN_SHELL_UTIL_WIN_IMPL_H_
// 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 <memory>
#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<ShellUtilWinImpl>(ref_factory->CreateRef()),
std::move(request));
}
} // namespace
UtilWinService::UtilWinService() = default;
UtilWinService::~UtilWinService() = default;
std::unique_ptr<service_manager::Service> UtilWinService::CreateService() {
return std::unique_ptr<service_manager::Service>(new UtilWinService());
}
void UtilWinService::OnStart() {
ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>(
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
// 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<service_manager::Service> 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<service_manager::ServiceContextRefFactory> ref_factory_;
service_manager::BinderRegistry registry_;
DISALLOW_COPY_AND_ASSIGN(UtilWinService);
};
} // namespace chrome
#endif // CHROME_SERVICES_UTIL_WIN_UTIL_WIN_SERVICE_H_
......@@ -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",
]
......@@ -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) {
......
......@@ -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",
......
......@@ -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
......
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