Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: content/browser/utility_process_host.cc

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/browser/utility_process_host.h" 5 #include "content/browser/utility_process_host.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/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "content/common/child_process_host.h"
12 #include "content/common/utility_messages.h" 13 #include "content/common/utility_messages.h"
13 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
15 #include "ipc/ipc_switches.h" 16 #include "ipc/ipc_switches.h"
16 #include "ui/base/ui_base_switches.h" 17 #include "ui/base/ui_base_switches.h"
17 #include "webkit/plugins/plugin_switches.h" 18 #include "webkit/plugins/plugin_switches.h"
18 19
19 using content::BrowserThread; 20 using content::BrowserThread;
20 21
21 UtilityProcessHost::Client::Client() { 22 UtilityProcessHost::Client::Client() {
(...skipping 11 matching lines...) Expand all
33 } 34 }
34 35
35 UtilityProcessHost::UtilityProcessHost(Client* client, 36 UtilityProcessHost::UtilityProcessHost(Client* client,
36 BrowserThread::ID client_thread_id) 37 BrowserThread::ID client_thread_id)
37 : BrowserChildProcessHost(content::PROCESS_TYPE_UTILITY), 38 : BrowserChildProcessHost(content::PROCESS_TYPE_UTILITY),
38 client_(client), 39 client_(client),
39 client_thread_id_(client_thread_id), 40 client_thread_id_(client_thread_id),
40 is_batch_mode_(false), 41 is_batch_mode_(false),
41 no_sandbox_(false), 42 no_sandbox_(false),
42 #if defined(OS_LINUX) 43 #if defined(OS_LINUX)
43 child_flags_(CHILD_ALLOW_SELF), 44 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF),
44 #else 45 #else
45 child_flags_(CHILD_NORMAL), 46 child_flags_(ChildProcessHost::CHILD_NORMAL),
46 #endif 47 #endif
47 started_(false) { 48 started_(false) {
48 } 49 }
49 50
50 UtilityProcessHost::~UtilityProcessHost() { 51 UtilityProcessHost::~UtilityProcessHost() {
51 DCHECK(!is_batch_mode_); 52 DCHECK(!is_batch_mode_);
52 } 53 }
53 54
54 bool UtilityProcessHost::Send(IPC::Message* message) { 55 bool UtilityProcessHost::Send(IPC::Message* message) {
55 if (!StartProcess()) 56 if (!StartProcess())
56 return false; 57 return false;
57 58
58 return BrowserChildProcessHost::Send(message); 59 return BrowserChildProcessHost::Send(message);
59 } 60 }
60 61
61 bool UtilityProcessHost::StartBatchMode() { 62 bool UtilityProcessHost::StartBatchMode() {
62 CHECK(!is_batch_mode_); 63 CHECK(!is_batch_mode_);
63 is_batch_mode_ = StartProcess(); 64 is_batch_mode_ = StartProcess();
64 Send(new UtilityMsg_BatchMode_Started()); 65 Send(new UtilityMsg_BatchMode_Started());
65 return is_batch_mode_; 66 return is_batch_mode_;
66 } 67 }
67 68
68 void UtilityProcessHost::EndBatchMode() { 69 void UtilityProcessHost::EndBatchMode() {
69 CHECK(is_batch_mode_); 70 CHECK(is_batch_mode_);
70 is_batch_mode_ = false; 71 is_batch_mode_ = false;
71 Send(new UtilityMsg_BatchMode_Finished()); 72 Send(new UtilityMsg_BatchMode_Finished());
72 } 73 }
73 74
74 FilePath UtilityProcessHost::GetUtilityProcessCmd() { 75 FilePath UtilityProcessHost::GetUtilityProcessCmd() {
75 return GetChildPath(child_flags_); 76 return ChildProcessHost::GetChildPath(child_flags_);
76 } 77 }
77 78
78 bool UtilityProcessHost::StartProcess() { 79 bool UtilityProcessHost::StartProcess() {
79 if (started_) 80 if (started_)
80 return true; 81 return true;
81 started_ = true; 82 started_ = true;
82 83
83 if (is_batch_mode_) 84 if (is_batch_mode_)
84 return true; 85 return true;
85 // Name must be set or metrics_service will crash in any test which 86 // Name must be set or metrics_service will crash in any test which
86 // launches a UtilityProcessHost. 87 // launches a UtilityProcessHost.
87 set_name(ASCIIToUTF16("utility process")); 88 set_name(ASCIIToUTF16("utility process"));
88 89
89 if (!CreateChannel()) 90 if (!child_process_host()->CreateChannel())
90 return false; 91 return false;
91 92
92 FilePath exe_path = GetUtilityProcessCmd(); 93 FilePath exe_path = GetUtilityProcessCmd();
93 if (exe_path.empty()) { 94 if (exe_path.empty()) {
94 NOTREACHED() << "Unable to get utility process binary name."; 95 NOTREACHED() << "Unable to get utility process binary name.";
95 return false; 96 return false;
96 } 97 }
97 98
98 CommandLine* cmd_line = new CommandLine(exe_path); 99 CommandLine* cmd_line = new CommandLine(exe_path);
99 cmd_line->AppendSwitchASCII(switches::kProcessType, 100 cmd_line->AppendSwitchASCII(switches::kProcessType,
100 switches::kUtilityProcess); 101 switches::kUtilityProcess);
101 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); 102 cmd_line->AppendSwitchASCII(switches::kProcessChannelID,
103 child_process_host()->channel_id());
102 std::string locale = 104 std::string locale =
103 content::GetContentClient()->browser()->GetApplicationLocale(); 105 content::GetContentClient()->browser()->GetApplicationLocale();
104 cmd_line->AppendSwitchASCII(switches::kLang, locale); 106 cmd_line->AppendSwitchASCII(switches::kLang, locale);
105 107
106 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 108 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
107 if (browser_command_line.HasSwitch(switches::kChromeFrame)) 109 if (browser_command_line.HasSwitch(switches::kChromeFrame))
108 cmd_line->AppendSwitch(switches::kChromeFrame); 110 cmd_line->AppendSwitch(switches::kChromeFrame);
109 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) 111 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox))
110 cmd_line->AppendSwitch(switches::kNoSandbox); 112 cmd_line->AppendSwitch(switches::kNoSandbox);
111 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) 113 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 base::IgnoreReturn<bool>( 146 base::IgnoreReturn<bool>(
145 base::Bind(&Client::OnMessageReceived, client_.get(), message))); 147 base::Bind(&Client::OnMessageReceived, client_.get(), message)));
146 return true; 148 return true;
147 } 149 }
148 150
149 void UtilityProcessHost::OnProcessCrashed(int exit_code) { 151 void UtilityProcessHost::OnProcessCrashed(int exit_code) {
150 BrowserThread::PostTask( 152 BrowserThread::PostTask(
151 client_thread_id_, FROM_HERE, 153 client_thread_id_, FROM_HERE,
152 base::Bind(&Client::OnProcessCrashed, client_.get(), exit_code)); 154 base::Bind(&Client::OnProcessCrashed, client_.get(), exit_code));
153 } 155 }
154
155 bool UtilityProcessHost::CanShutdown() {
156 return true;
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698