| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_HOST_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_ | 6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/process/launch.h" | 9 #include "base/process/launch.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/public/common/bind_interface_helpers.h" |
| 13 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "mojo/public/cpp/system/message_pipe.h" |
| 14 | 18 |
| 15 namespace base { | 19 namespace base { |
| 16 class FilePath; | 20 class FilePath; |
| 17 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
| 18 } | 22 } |
| 19 | 23 |
| 20 namespace service_manager { | |
| 21 class InterfaceProvider; | |
| 22 } | |
| 23 | |
| 24 namespace content { | 24 namespace content { |
| 25 class UtilityProcessHostClient; | 25 class UtilityProcessHostClient; |
| 26 struct ChildProcessData; | 26 struct ChildProcessData; |
| 27 | 27 |
| 28 // This class acts as the browser-side host to a utility child process. A | 28 // This class acts as the browser-side host to a utility child process. A |
| 29 // utility process is a short-lived process that is created to run a specific | 29 // utility process is a short-lived process that is created to run a specific |
| 30 // task. This class lives solely on the IO thread. | 30 // task. This class lives solely on the IO thread. |
| 31 // If you need a single method call in the process, use StartFooBar(p). | 31 // If you need a single method call in the process, use StartFooBar(p). |
| 32 // If you need multiple batches of work to be done in the process, use | 32 // If you need multiple batches of work to be done in the process, use |
| 33 // StartBatchMode(), then multiple calls to StartFooBar(p), then finish with | 33 // StartBatchMode(), then multiple calls to StartFooBar(p), then finish with |
| 34 // EndBatchMode(). | 34 // EndBatchMode(). |
| 35 // If you need to bind Mojo interfaces, use Start() to start the child | 35 // If you need to bind Mojo interfaces, use Start() to start the child |
| 36 // process and GetRemoteInterfaces() to get the utility process' | 36 // process and then call BindInterface(). |
| 37 // service_manager::InterfaceProvider. | |
| 38 // | 37 // |
| 39 // Note: If your class keeps a ptr to an object of this type, grab a weak ptr to | 38 // Note: If your class keeps a ptr to an object of this type, grab a weak ptr to |
| 40 // avoid a use after free since this object is deleted synchronously but the | 39 // avoid a use after free since this object is deleted synchronously but the |
| 41 // client notification is asynchronous. See http://crbug.com/108871. | 40 // client notification is asynchronous. See http://crbug.com/108871. |
| 42 class UtilityProcessHost : public IPC::Sender { | 41 class UtilityProcessHost : public IPC::Sender { |
| 43 public: | 42 public: |
| 44 // Used to create a utility process. |client| is optional. If supplied it will | 43 // Used to create a utility process. |client| is optional. If supplied it will |
| 45 // be notified of incoming messages from the utility process. | 44 // be notified of incoming messages from the utility process. |
| 46 // |client_task_runner| is required if |client| is supplied and is the task | 45 // |client_task_runner| is required if |client| is supplied and is the task |
| 47 // runner upon which |client| will be invoked. | 46 // runner upon which |client| will be invoked. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 75 // Returns information about the utility child process. | 74 // Returns information about the utility child process. |
| 76 virtual const ChildProcessData& GetData() = 0; | 75 virtual const ChildProcessData& GetData() = 0; |
| 77 | 76 |
| 78 #if defined(OS_POSIX) | 77 #if defined(OS_POSIX) |
| 79 virtual void SetEnv(const base::EnvironmentMap& env) = 0; | 78 virtual void SetEnv(const base::EnvironmentMap& env) = 0; |
| 80 #endif | 79 #endif |
| 81 | 80 |
| 82 // Starts the utility process. | 81 // Starts the utility process. |
| 83 virtual bool Start() = 0; | 82 virtual bool Start() = 0; |
| 84 | 83 |
| 85 // Returns the service_manager::InterfaceProvider the browser process can use | 84 // Bind an interface exposed by the utility process. |
| 86 // to bind | 85 virtual void BindInterface(const std::string& interface_name, |
| 87 // interfaces exposed to it from the utility process. | 86 mojo::ScopedMessagePipeHandle interface_pipe) = 0; |
| 88 virtual service_manager::InterfaceProvider* GetRemoteInterfaces() = 0; | |
| 89 | 87 |
| 90 // Set the name of the process to appear in the task manager. | 88 // Set the name of the process to appear in the task manager. |
| 91 virtual void SetName(const base::string16& name) = 0; | 89 virtual void SetName(const base::string16& name) = 0; |
| 92 }; | 90 }; |
| 93 | 91 |
| 94 }; // namespace content | 92 }; // namespace content |
| 95 | 93 |
| 96 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_ | 94 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_ |
| OLD | NEW |