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" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (client_) { | 136 if (client_) { |
137 client_->OnCloudPrintProxyEnabled(true); | 137 client_->OnCloudPrintProxyEnabled(true); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 bool CloudPrintProxy::CreateBackend() { | 141 bool CloudPrintProxy::CreateBackend() { |
142 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
143 if (backend_.get()) | 143 if (backend_.get()) |
144 return false; | 144 return false; |
145 | 145 |
146 settings_.InitFrom(service_prefs_); | 146 ConnectorSettings settings; |
| 147 settings.InitFrom(service_prefs_); |
147 | 148 |
148 // By default we don't poll for jobs when we lose XMPP connection. But this | 149 // By default we don't poll for jobs when we lose XMPP connection. But this |
149 // behavior can be overridden by a preference. | 150 // behavior can be overridden by a preference. |
150 bool enable_job_poll = | 151 bool enable_job_poll = |
151 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); | 152 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); |
152 | 153 |
153 gaia::OAuthClientInfo oauth_client_info; | 154 gaia::OAuthClientInfo oauth_client_info; |
154 oauth_client_info.client_id = | 155 oauth_client_info.client_id = |
155 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); | 156 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); |
156 oauth_client_info.client_secret = | 157 oauth_client_info.client_secret = |
157 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); | 158 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); |
158 oauth_client_info.redirect_uri = "oob"; | 159 oauth_client_info.redirect_uri = "oob"; |
159 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, | 160 backend_.reset(new CloudPrintProxyBackend( |
160 enable_job_poll)); | 161 this, settings, oauth_client_info, enable_job_poll)); |
161 return true; | 162 return true; |
162 } | 163 } |
163 | 164 |
164 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { | 165 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { |
165 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
166 if (backend_.get()) { | 167 if (backend_.get()) { |
167 // Try getting auth and printers info from the backend. | 168 // Try getting auth and printers info from the backend. |
168 // We'll get notified in this case. | 169 // We'll get notified in this case. |
169 backend_->UnregisterPrinters(); | 170 backend_->UnregisterPrinters(); |
170 } else { | 171 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
181 client_->OnCloudPrintProxyDisabled(true); | 182 client_->OnCloudPrintProxyDisabled(true); |
182 } | 183 } |
183 ShutdownBackend(); | 184 ShutdownBackend(); |
184 } | 185 } |
185 | 186 |
186 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) { | 187 void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) { |
187 info->enabled = enabled_; | 188 info->enabled = enabled_; |
188 info->email.clear(); | 189 info->email.clear(); |
189 if (enabled_) | 190 if (enabled_) |
190 info->email = user_email(); | 191 info->email = user_email(); |
191 info->proxy_id = settings_.proxy_id(); | 192 ConnectorSettings settings; |
192 // If the Cloud Print service is not enabled, we may need to read the old | 193 settings.InitFrom(service_prefs_); |
193 // value of proxy_id from prefs. | 194 info->proxy_id = settings.proxy_id(); |
194 if (info->proxy_id.empty()) | 195 } |
195 info->proxy_id = | 196 |
196 service_prefs_->GetString(prefs::kCloudPrintProxyId, std::string()); | 197 void CloudPrintProxy::GetPrinters(std::vector<std::string>* printers) { |
| 198 ConnectorSettings settings; |
| 199 settings.InitFrom(service_prefs_); |
| 200 scoped_refptr<PrintSystem> print_system = |
| 201 PrintSystem::CreateInstance(settings.print_system_settings()); |
| 202 if (!print_system) |
| 203 return; |
| 204 PrintSystem::PrintSystemResult result = print_system->Init(); |
| 205 if (!result.succeeded()) |
| 206 return; |
| 207 printing::PrinterList printer_list; |
| 208 print_system->EnumeratePrinters(&printer_list); |
| 209 for (size_t i = 0; i < printer_list.size(); ++i) |
| 210 printers->push_back(printer_list[i].printer_name); |
197 } | 211 } |
198 | 212 |
199 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { | 213 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { |
200 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 214 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
201 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); | 215 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); |
202 } | 216 } |
203 | 217 |
204 void CloudPrintProxy::OnAuthenticated( | 218 void CloudPrintProxy::OnAuthenticated( |
205 const std::string& robot_oauth_refresh_token, | 219 const std::string& robot_oauth_refresh_token, |
206 const std::string& robot_email, | 220 const std::string& robot_email, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 client_->OnCloudPrintProxyDisabled(false); | 260 client_->OnCloudPrintProxyDisabled(false); |
247 } | 261 } |
248 } | 262 } |
249 | 263 |
250 void CloudPrintProxy::OnUnregisterPrinters( | 264 void CloudPrintProxy::OnUnregisterPrinters( |
251 const std::string& auth_token, | 265 const std::string& auth_token, |
252 const std::list<std::string>& printer_ids) { | 266 const std::list<std::string>& printer_ids) { |
253 UMA_HISTOGRAM_COUNTS_10000("CloudPrint.UnregisterPrinters", | 267 UMA_HISTOGRAM_COUNTS_10000("CloudPrint.UnregisterPrinters", |
254 printer_ids.size()); | 268 printer_ids.size()); |
255 ShutdownBackend(); | 269 ShutdownBackend(); |
256 wipeout_.reset(new CloudPrintWipeout(this, settings_.server_url())); | 270 ConnectorSettings settings; |
| 271 settings.InitFrom(service_prefs_); |
| 272 wipeout_.reset(new CloudPrintWipeout(this, settings.server_url())); |
257 wipeout_->UnregisterPrinters(auth_token, printer_ids); | 273 wipeout_->UnregisterPrinters(auth_token, printer_ids); |
258 } | 274 } |
259 | 275 |
260 void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) { | 276 void CloudPrintProxy::OnXmppPingUpdated(int ping_timeout) { |
261 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
262 service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout); | 278 service_prefs_->SetInt(prefs::kCloudPrintXmppPingTimeout, ping_timeout); |
263 service_prefs_->WritePrefs(); | 279 service_prefs_->WritePrefs(); |
264 } | 280 } |
265 | 281 |
266 void CloudPrintProxy::OnUnregisterPrintersComplete() { | 282 void CloudPrintProxy::OnUnregisterPrintersComplete() { |
267 wipeout_.reset(); | 283 wipeout_.reset(); |
268 // Finish disabling cloud print for this user. | 284 // Finish disabling cloud print for this user. |
269 DisableForUser(); | 285 DisableForUser(); |
270 } | 286 } |
271 | 287 |
272 void CloudPrintProxy::ShutdownBackend() { | 288 void CloudPrintProxy::ShutdownBackend() { |
273 DCHECK(CalledOnValidThread()); | 289 DCHECK(CalledOnValidThread()); |
274 if (backend_.get()) | 290 if (backend_.get()) |
275 backend_->Shutdown(); | 291 backend_->Shutdown(); |
276 backend_.reset(); | 292 backend_.reset(); |
277 } | 293 } |
278 | 294 |
279 } // namespace cloud_print | 295 } // namespace cloud_print |
OLD | NEW |