Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_UTILITY_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_ |
| 6 #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/memory/weak_ptr.h" | |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/browser_child_process_host_delegate.h" | 17 #include "content/public/browser/browser_child_process_host_delegate.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 19 | 20 |
| 20 class BrowserChildProcessHostImpl; | 21 class BrowserChildProcessHostImpl; |
| 21 | 22 |
| 22 // This class acts as the browser-side host to a utility child process. A | 23 // This class acts as the browser-side host to a utility child process. A |
| 23 // utility process is a short-lived sandboxed process that is created to run | 24 // utility process is a short-lived sandboxed process that is created to run |
| 24 // a specific task. This class lives solely on the IO thread. | 25 // a specific task. This class lives solely on the IO thread. |
| 25 // If you need a single method call in the sandbox, use StartFooBar(p). | 26 // If you need a single method call in the sandbox, use StartFooBar(p). |
| 26 // If you need multiple batches of work to be done in the sandboxed process, | 27 // If you need multiple batches of work to be done in the sandboxed process, |
| 27 // use StartBatchMode(), then multiple calls to StartFooBar(p), | 28 // use StartBatchMode(), then multiple calls to StartFooBar(p), |
| 28 // then finish with EndBatchMode(). | 29 // then finish with EndBatchMode(). |
| 29 class CONTENT_EXPORT UtilityProcessHost | 30 class CONTENT_EXPORT UtilityProcessHost |
| 30 : public content::BrowserChildProcessHostDelegate, | 31 : public content::BrowserChildProcessHostDelegate, |
| 31 public IPC::Message::Sender { | 32 public IPC::Message::Sender, |
| 33 public base::SupportsWeakPtr<UtilityProcessHost> { | |
|
jam
2012/01/26 03:56:18
i dont think this is necessary. you can already ge
dgrogan
2012/01/26 04:17:39
Client::OnProcessCrashed is posted to the IO threa
jam
2012/01/26 05:17:00
ah, good point. There are other places that hang o
dgrogan
2012/01/26 23:17:58
Done.
| |
| 32 public: | 34 public: |
| 33 // An interface to be implemented by consumers of the utility process to | 35 // An interface to be implemented by consumers of the utility process to |
| 34 // get results back. All functions are called on the thread passed along | 36 // get results back. All functions are called on the thread passed along |
| 35 // to UtilityProcessHost. | 37 // to UtilityProcessHost. |
| 36 class CONTENT_EXPORT Client : public base::RefCountedThreadSafe<Client> { | 38 class CONTENT_EXPORT Client : public base::RefCountedThreadSafe<Client> { |
| 37 public: | 39 public: |
| 38 Client(); | 40 Client(); |
| 39 | 41 |
| 40 // Called when the process has crashed. | 42 // Called when the process has crashed. |
| 41 virtual void OnProcessCrashed(int exit_code); | 43 virtual void OnProcessCrashed(int exit_code); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 // Allow these methods to be overridden for tests. | 82 // Allow these methods to be overridden for tests. |
| 81 virtual FilePath GetUtilityProcessCmd(); | 83 virtual FilePath GetUtilityProcessCmd(); |
| 82 | 84 |
| 83 private: | 85 private: |
| 84 // Starts a process if necessary. Returns true if it succeeded or a process | 86 // Starts a process if necessary. Returns true if it succeeded or a process |
| 85 // has already been started via StartBatchMode(). | 87 // has already been started via StartBatchMode(). |
| 86 bool StartProcess(); | 88 bool StartProcess(); |
| 87 | 89 |
| 88 // BrowserChildProcessHost: | 90 // BrowserChildProcessHost: |
| 89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 91 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 90 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 92 virtual void OnProcessCrashedOrWasKilled(int exit_code) OVERRIDE; |
| 91 | 93 |
| 92 // A pointer to our client interface, who will be informed of progress. | 94 // A pointer to our client interface, who will be informed of progress. |
| 93 scoped_refptr<Client> client_; | 95 scoped_refptr<Client> client_; |
| 94 content::BrowserThread::ID client_thread_id_; | 96 content::BrowserThread::ID client_thread_id_; |
| 95 // True when running in batch mode, i.e., StartBatchMode() has been called | 97 // True when running in batch mode, i.e., StartBatchMode() has been called |
| 96 // and the utility process will run until EndBatchMode(). | 98 // and the utility process will run until EndBatchMode(). |
| 97 bool is_batch_mode_; | 99 bool is_batch_mode_; |
| 98 | 100 |
| 99 // Allows a directory to be opened through the sandbox, in case it's needed by | 101 // Allows a directory to be opened through the sandbox, in case it's needed by |
| 100 // the operation. | 102 // the operation. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 114 base::environment_vector env_; | 116 base::environment_vector env_; |
| 115 | 117 |
| 116 bool started_; | 118 bool started_; |
| 117 | 119 |
| 118 scoped_ptr<BrowserChildProcessHostImpl> process_; | 120 scoped_ptr<BrowserChildProcessHostImpl> process_; |
| 119 | 121 |
| 120 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost); | 122 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost); |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_ | 125 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_ |
| OLD | NEW |