Chromium Code Reviews| 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 #include "content/browser/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 base::FilePath exposed_dir_; | 53 base::FilePath exposed_dir_; |
| 54 }; | 54 }; |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 // We want to ensure there's only one utility thread running at a time, as there | 57 // We want to ensure there's only one utility thread running at a time, as there |
| 58 // are many globals used in the utility process. | 58 // are many globals used in the utility process. |
| 59 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; | 59 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; |
| 60 | 60 |
| 61 // Single process not supported in multiple dll mode currently. | |
| 62 #if !defined(CHROME_MULTIPLE_DLL) | |
| 61 class UtilityMainThread : public base::Thread { | 63 class UtilityMainThread : public base::Thread { |
| 62 public: | 64 public: |
| 63 UtilityMainThread(const std::string& channel_id) | 65 UtilityMainThread(const std::string& channel_id) |
| 64 : Thread("Chrome_InProcUtilityThread"), | 66 : Thread("Chrome_InProcUtilityThread"), |
| 65 channel_id_(channel_id) { | 67 channel_id_(channel_id) { |
| 66 } | 68 } |
| 67 | 69 |
| 68 virtual ~UtilityMainThread() { | 70 virtual ~UtilityMainThread() { |
| 69 Stop(); | 71 Stop(); |
| 70 } | 72 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 91 g_one_utility_thread_lock.Get().Acquire(); | 93 g_one_utility_thread_lock.Get().Acquire(); |
| 92 child_process_.reset(new ChildProcess()); | 94 child_process_.reset(new ChildProcess()); |
| 93 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_)); | 95 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_)); |
| 94 } | 96 } |
| 95 | 97 |
| 96 std::string channel_id_; | 98 std::string channel_id_; |
| 97 scoped_ptr<ChildProcess> child_process_; | 99 scoped_ptr<ChildProcess> child_process_; |
| 98 | 100 |
| 99 DISALLOW_COPY_AND_ASSIGN(UtilityMainThread); | 101 DISALLOW_COPY_AND_ASSIGN(UtilityMainThread); |
| 100 }; | 102 }; |
| 103 #endif // !CHROME_MULTIPLE_DLL | |
| 101 | 104 |
| 102 UtilityProcessHost* UtilityProcessHost::Create( | 105 UtilityProcessHost* UtilityProcessHost::Create( |
| 103 UtilityProcessHostClient* client, | 106 UtilityProcessHostClient* client, |
| 104 base::SequencedTaskRunner* client_task_runner) { | 107 base::SequencedTaskRunner* client_task_runner) { |
| 105 return new UtilityProcessHostImpl(client, client_task_runner); | 108 return new UtilityProcessHostImpl(client, client_task_runner); |
| 106 } | 109 } |
| 107 | 110 |
| 108 UtilityProcessHostImpl::UtilityProcessHostImpl( | 111 UtilityProcessHostImpl::UtilityProcessHostImpl( |
| 109 UtilityProcessHostClient* client, | 112 UtilityProcessHostClient* client, |
| 110 base::SequencedTaskRunner* client_task_runner) | 113 base::SequencedTaskRunner* client_task_runner) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 189 |
| 187 // Name must be set or metrics_service will crash in any test which | 190 // Name must be set or metrics_service will crash in any test which |
| 188 // launches a UtilityProcessHost. | 191 // launches a UtilityProcessHost. |
| 189 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 192 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
| 190 process_->SetName(ASCIIToUTF16("utility process")); | 193 process_->SetName(ASCIIToUTF16("utility process")); |
| 191 | 194 |
| 192 std::string channel_id = process_->GetHost()->CreateChannel(); | 195 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 193 if (channel_id.empty()) | 196 if (channel_id.empty()) |
| 194 return false; | 197 return false; |
| 195 | 198 |
| 199 // Multiple | |
|
jam
2013/07/23 15:19:36
nit: comment cut off?
scottmg
2013/07/23 15:33:15
wat
Done.
| |
| 200 #if !defined(CHROME_MULTIPLE_DLL) | |
| 196 if (RenderProcessHost::run_renderer_in_process()) { | 201 if (RenderProcessHost::run_renderer_in_process()) { |
| 197 // See comment in RenderProcessHostImpl::Init() for the background on why we | 202 // See comment in RenderProcessHostImpl::Init() for the background on why we |
| 198 // support single process mode this way. | 203 // support single process mode this way. |
| 199 in_process_thread_.reset(new UtilityMainThread(channel_id)); | 204 in_process_thread_.reset(new UtilityMainThread(channel_id)); |
| 200 in_process_thread_->Start(); | 205 in_process_thread_->Start(); |
| 201 } else { | 206 } else |
| 207 #endif // !CHROME_MULTIPLE_DLL | |
| 208 { | |
| 202 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 209 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 203 int child_flags = child_flags_; | 210 int child_flags = child_flags_; |
| 204 | 211 |
| 205 #if defined(OS_POSIX) | 212 #if defined(OS_POSIX) |
| 206 bool has_cmd_prefix = browser_command_line.HasSwitch( | 213 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 207 switches::kUtilityCmdPrefix); | 214 switches::kUtilityCmdPrefix); |
| 208 | 215 |
| 209 // When running under gdb, forking /proc/self/exe ends up forking the gdb | 216 // When running under gdb, forking /proc/self/exe ends up forking the gdb |
| 210 // executable instead of Chromium. It is almost safe to assume that no | 217 // executable instead of Chromium. It is almost safe to assume that no |
| 211 // updates will happen while a developer is running with | 218 // updates will happen while a developer is running with |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 } | 289 } |
| 283 | 290 |
| 284 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 291 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
| 285 client_task_runner_->PostTask( | 292 client_task_runner_->PostTask( |
| 286 FROM_HERE, | 293 FROM_HERE, |
| 287 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 294 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
| 288 exit_code)); | 295 exit_code)); |
| 289 } | 296 } |
| 290 | 297 |
| 291 } // namespace content | 298 } // namespace content |
| OLD | NEW |