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

Side by Side Diff: chrome/service/service_process.cc

Issue 3153029: Resubmit r56600 - Start/stop service process when browser starts and stop (Closed)
Patch Set: Created 10 years, 4 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
« no previous file with comments | « chrome/service/service_main.cc ('k') | chrome/test/in_process_browser_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/service/service_process.h" 5 #include "chrome/service/service_process.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h"
11 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/json_pref_store.h" 14 #include "chrome/common/json_pref_store.h"
15 #include "chrome/common/pref_names.h"
14 #include "chrome/common/service_process_type.h" 16 #include "chrome/common/service_process_type.h"
15 #include "chrome/common/service_process_util.h" 17 #include "chrome/common/service_process_util.h"
16 #include "chrome/service/cloud_print/cloud_print_proxy.h" 18 #include "chrome/service/cloud_print/cloud_print_proxy.h"
17 #include "chrome/service/service_ipc_server.h" 19 #include "chrome/service/service_ipc_server.h"
18 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
19 21
20 #if defined(ENABLE_REMOTING) 22 #if defined(ENABLE_REMOTING)
21 #include "remoting/base/constants.h" 23 #include "remoting/base/constants.h"
22 #include "remoting/base/encoder_zlib.h" 24 #include "remoting/base/encoder_zlib.h"
23 #include "remoting/host/chromoting_host.h" 25 #include "remoting/host/chromoting_host.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Teardown(); 60 Teardown();
59 return false; 61 return false;
60 } 62 }
61 FilePath user_data_dir; 63 FilePath user_data_dir;
62 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 64 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
63 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); 65 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName);
64 service_prefs_.reset(new JsonPrefStore(pref_path, 66 service_prefs_.reset(new JsonPrefStore(pref_path,
65 file_thread_->message_loop_proxy())); 67 file_thread_->message_loop_proxy()));
66 service_prefs_->ReadPrefs(); 68 service_prefs_->ReadPrefs();
67 69
70 DictionaryValue* values = service_prefs_->prefs();
71 bool remoting_host_enabled = false;
72
73 // Check if remoting host is already enabled.
74 if (values->GetBoolean(prefs::kRemotingHostEnabled, &remoting_host_enabled) &&
75 remoting_host_enabled) {
76 // If true then we start the host.
77 StartChromotingHost();
78 }
79
68 // TODO(hclam): Each type of service process should has it own instance of 80 // TODO(hclam): Each type of service process should has it own instance of
69 // process and thus channel, but now we have only one process for all types 81 // process and thus channel, but now we have only one process for all types
70 // so the type parameter doesn't matter now. 82 // so the type parameter doesn't matter now.
71 LOG(INFO) << "Starting Service Process IPC Server"; 83 LOG(INFO) << "Starting Service Process IPC Server";
72 ipc_server_.reset(new ServiceIPCServer( 84 ipc_server_.reset(new ServiceIPCServer(
73 GetServiceProcessChannelName(kServiceProcessCloudPrint))); 85 GetServiceProcessChannelName(kServiceProcessCloudPrint)));
74 ipc_server_->Init(); 86 ipc_server_->Init();
75 87
76 // After the IPC server has started we can create the lock file to indicate 88 // After the IPC server has started we can create the lock file to indicate
77 // that we have started. 89 // that we have started.
78 bool ret = CreateServiceProcessLockFile(kServiceProcessCloudPrint); 90 bool ret = CreateServiceProcessLockFile(kServiceProcessCloudPrint);
79 DCHECK(ret) << "Failed to create service process lock file."; 91 DCHECK(ret) << "Failed to create service process lock file.";
80 return ret; 92 return ret;
81 } 93 }
82 94
83 bool ServiceProcess::Teardown() { 95 bool ServiceProcess::Teardown() {
84 // TODO(hclam): Remove this as this looks like dead code.
85 if (service_prefs_.get()) { 96 if (service_prefs_.get()) {
86 service_prefs_->WritePrefs(); 97 service_prefs_->WritePrefs();
87 service_prefs_.reset(); 98 service_prefs_.reset();
88 } 99 }
89 cloud_print_proxy_.reset(); 100 cloud_print_proxy_.reset();
90 101
91 #if defined(ENABLE_REMOTING) 102 #if defined(ENABLE_REMOTING)
92 ShutdownChromotingHost(); 103 ShutdownChromotingHost();
93 #endif 104 #endif
94 105
(...skipping 30 matching lines...) Expand all
125 bool ServiceProcess::EnableChromotingHostWithTokens( 136 bool ServiceProcess::EnableChromotingHostWithTokens(
126 const std::string& login, 137 const std::string& login,
127 const std::string& remoting_token, 138 const std::string& remoting_token,
128 const std::string& talk_token) { 139 const std::string& talk_token) {
129 // Save the login info and tokens. 140 // Save the login info and tokens.
130 remoting_login_ = login; 141 remoting_login_ = login;
131 remoting_token_ = remoting_token; 142 remoting_token_ = remoting_token;
132 talk_token_ = talk_token; 143 talk_token_ = talk_token;
133 144
134 // Use the remoting directory to register the host. 145 // Use the remoting directory to register the host.
146 if (remoting_directory_.get())
147 remoting_directory_->CancelRequest();
135 remoting_directory_.reset(new RemotingDirectoryService(this)); 148 remoting_directory_.reset(new RemotingDirectoryService(this));
136 remoting_directory_->AddHost(remoting_token); 149 remoting_directory_->AddHost(remoting_token);
137 return true; 150 return true;
138 } 151 }
139 152
140 bool ServiceProcess::StartChromotingHost() { 153 bool ServiceProcess::StartChromotingHost() {
141 // We have already started. 154 // We have already started.
142 if (chromoting_context_.get()) 155 if (chromoting_context_.get())
143 return true; 156 return true;
144 157
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 SaveChromotingConfig(remoting_login_, 213 SaveChromotingConfig(remoting_login_,
201 talk_token_, 214 talk_token_,
202 remoting_directory_->host_id(), 215 remoting_directory_->host_id(),
203 remoting_directory_->host_name(), 216 remoting_directory_->host_name(),
204 remoting_directory_->host_key_pair()); 217 remoting_directory_->host_key_pair());
205 remoting_directory_.reset(); 218 remoting_directory_.reset();
206 remoting_login_ = ""; 219 remoting_login_ = "";
207 remoting_token_ = ""; 220 remoting_token_ = "";
208 talk_token_ = ""; 221 talk_token_ = "";
209 222
223 // Save the preference that we have enabled the remoting host.
224 service_prefs_->prefs()->SetBoolean(prefs::kRemotingHostEnabled, true);
225
226 // Force writing prefs to the disk.
227 service_prefs_->WritePrefs();
228
210 // TODO(hclam): If we have a problem we need to send an IPC message back 229 // TODO(hclam): If we have a problem we need to send an IPC message back
211 // to the client that started this. 230 // to the client that started this.
212 bool ret = StartChromotingHost(); 231 bool ret = StartChromotingHost();
213 DCHECK(ret); 232 DCHECK(ret);
214 } 233 }
215 234
216 void ServiceProcess::OnRemotingDirectoryError() { 235 void ServiceProcess::OnRemotingDirectoryError() {
217 remoting_directory_.reset(); 236 remoting_directory_.reset();
218 remoting_login_ = ""; 237 remoting_login_ = "";
219 remoting_token_ = ""; 238 remoting_token_ = "";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 #endif 295 #endif
277 296
278 ServiceProcess::~ServiceProcess() { 297 ServiceProcess::~ServiceProcess() {
279 Teardown(); 298 Teardown();
280 g_service_process = NULL; 299 g_service_process = NULL;
281 } 300 }
282 301
283 // Disable refcounting for runnable method because it is really not needed 302 // Disable refcounting for runnable method because it is really not needed
284 // when we post tasks on the main message loop. 303 // when we post tasks on the main message loop.
285 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); 304 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess);
OLDNEW
« no previous file with comments | « chrome/service/service_main.cc ('k') | chrome/test/in_process_browser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698