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

Side by Side Diff: chrome/browser/service/service_process_control.cc

Issue 3306001: Don't launch service process if it's already running (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: removed code Created 10 years, 3 months 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/service/service_process_control.h" 5 #include "chrome/browser/service/service_process_control.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ServiceProcessControl::ServiceProcessControl(Profile* profile, 84 ServiceProcessControl::ServiceProcessControl(Profile* profile,
85 ServiceProcessType type) 85 ServiceProcessType type)
86 : profile_(profile), 86 : profile_(profile),
87 type_(type), 87 type_(type),
88 message_handler_(NULL) { 88 message_handler_(NULL) {
89 } 89 }
90 90
91 ServiceProcessControl::~ServiceProcessControl() { 91 ServiceProcessControl::~ServiceProcessControl() {
92 } 92 }
93 93
94 void ServiceProcessControl::Connect(Task* task) { 94 void ServiceProcessControl::ConnectInternal(Task* task) {
95 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 95 // If the channel has already been established then we run the task
96 // and return.
96 if (channel_.get()) { 97 if (channel_.get()) {
97 task->Run(); 98 if (task) {
98 delete task; 99 task->Run();
100 delete task;
101 }
99 return; 102 return;
100 } 103 }
101 104
102 // Saves the task. 105 // Actually going to connect.
106 LOG(INFO) << "Connecting to Service Process IPC Server";
103 connect_done_task_.reset(task); 107 connect_done_task_.reset(task);
104 ConnectInternal();
105 }
106 108
107 void ServiceProcessControl::ConnectInternal() {
108 LOG(INFO) << "Connecting to Service Process IPC Server";
109 // Run the IPC channel on the shared IO thread. 109 // Run the IPC channel on the shared IO thread.
110 base::Thread* io_thread = g_browser_process->io_thread(); 110 base::Thread* io_thread = g_browser_process->io_thread();
111 111
112 // TODO(hclam): Determine the the channel id from profile and type. 112 // TODO(hclam): Determine the the channel id from profile and type.
113 // TODO(hclam): Handle error connecting to channel. 113 // TODO(hclam): Handle error connecting to channel.
114 const std::string channel_id = GetServiceProcessChannelName(type_); 114 const std::string channel_id = GetServiceProcessChannelName(type_);
115 channel_.reset( 115 channel_.reset(
116 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, NULL, 116 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, NULL,
117 io_thread->message_loop(), true, 117 io_thread->message_loop(), true,
118 g_browser_process->shutdown_event())); 118 g_browser_process->shutdown_event()));
119 channel_->set_sync_messages_with_no_timeout_allowed(false); 119 channel_->set_sync_messages_with_no_timeout_allowed(false);
120 } 120 }
121 121
122 void ServiceProcessControl::Launch(Task* task) { 122 void ServiceProcessControl::Launch(Task* task) {
123 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 123 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
124 if (channel_.get()) { 124
125 if (task) { 125 // If the service process is already running then connects to it.
126 task->Run(); 126 if (CheckServiceProcessRunning(kServiceProcessCloudPrint)) {
127 delete task; 127 ConnectInternal(task);
128 }
129 return; 128 return;
130 } 129 }
131 130
132 // A service process should have a different mechanism for starting, but now 131 // A service process should have a different mechanism for starting, but now
133 // we start it as if it is a child process. 132 // we start it as if it is a child process.
134 FilePath exe_path = ChildProcessHost::GetChildPath(true); 133 FilePath exe_path = ChildProcessHost::GetChildPath(true);
135 if (exe_path.empty()) { 134 if (exe_path.empty()) {
136 NOTREACHED() << "Unable to get service process binary name."; 135 NOTREACHED() << "Unable to get service process binary name.";
137 } 136 }
138 137
(...skipping 18 matching lines...) Expand all
157 156
158 // And then start the process asynchronously. 157 // And then start the process asynchronously.
159 launcher_ = new Launcher(this, cmd_line); 158 launcher_ = new Launcher(this, cmd_line);
160 launcher_->Run( 159 launcher_->Run(
161 NewRunnableMethod(this, &ServiceProcessControl::OnProcessLaunched, task)); 160 NewRunnableMethod(this, &ServiceProcessControl::OnProcessLaunched, task));
162 } 161 }
163 162
164 void ServiceProcessControl::OnProcessLaunched(Task* task) { 163 void ServiceProcessControl::OnProcessLaunched(Task* task) {
165 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 164 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
166 if (launcher_->launched()) { 165 if (launcher_->launched()) {
167 // Now use the launch task as the connect task.
168 connect_done_task_.reset(task);
169
170 // After we have successfully created the service process we try to connect 166 // After we have successfully created the service process we try to connect
171 // to it. The launch task is transfered to a connect task. 167 // to it. The launch task is transfered to a connect task.
172 ConnectInternal(); 168 ConnectInternal(task);
173 } else if (task) { 169 } else if (task) {
174 // If we don't have process handle that means launching the service process 170 // If we don't have process handle that means launching the service process
175 // has failed. 171 // has failed.
176 task->Run(); 172 task->Run();
177 delete task; 173 delete task;
178 } 174 }
179 175
180 // We don't need the launcher anymore. 176 // We don't need the launcher anymore.
181 launcher_ = NULL; 177 launcher_ = NULL;
182 } 178 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 bool ServiceProcessControl::EnableRemotingWithTokens( 222 bool ServiceProcessControl::EnableRemotingWithTokens(
227 const std::string& user, 223 const std::string& user,
228 const std::string& remoting_token, 224 const std::string& remoting_token,
229 const std::string& talk_token) { 225 const std::string& talk_token) {
230 return Send( 226 return Send(
231 new ServiceMsg_EnableRemotingWithTokens(user, remoting_token, 227 new ServiceMsg_EnableRemotingWithTokens(user, remoting_token,
232 talk_token)); 228 talk_token));
233 } 229 }
234 230
235 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl); 231 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl);
OLDNEW
« no previous file with comments | « chrome/browser/service/service_process_control.h ('k') | chrome/browser/service/service_process_control_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698