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 "chrome/service/cloud_print/cloud_print_proxy.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
12 #include "base/process/launch.h" | 12 #include "base/process/launch.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/cloud_print/cloud_print_constants.h" | 15 #include "chrome/common/cloud_print/cloud_print_constants.h" |
16 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" | 16 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/service/cloud_print/print_system.h" | 18 #include "chrome/service/cloud_print/print_system.h" |
19 #include "chrome/service/service_process.h" | 19 #include "chrome/service/service_process.h" |
20 #include "chrome/service/service_process_prefs.h" | 20 #include "chrome/service/service_process_prefs.h" |
21 #include "google_apis/gaia/gaia_oauth_client.h" | 21 #include "google_apis/gaia/gaia_oauth_client.h" |
22 #include "google_apis/google_api_keys.h" | 22 #include "google_apis/google_api_keys.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 namespace { | |
26 | |
27 #if !defined(OS_MACOSX) | |
28 void LaunchBrowserProcessWithSwitch(const std::string& switch_string) { | |
29 DCHECK(g_service_process->io_thread()->message_loop_proxy()-> | |
30 BelongsToCurrentThread()); | |
31 base::FilePath exe_path; | |
32 PathService::Get(base::FILE_EXE, &exe_path); | |
33 if (exe_path.empty()) { | |
34 NOTREACHED() << "Unable to get browser process binary name."; | |
35 } | |
36 base::CommandLine cmd_line(exe_path); | |
37 | |
38 // Propagate an explicit --user-data-dir value if one was given. The new | |
39 // browser process will pick up a policy override during initialization. | |
40 const base::CommandLine& process_command_line = | |
41 *base::CommandLine::ForCurrentProcess(); | |
42 base::FilePath user_data_dir = | |
43 process_command_line.GetSwitchValuePath(switches::kUserDataDir); | |
44 if (!user_data_dir.empty()) | |
45 cmd_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); | |
46 cmd_line.AppendSwitch(switch_string); | |
47 | |
48 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
49 base::Process process = base::LaunchProcess(cmd_line, base::LaunchOptions()); | |
50 if (process.IsValid()) | |
51 base::EnsureProcessGetsReaped(process.Pid()); | |
52 #else | |
53 base::LaunchOptions launch_options; | |
54 #if defined(OS_WIN) | |
55 launch_options.force_breakaway_from_job_ = true; | |
56 #endif // OS_WIN | |
57 base::LaunchProcess(cmd_line, launch_options); | |
58 #endif | |
59 } | |
60 | |
61 void CheckCloudPrintProxyPolicyInBrowser() { | |
62 LaunchBrowserProcessWithSwitch(switches::kCheckCloudPrintConnectorPolicy); | |
63 } | |
64 | |
65 #endif // !OS_MACOSX | |
66 | |
67 } // namespace | |
68 | |
69 namespace cloud_print { | 25 namespace cloud_print { |
70 | 26 |
71 CloudPrintProxy::CloudPrintProxy() | 27 CloudPrintProxy::CloudPrintProxy() |
72 : service_prefs_(NULL), | 28 : service_prefs_(NULL), |
73 client_(NULL), | 29 client_(NULL), |
74 enabled_(false) { | 30 enabled_(false) { |
75 } | 31 } |
76 | 32 |
77 CloudPrintProxy::~CloudPrintProxy() { | 33 CloudPrintProxy::~CloudPrintProxy() { |
78 DCHECK(CalledOnValidThread()); | 34 DCHECK(CalledOnValidThread()); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 return; | 165 return; |
210 PrintSystem::PrintSystemResult result = print_system->Init(); | 166 PrintSystem::PrintSystemResult result = print_system->Init(); |
211 if (!result.succeeded()) | 167 if (!result.succeeded()) |
212 return; | 168 return; |
213 printing::PrinterList printer_list; | 169 printing::PrinterList printer_list; |
214 print_system->EnumeratePrinters(&printer_list); | 170 print_system->EnumeratePrinters(&printer_list); |
215 for (size_t i = 0; i < printer_list.size(); ++i) | 171 for (size_t i = 0; i < printer_list.size(); ++i) |
216 printers->push_back(printer_list[i].printer_name); | 172 printers->push_back(printer_list[i].printer_name); |
217 } | 173 } |
218 | 174 |
219 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { | |
220 #if !defined(OS_MACOSX) | |
221 g_service_process->io_thread()->message_loop_proxy()->PostTask( | |
222 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); | |
223 #endif | |
224 } | |
225 | |
226 void CloudPrintProxy::OnAuthenticated( | 175 void CloudPrintProxy::OnAuthenticated( |
227 const std::string& robot_oauth_refresh_token, | 176 const std::string& robot_oauth_refresh_token, |
228 const std::string& robot_email, | 177 const std::string& robot_email, |
229 const std::string& user_email) { | 178 const std::string& user_email) { |
230 DCHECK(CalledOnValidThread()); | 179 DCHECK(CalledOnValidThread()); |
231 service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken, | 180 service_prefs_->SetString(prefs::kCloudPrintRobotRefreshToken, |
232 robot_oauth_refresh_token); | 181 robot_oauth_refresh_token); |
233 service_prefs_->SetString(prefs::kCloudPrintRobotEmail, | 182 service_prefs_->SetString(prefs::kCloudPrintRobotEmail, |
234 robot_email); | 183 robot_email); |
235 // If authenticating from a robot, the user email will be empty. | 184 // If authenticating from a robot, the user email will be empty. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 243 } |
295 | 244 |
296 void CloudPrintProxy::ShutdownBackend() { | 245 void CloudPrintProxy::ShutdownBackend() { |
297 DCHECK(CalledOnValidThread()); | 246 DCHECK(CalledOnValidThread()); |
298 if (backend_.get()) | 247 if (backend_.get()) |
299 backend_->Shutdown(); | 248 backend_->Shutdown(); |
300 backend_.reset(); | 249 backend_.reset(); |
301 } | 250 } |
302 | 251 |
303 } // namespace cloud_print | 252 } // namespace cloud_print |
OLD | NEW |