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

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

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 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
« no previous file with comments | « chrome/service/service_process.h ('k') | chrome/service/service_process_prefs.h » ('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/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/singleton.h" 12 #include "base/singleton.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/json_pref_store.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
21 #include "chrome/common/service_process_util.h" 20 #include "chrome/common/service_process_util.h"
22 #include "chrome/service/cloud_print/cloud_print_proxy.h" 21 #include "chrome/service/cloud_print/cloud_print_proxy.h"
23 #include "chrome/service/service_ipc_server.h" 22 #include "chrome/service/service_ipc_server.h"
23 #include "chrome/service/service_process_prefs.h"
24 #include "net/base/network_change_notifier.h" 24 #include "net/base/network_change_notifier.h"
25 25
26 #if defined(ENABLE_REMOTING) 26 #if defined(ENABLE_REMOTING)
27 #include "remoting/base/constants.h" 27 #include "remoting/base/constants.h"
28 #include "remoting/host/chromoting_host.h" 28 #include "remoting/host/chromoting_host.h"
29 #include "remoting/host/chromoting_host_context.h" 29 #include "remoting/host/chromoting_host_context.h"
30 #include "remoting/host/json_host_config.h" 30 #include "remoting/host/json_host_config.h"
31 #endif // defined(ENABLED_REMOTING) 31 #endif // defined(ENABLED_REMOTING)
32 32
33 ServiceProcess* g_service_process = NULL; 33 ServiceProcess* g_service_process = NULL;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 // See if we have been suppiled an LSID in the command line. This LSID will 90 // See if we have been suppiled an LSID in the command line. This LSID will
91 // override the credentials we use for Cloud Print. 91 // override the credentials we use for Cloud Print.
92 std::string lsid = command_line.GetSwitchValueASCII( 92 std::string lsid = command_line.GetSwitchValueASCII(
93 switches::kServiceAccountLsid); 93 switches::kServiceAccountLsid);
94 94
95 FilePath user_data_dir; 95 FilePath user_data_dir;
96 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 96 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
97 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); 97 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName);
98 service_prefs_.reset(new JsonPrefStore(pref_path, 98 service_prefs_.reset(
99 file_thread_->message_loop_proxy())); 99 new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy()));
100 service_prefs_->ReadPrefs(); 100 service_prefs_->ReadPrefs();
101 101
102 DictionaryValue* values = service_prefs_->prefs();
103 bool remoting_host_enabled = false; 102 bool remoting_host_enabled = false;
104 103
105 // For development, we allow forcing the enabling of the host daemon via a 104 // For development, we allow forcing the enabling of the host daemon via a
106 // commandline flag, regardless of the preference setting. 105 // commandline flag, regardless of the preference setting.
107 // 106 //
108 // TODO(ajwong): When we've gotten the preference setting workflow more 107 // TODO(ajwong): When we've gotten the preference setting workflow more
109 // stable, we should remove the command-line flag force-enable. 108 // stable, we should remove the command-line flag force-enable.
110 values->GetBoolean(prefs::kRemotingHostEnabled, &remoting_host_enabled); 109 service_prefs_->GetBoolean(prefs::kRemotingHostEnabled,
110 &remoting_host_enabled);
111 remoting_host_enabled |= command_line.HasSwitch(switches::kEnableRemoting); 111 remoting_host_enabled |= command_line.HasSwitch(switches::kEnableRemoting);
112 112
113 #if defined(ENABLE_REMOTING) 113 #if defined(ENABLE_REMOTING)
114 // Check if remoting host is already enabled. 114 // Check if remoting host is already enabled.
115 if (remoting_host_enabled) { 115 if (remoting_host_enabled) {
116 StartChromotingHost(); 116 StartChromotingHost();
117 } 117 }
118 #endif 118 #endif
119 119
120 // Enable Cloud Print if needed. First check the command-line. 120 // Enable Cloud Print if needed. First check the command-line.
121 bool cloud_print_proxy_enabled = 121 bool cloud_print_proxy_enabled =
122 command_line.HasSwitch(switches::kEnableCloudPrintProxy); 122 command_line.HasSwitch(switches::kEnableCloudPrintProxy);
123 if (!cloud_print_proxy_enabled) { 123 if (!cloud_print_proxy_enabled) {
124 // Then check if the cloud print proxy was previously enabled. 124 // Then check if the cloud print proxy was previously enabled.
125 values->GetBoolean(prefs::kCloudPrintProxyEnabled, 125 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled,
126 &cloud_print_proxy_enabled); 126 &cloud_print_proxy_enabled);
127 } 127 }
128 128
129 if (cloud_print_proxy_enabled) { 129 if (cloud_print_proxy_enabled) {
130 GetCloudPrintProxy()->EnableForUser(lsid); 130 GetCloudPrintProxy()->EnableForUser(lsid);
131 } 131 }
132 132
133 VLOG(1) << "Starting Service Process IPC Server"; 133 VLOG(1) << "Starting Service Process IPC Server";
134 ipc_server_.reset(new ServiceIPCServer(GetServiceProcessChannelName())); 134 ipc_server_.reset(new ServiceIPCServer(GetServiceProcessChannelName()));
135 ipc_server_->Init(); 135 ipc_server_->Init();
136 136
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { 185 CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
186 if (!cloud_print_proxy_.get()) { 186 if (!cloud_print_proxy_.get()) {
187 cloud_print_proxy_.reset(new CloudPrintProxy()); 187 cloud_print_proxy_.reset(new CloudPrintProxy());
188 cloud_print_proxy_->Initialize(service_prefs_.get(), this); 188 cloud_print_proxy_->Initialize(service_prefs_.get(), this);
189 } 189 }
190 return cloud_print_proxy_.get(); 190 return cloud_print_proxy_.get();
191 } 191 }
192 192
193 void ServiceProcess::OnCloudPrintProxyEnabled() { 193 void ServiceProcess::OnCloudPrintProxyEnabled() {
194 // Save the preference that we have enabled the cloud print proxy. 194 // Save the preference that we have enabled the cloud print proxy.
195 service_prefs_->prefs()->SetBoolean(prefs::kCloudPrintProxyEnabled, true); 195 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true);
196 service_prefs_->WritePrefs(); 196 service_prefs_->WritePrefs();
197 OnServiceEnabled(); 197 OnServiceEnabled();
198 } 198 }
199 199
200 void ServiceProcess::OnCloudPrintProxyDisabled() { 200 void ServiceProcess::OnCloudPrintProxyDisabled() {
201 // Save the preference that we have disabled the cloud print proxy. 201 // Save the preference that we have disabled the cloud print proxy.
202 service_prefs_->prefs()->SetBoolean(prefs::kCloudPrintProxyEnabled, false); 202 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false);
203 service_prefs_->WritePrefs(); 203 service_prefs_->WritePrefs();
204 OnServiceDisabled(); 204 OnServiceDisabled();
205 } 205 }
206 206
207 void ServiceProcess::OnServiceEnabled() { 207 void ServiceProcess::OnServiceEnabled() {
208 enabled_services_++; 208 enabled_services_++;
209 if (1 == enabled_services_) { 209 if (1 == enabled_services_) {
210 ServiceProcessState::GetInstance()->AddToAutoRun(); 210 ServiceProcessState::GetInstance()->AddToAutoRun();
211 } 211 }
212 } 212 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 talk_token_, 304 talk_token_,
305 remoting_directory_->host_id(), 305 remoting_directory_->host_id(),
306 remoting_directory_->host_name(), 306 remoting_directory_->host_name(),
307 remoting_directory_->host_key_pair()); 307 remoting_directory_->host_key_pair());
308 remoting_directory_.reset(); 308 remoting_directory_.reset();
309 remoting_login_ = ""; 309 remoting_login_ = "";
310 remoting_token_ = ""; 310 remoting_token_ = "";
311 talk_token_ = ""; 311 talk_token_ = "";
312 312
313 // Save the preference that we have enabled the remoting host. 313 // Save the preference that we have enabled the remoting host.
314 service_prefs_->prefs()->SetBoolean(prefs::kRemotingHostEnabled, true); 314 service_prefs_->SetBoolean(prefs::kRemotingHostEnabled, true);
315 315
316 // Force writing prefs to the disk. 316 // Force writing prefs to the disk.
317 service_prefs_->WritePrefs(); 317 service_prefs_->WritePrefs();
318 318
319 // TODO(hclam): If we have a problem we need to send an IPC message back 319 // TODO(hclam): If we have a problem we need to send an IPC message back
320 // to the client that started this. 320 // to the client that started this.
321 bool ret = StartChromotingHost(); 321 bool ret = StartChromotingHost();
322 DCHECK(ret); 322 DCHECK(ret);
323 } 323 }
324 324
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 #endif 388 #endif
389 389
390 ServiceProcess::~ServiceProcess() { 390 ServiceProcess::~ServiceProcess() {
391 Teardown(); 391 Teardown();
392 g_service_process = NULL; 392 g_service_process = NULL;
393 } 393 }
394 394
395 // Disable refcounting for runnable method because it is really not needed 395 // Disable refcounting for runnable method because it is really not needed
396 // when we post tasks on the main message loop. 396 // when we post tasks on the main message loop.
397 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); 397 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess);
OLDNEW
« no previous file with comments | « chrome/service/service_process.h ('k') | chrome/service/service_process_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698