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/browser/printing/cloud_print/cloud_print_proxy_service.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 InvokeServiceTask( | 84 InvokeServiceTask( |
85 base::Bind(&CloudPrintProxyService::EnableCloudPrintProxy, | 85 base::Bind(&CloudPrintProxyService::EnableCloudPrintProxy, |
86 weak_factory_.GetWeakPtr(), lsid, email)); | 86 weak_factory_.GetWeakPtr(), lsid, email)); |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 void CloudPrintProxyService::EnableForUserWithRobot( | 90 void CloudPrintProxyService::EnableForUserWithRobot( |
91 const std::string& robot_auth_code, | 91 const std::string& robot_auth_code, |
92 const std::string& robot_email, | 92 const std::string& robot_email, |
93 const std::string& user_email, | 93 const std::string& user_email, |
94 bool connect_new_printers, | 94 const base::DictionaryValue& user_preferences) { |
95 const std::vector<std::string>& printer_blacklist) { | |
96 if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { | 95 if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
97 InvokeServiceTask( | 96 InvokeServiceTask( |
98 base::Bind(&CloudPrintProxyService::EnableCloudPrintProxyWithRobot, | 97 base::Bind(&CloudPrintProxyService::EnableCloudPrintProxyWithRobot, |
99 weak_factory_.GetWeakPtr(), robot_auth_code, robot_email, | 98 weak_factory_.GetWeakPtr(), robot_auth_code, robot_email, |
100 user_email, connect_new_printers, printer_blacklist)); | 99 user_email, base::Owned(user_preferences.DeepCopy()))); |
101 } | 100 } |
102 } | 101 } |
103 | 102 |
104 void CloudPrintProxyService::DisableForUser() { | 103 void CloudPrintProxyService::DisableForUser() { |
105 InvokeServiceTask( | 104 InvokeServiceTask( |
106 base::Bind(&CloudPrintProxyService::DisableCloudPrintProxy, | 105 base::Bind(&CloudPrintProxyService::DisableCloudPrintProxy, |
107 weak_factory_.GetWeakPtr())); | 106 weak_factory_.GetWeakPtr())); |
108 } | 107 } |
109 | 108 |
110 bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { | 109 bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 DCHECK(process_control->IsConnected()); | 177 DCHECK(process_control->IsConnected()); |
179 process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid)); | 178 process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid)); |
180 // Assume the IPC worked. | 179 // Assume the IPC worked. |
181 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, email); | 180 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, email); |
182 } | 181 } |
183 | 182 |
184 void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( | 183 void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( |
185 const std::string& robot_auth_code, | 184 const std::string& robot_auth_code, |
186 const std::string& robot_email, | 185 const std::string& robot_email, |
187 const std::string& user_email, | 186 const std::string& user_email, |
188 bool connect_new_printers, | 187 const base::DictionaryValue* user_preferences) { |
189 const std::vector<std::string>& printer_blacklist) { | |
190 ServiceProcessControl* process_control = GetServiceProcessControl(); | 188 ServiceProcessControl* process_control = GetServiceProcessControl(); |
191 DCHECK(process_control->IsConnected()); | 189 DCHECK(process_control->IsConnected()); |
192 process_control->Send( | 190 process_control->Send( |
193 new ServiceMsg_EnableCloudPrintProxyWithRobot( | 191 new ServiceMsg_EnableCloudPrintProxyWithRobot( |
194 robot_auth_code, robot_email, user_email, connect_new_printers, | 192 robot_auth_code, robot_email, user_email, *user_preferences)); |
195 printer_blacklist)); | |
196 // Assume the IPC worked. | 193 // Assume the IPC worked. |
197 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); | 194 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); |
198 } | 195 } |
199 | 196 |
200 void CloudPrintProxyService::DisableCloudPrintProxy() { | 197 void CloudPrintProxyService::DisableCloudPrintProxy() { |
201 ServiceProcessControl* process_control = GetServiceProcessControl(); | 198 ServiceProcessControl* process_control = GetServiceProcessControl(); |
202 DCHECK(process_control->IsConnected()); | 199 DCHECK(process_control->IsConnected()); |
203 process_control->Send(new ServiceMsg_DisableCloudPrintProxy); | 200 process_control->Send(new ServiceMsg_DisableCloudPrintProxy); |
204 // Assume the IPC worked. | 201 // Assume the IPC worked. |
205 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 202 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
206 } | 203 } |
207 | 204 |
208 void CloudPrintProxyService::ProxyInfoCallback( | 205 void CloudPrintProxyService::ProxyInfoCallback( |
209 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 206 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
210 proxy_id_ = proxy_info.proxy_id; | 207 proxy_id_ = proxy_info.proxy_id; |
211 profile_->GetPrefs()->SetString( | 208 profile_->GetPrefs()->SetString( |
212 prefs::kCloudPrintEmail, | 209 prefs::kCloudPrintEmail, |
213 proxy_info.enabled ? proxy_info.email : std::string()); | 210 proxy_info.enabled ? proxy_info.email : std::string()); |
214 ApplyCloudPrintConnectorPolicy(); | 211 ApplyCloudPrintConnectorPolicy(); |
215 } | 212 } |
216 | 213 |
217 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { | 214 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |
218 GetServiceProcessControl()->Launch(task, base::Closure()); | 215 GetServiceProcessControl()->Launch(task, base::Closure()); |
219 return true; | 216 return true; |
220 } | 217 } |
221 | 218 |
222 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { | 219 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |
223 return ServiceProcessControl::GetInstance(); | 220 return ServiceProcessControl::GetInstance(); |
224 } | 221 } |
OLD | NEW |