| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/utility_process_host.h" | 17 #include "content/public/browser/utility_process_host.h" |
| 17 #include "content/public/browser/utility_process_host_client.h" | 18 #include "content/public/browser/utility_process_host_client.h" |
| 18 #include "mojo/public/cpp/bindings/interface_ptr.h" | 19 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 19 #include "services/service_manager/public/cpp/interface_provider.h" | 20 #include "services/service_manager/public/cpp/interface_provider.h" |
| 20 | 21 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 ~UtilityProcessMojoClient() { | 36 ~UtilityProcessMojoClient() { |
| 36 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, helper_.release()); | 37 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, helper_.release()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 // Sets the error callback. A valid callback must be set before calling | 40 // Sets the error callback. A valid callback must be set before calling |
| 40 // Start(). | 41 // Start(). |
| 41 void set_error_callback(const base::Closure& on_error_callback) { | 42 void set_error_callback(const base::Closure& on_error_callback) { |
| 42 on_error_callback_ = on_error_callback; | 43 on_error_callback_ = on_error_callback; |
| 43 } | 44 } |
| 44 | 45 |
| 46 // Allows a directory to be opened through the sandbox. |
| 47 void set_exposed_directory(const base::FilePath& directory) { |
| 48 DCHECK(!start_called_); |
| 49 helper_->set_exposed_directory(directory); |
| 50 } |
| 51 |
| 45 // Disables the sandbox in the utility process. | 52 // Disables the sandbox in the utility process. |
| 46 void set_disable_sandbox() { | 53 void set_disable_sandbox() { |
| 47 DCHECK(!start_called_); | 54 DCHECK(!start_called_); |
| 48 helper_->set_disable_sandbox(); | 55 helper_->set_disable_sandbox(); |
| 49 } | 56 } |
| 50 | 57 |
| 51 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 52 // Allow the utility process to run with elevated privileges. | 59 // Allow the utility process to run with elevated privileges. |
| 53 void set_run_elevated() { | 60 void set_run_elevated() { |
| 54 DCHECK(!start_called_); | 61 DCHECK(!start_called_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 102 |
| 96 // Starts the utility process on the IO thread. | 103 // Starts the utility process on the IO thread. |
| 97 void Start(const std::string& mojo_interface_name, | 104 void Start(const std::string& mojo_interface_name, |
| 98 mojo::ScopedMessagePipeHandle interface_pipe) { | 105 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 99 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
| 100 BrowserThread::IO, FROM_HERE, | 107 BrowserThread::IO, FROM_HERE, |
| 101 base::Bind(&Helper::StartOnIOThread, base::Unretained(this), | 108 base::Bind(&Helper::StartOnIOThread, base::Unretained(this), |
| 102 mojo_interface_name, base::Passed(&interface_pipe))); | 109 mojo_interface_name, base::Passed(&interface_pipe))); |
| 103 } | 110 } |
| 104 | 111 |
| 112 void set_exposed_directory(const base::FilePath& directory) { |
| 113 exposed_directory_ = directory; |
| 114 } |
| 115 |
| 105 void set_disable_sandbox() { disable_sandbox_ = true; } | 116 void set_disable_sandbox() { disable_sandbox_ = true; } |
| 106 | 117 |
| 107 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 108 void set_run_elevated() { | 119 void set_run_elevated() { |
| 109 disable_sandbox_ = true; | 120 disable_sandbox_ = true; |
| 110 run_elevated_ = true; | 121 run_elevated_ = true; |
| 111 } | 122 } |
| 112 #endif // defined(OS_WIN) | 123 #endif // defined(OS_WIN) |
| 113 | 124 |
| 114 private: | 125 private: |
| 115 // Starts the utility process and connects to the remote Mojo service. | 126 // Starts the utility process and connects to the remote Mojo service. |
| 116 void StartOnIOThread(const std::string& mojo_interface_name, | 127 void StartOnIOThread(const std::string& mojo_interface_name, |
| 117 mojo::ScopedMessagePipeHandle interface_pipe) { | 128 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 119 | 130 |
| 120 utility_host_ = UtilityProcessHost::Create(nullptr, nullptr)->AsWeakPtr(); | 131 utility_host_ = UtilityProcessHost::Create(nullptr, nullptr)->AsWeakPtr(); |
| 121 utility_host_->SetName(process_name_); | 132 utility_host_->SetName(process_name_); |
| 122 | 133 |
| 134 if (!exposed_directory_.empty()) |
| 135 utility_host_->SetExposedDir(exposed_directory_); |
| 136 |
| 123 if (disable_sandbox_) | 137 if (disable_sandbox_) |
| 124 utility_host_->DisableSandbox(); | 138 utility_host_->DisableSandbox(); |
| 125 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 126 if (run_elevated_) { | 140 if (run_elevated_) { |
| 127 DCHECK(disable_sandbox_); | 141 DCHECK(disable_sandbox_); |
| 128 utility_host_->ElevatePrivileges(); | 142 utility_host_->ElevatePrivileges(); |
| 129 } | 143 } |
| 130 #endif // defined(OS_WIN) | 144 #endif // defined(OS_WIN) |
| 131 | 145 |
| 132 utility_host_->Start(); | 146 utility_host_->Start(); |
| 133 | 147 |
| 134 utility_host_->GetRemoteInterfaces()->GetInterface( | 148 utility_host_->GetRemoteInterfaces()->GetInterface( |
| 135 mojo_interface_name, std::move(interface_pipe)); | 149 mojo_interface_name, std::move(interface_pipe)); |
| 136 } | 150 } |
| 137 | 151 |
| 138 // Properties of the utility process. | 152 // Properties of the utility process. |
| 139 base::string16 process_name_; | 153 base::string16 process_name_; |
| 154 base::FilePath exposed_directory_; |
| 140 bool disable_sandbox_ = false; | 155 bool disable_sandbox_ = false; |
| 141 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 142 bool run_elevated_ = false; | 157 bool run_elevated_ = false; |
| 143 #endif // defined(OS_WIN) | 158 #endif // defined(OS_WIN) |
| 144 | 159 |
| 145 // Must only be accessed on the IO thread. | 160 // Must only be accessed on the IO thread. |
| 146 base::WeakPtr<UtilityProcessHost> utility_host_; | 161 base::WeakPtr<UtilityProcessHost> utility_host_; |
| 147 | 162 |
| 148 DISALLOW_COPY_AND_ASSIGN(Helper); | 163 DISALLOW_COPY_AND_ASSIGN(Helper); |
| 149 }; | 164 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 | 175 |
| 161 // Checks that this class is always accessed from the same thread. | 176 // Checks that this class is always accessed from the same thread. |
| 162 base::ThreadChecker thread_checker_; | 177 base::ThreadChecker thread_checker_; |
| 163 | 178 |
| 164 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient); | 179 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient); |
| 165 }; | 180 }; |
| 166 | 181 |
| 167 } // namespace content | 182 } // namespace content |
| 168 | 183 |
| 169 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 184 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
| OLD | NEW |