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 "cloud_print/service/win/chrome_launcher.h" | 5 #include "cloud_print/service/win/chrome_launcher.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/process.h" | 13 #include "base/process.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
17 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
18 #include "base/win/scoped_process_information.h" | 18 #include "base/win/scoped_process_information.h" |
19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 22 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
23 #include "cloud_print/common/win/cloud_print_utils.h" | 23 #include "cloud_print/common/win/cloud_print_utils.h" |
24 #include "cloud_print/service/service_constants.h" | 24 #include "cloud_print/service/service_constants.h" |
| 25 #include "cloud_print/service/win/service_utils.h" |
25 #include "google_apis/gaia/gaia_urls.h" | 26 #include "google_apis/gaia/gaia_urls.h" |
26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
27 #include "net/base/url_util.h" | 28 #include "net/base/url_util.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const int kShutdownTimeoutMs = 30 * 1000; | 32 const int kShutdownTimeoutMs = 30 * 1000; |
32 const int kUsageUpdateTimeoutMs = 6 * 3600 * 1000; // 6 hours. | 33 const int kUsageUpdateTimeoutMs = 6 * 3600 * 1000; // 6 hours. |
33 | 34 |
34 static const char16 kAutoRunKeyPath[] = | 35 static const char16 kAutoRunKeyPath[] = |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void ChromeLauncher::Run() { | 177 void ChromeLauncher::Run() { |
177 const base::TimeDelta default_time_out = base::TimeDelta::FromSeconds(1); | 178 const base::TimeDelta default_time_out = base::TimeDelta::FromSeconds(1); |
178 const base::TimeDelta max_time_out = base::TimeDelta::FromHours(1); | 179 const base::TimeDelta max_time_out = base::TimeDelta::FromHours(1); |
179 | 180 |
180 for (base::TimeDelta time_out = default_time_out;; | 181 for (base::TimeDelta time_out = default_time_out;; |
181 time_out = std::min(time_out * 2, max_time_out)) { | 182 time_out = std::min(time_out * 2, max_time_out)) { |
182 base::FilePath chrome_path = chrome_launcher_support::GetAnyChromePath(); | 183 base::FilePath chrome_path = chrome_launcher_support::GetAnyChromePath(); |
183 | 184 |
184 if (!chrome_path.empty()) { | 185 if (!chrome_path.empty()) { |
185 CommandLine cmd(chrome_path); | 186 CommandLine cmd(chrome_path); |
186 CopySwitchesFromCurrent(&cmd); | 187 CopyChromeSwitchesFromCurrentProcess(&cmd); |
187 | 188 |
188 // Required switches. | 189 // Required switches. |
189 cmd.AppendSwitchASCII(switches::kProcessType, switches::kServiceProcess); | 190 cmd.AppendSwitchASCII(switches::kProcessType, switches::kServiceProcess); |
190 cmd.AppendSwitchPath(switches::kUserDataDir, user_data_); | 191 cmd.AppendSwitchPath(switches::kUserDataDir, user_data_); |
191 cmd.AppendSwitch(switches::kNoServiceAutorun); | 192 cmd.AppendSwitch(switches::kNoServiceAutorun); |
192 | 193 |
193 // Optional. | 194 // Optional. |
194 cmd.AppendSwitch(switches::kAutoLaunchAtStartup); | 195 cmd.AppendSwitch(switches::kAutoLaunchAtStartup); |
195 cmd.AppendSwitch(switches::kDisableBackgroundMode); | 196 cmd.AppendSwitch(switches::kDisableBackgroundMode); |
196 cmd.AppendSwitch(switches::kDisableDefaultApps); | 197 cmd.AppendSwitch(switches::kDisableDefaultApps); |
(...skipping 27 matching lines...) Expand all Loading... |
224 if (base::Time::Now() - started > base::TimeDelta::FromHours(1)) { | 225 if (base::Time::Now() - started > base::TimeDelta::FromHours(1)) { |
225 // Reset timeout because process worked long enough. | 226 // Reset timeout because process worked long enough. |
226 time_out = default_time_out; | 227 time_out = default_time_out; |
227 } | 228 } |
228 } | 229 } |
229 if (stop_event_.TimedWait(time_out)) | 230 if (stop_event_.TimedWait(time_out)) |
230 break; | 231 break; |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 void ChromeLauncher::CopySwitchesFromCurrent(CommandLine* destination) { | |
235 static const char* const kSwitchesToCopy[] = { | |
236 switches::kEnableLogging, | |
237 switches::kV, | |
238 }; | |
239 destination->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
240 kSwitchesToCopy, | |
241 arraysize(kSwitchesToCopy)); | |
242 } | |
243 | |
244 std::string ChromeLauncher::CreateServiceStateFile( | 235 std::string ChromeLauncher::CreateServiceStateFile( |
245 const std::string& proxy_id, | 236 const std::string& proxy_id, |
246 const std::vector<std::string>& printers) { | 237 const std::vector<std::string>& printers) { |
247 std::string result; | 238 std::string result; |
248 | 239 |
249 base::ScopedTempDir temp_user_data; | 240 base::ScopedTempDir temp_user_data; |
250 if (!temp_user_data.CreateUniqueTempDir()) { | 241 if (!temp_user_data.CreateUniqueTempDir()) { |
251 LOG(ERROR) << "Can't create temp dir."; | 242 LOG(ERROR) << "Can't create temp dir."; |
252 return result; | 243 return result; |
253 } | 244 } |
(...skipping 13 matching lines...) Expand all Loading... |
267 base::JSONWriter::Write(&printer_list, &printers_json); | 258 base::JSONWriter::Write(&printer_list, &printers_json); |
268 size_t written = file_util::WriteFile(printers_file, | 259 size_t written = file_util::WriteFile(printers_file, |
269 printers_json.c_str(), | 260 printers_json.c_str(), |
270 printers_json.size()); | 261 printers_json.size()); |
271 if (written != printers_json.size()) { | 262 if (written != printers_json.size()) { |
272 LOG(ERROR) << "Can't write file."; | 263 LOG(ERROR) << "Can't write file."; |
273 return result; | 264 return result; |
274 } | 265 } |
275 | 266 |
276 CommandLine cmd(chrome_path); | 267 CommandLine cmd(chrome_path); |
277 CopySwitchesFromCurrent(&cmd); | 268 CopyChromeSwitchesFromCurrentProcess(&cmd); |
278 cmd.AppendSwitchPath(switches::kUserDataDir, temp_user_data.path()); | 269 cmd.AppendSwitchPath(switches::kUserDataDir, temp_user_data.path()); |
279 cmd.AppendSwitchPath(switches::kCloudPrintSetupProxy, printers_file); | 270 cmd.AppendSwitchPath(switches::kCloudPrintSetupProxy, printers_file); |
280 cmd.AppendSwitch(switches::kNoServiceAutorun); | 271 cmd.AppendSwitch(switches::kNoServiceAutorun); |
281 | 272 |
282 // Optional. | 273 // Optional. |
283 cmd.AppendSwitch(switches::kDisableBackgroundMode); | 274 cmd.AppendSwitch(switches::kDisableBackgroundMode); |
284 cmd.AppendSwitch(switches::kDisableDefaultApps); | 275 cmd.AppendSwitch(switches::kDisableDefaultApps); |
285 cmd.AppendSwitch(switches::kDisableExtensions); | 276 cmd.AppendSwitch(switches::kDisableExtensions); |
286 cmd.AppendSwitch(switches::kDisableSync); | 277 cmd.AppendSwitch(switches::kDisableSync); |
287 cmd.AppendSwitch(switches::kNoDefaultBrowserCheck); | 278 cmd.AppendSwitch(switches::kNoDefaultBrowserCheck); |
(...skipping 16 matching lines...) Expand all Loading... |
304 | 295 |
305 std::string json; | 296 std::string json; |
306 if (!file_util::ReadFileToString( | 297 if (!file_util::ReadFileToString( |
307 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) { | 298 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) { |
308 return result; | 299 return result; |
309 } | 300 } |
310 | 301 |
311 return UpdateServiceState(json, proxy_id); | 302 return UpdateServiceState(json, proxy_id); |
312 } | 303 } |
313 | 304 |
OLD | NEW |