| 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_backend.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/service/cloud_print/cloud_print_auth.h" | 15 #include "chrome/service/cloud_print/cloud_print_auth.h" |
| 16 #include "chrome/service/cloud_print/cloud_print_connector.h" | 16 #include "chrome/service/cloud_print/cloud_print_connector.h" |
| 17 #include "chrome/service/cloud_print/cloud_print_consts.h" | 17 #include "chrome/service/cloud_print/cloud_print_consts.h" |
| 18 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 18 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
| 19 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 19 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
| 20 #include "chrome/service/cloud_print/connector_settings.h" |
| 20 #include "chrome/service/gaia/service_gaia_authenticator.h" | 21 #include "chrome/service/gaia/service_gaia_authenticator.h" |
| 21 #include "chrome/service/net/service_url_request_context.h" | 22 #include "chrome/service/net/service_url_request_context.h" |
| 22 #include "chrome/service/service_process.h" | 23 #include "chrome/service/service_process.h" |
| 23 #include "google_apis/gaia/gaia_oauth_client.h" | 24 #include "google_apis/gaia/gaia_oauth_client.h" |
| 24 #include "google_apis/gaia/gaia_urls.h" | 25 #include "google_apis/gaia/gaia_urls.h" |
| 25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 27 #include "jingle/notifier/base/notifier_options.h" | 28 #include "jingle/notifier/base/notifier_options.h" |
| 28 #include "jingle/notifier/listener/push_client.h" | 29 #include "jingle/notifier/listener/push_client.h" |
| 29 #include "jingle/notifier/listener/push_client_observer.h" | 30 #include "jingle/notifier/listener/push_client_observer.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 31 | 32 |
| 32 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. | 33 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. |
| 33 class CloudPrintProxyBackend::Core | 34 class CloudPrintProxyBackend::Core |
| 34 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, | 35 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, |
| 35 public CloudPrintAuth::Client, | 36 public CloudPrintAuth::Client, |
| 36 public CloudPrintConnector::Client, | 37 public CloudPrintConnector::Client, |
| 37 public notifier::PushClientObserver { | 38 public notifier::PushClientObserver { |
| 38 public: | 39 public: |
| 39 // It is OK for print_server_url to be empty. In this case system should | 40 // It is OK for print_server_url to be empty. In this case system should |
| 40 // use system default (local) print server. | 41 // use system default (local) print server. |
| 41 Core(CloudPrintProxyBackend* backend, | 42 Core(CloudPrintProxyBackend* backend, |
| 42 const std::string& proxy_id, | 43 const ConnectorSettings& settings, |
| 43 const GURL& cloud_print_server_url, | |
| 44 const DictionaryValue* print_system_settings, | |
| 45 const gaia::OAuthClientInfo& oauth_client_info, | 44 const gaia::OAuthClientInfo& oauth_client_info, |
| 46 bool enable_job_poll); | 45 bool enable_job_poll); |
| 47 | 46 |
| 48 // Note: | 47 // Note: |
| 49 // | 48 // |
| 50 // The Do* methods are the various entry points from CloudPrintProxyBackend | 49 // The Do* methods are the various entry points from CloudPrintProxyBackend |
| 51 // It calls us on a dedicated thread to actually perform synchronous | 50 // It calls us on a dedicated thread to actually perform synchronous |
| 52 // (and potentially blocking) operations. | 51 // (and potentially blocking) operations. |
| 53 // | 52 // |
| 54 // Called on the CloudPrintProxyBackend core_thread_ to perform | 53 // Called on the CloudPrintProxyBackend core_thread_ to perform |
| 55 // initialization. When we are passed in an LSID we authenticate using that | 54 // initialization. When we are passed in an LSID we authenticate using that |
| 56 // and retrieve new auth tokens. | 55 // and retrieve new auth tokens. |
| 57 void DoInitializeWithLsid(const std::string& lsid, | 56 void DoInitializeWithLsid(const std::string& lsid, |
| 58 const std::string& proxy_id, | |
| 59 const std::string& last_robot_refresh_token, | 57 const std::string& last_robot_refresh_token, |
| 60 const std::string& last_robot_email, | 58 const std::string& last_robot_email, |
| 61 const std::string& last_user_email); | 59 const std::string& last_user_email); |
| 62 | 60 |
| 63 void DoInitializeWithToken(const std::string& cloud_print_token, | 61 void DoInitializeWithToken(const std::string& cloud_print_token); |
| 64 const std::string& proxy_id); | |
| 65 void DoInitializeWithRobotToken(const std::string& robot_oauth_refresh_token, | 62 void DoInitializeWithRobotToken(const std::string& robot_oauth_refresh_token, |
| 66 const std::string& robot_email, | 63 const std::string& robot_email); |
| 67 const std::string& proxy_id); | |
| 68 void DoInitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code, | 64 void DoInitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code, |
| 69 const std::string& robot_email, | 65 const std::string& robot_email); |
| 70 const std::string& proxy_id); | |
| 71 | 66 |
| 72 // Called on the CloudPrintProxyBackend core_thread_ to perform | 67 // Called on the CloudPrintProxyBackend core_thread_ to perform |
| 73 // shutdown. | 68 // shutdown. |
| 74 void DoShutdown(); | 69 void DoShutdown(); |
| 75 void DoRegisterSelectedPrinters( | 70 void DoRegisterSelectedPrinters( |
| 76 const printing::PrinterList& printer_list); | 71 const printing::PrinterList& printer_list); |
| 77 void DoUnregisterPrinters(); | 72 void DoUnregisterPrinters(); |
| 78 | 73 |
| 79 // CloudPrintAuth::Client implementation. | 74 // CloudPrintAuth::Client implementation. |
| 80 virtual void OnAuthenticationComplete( | 75 virtual void OnAuthenticationComplete( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 123 |
| 129 // Our parent CloudPrintProxyBackend | 124 // Our parent CloudPrintProxyBackend |
| 130 CloudPrintProxyBackend* backend_; | 125 CloudPrintProxyBackend* backend_; |
| 131 | 126 |
| 132 // Cloud Print authenticator. | 127 // Cloud Print authenticator. |
| 133 scoped_refptr<CloudPrintAuth> auth_; | 128 scoped_refptr<CloudPrintAuth> auth_; |
| 134 | 129 |
| 135 // Cloud Print connector. | 130 // Cloud Print connector. |
| 136 scoped_refptr<CloudPrintConnector> connector_; | 131 scoped_refptr<CloudPrintConnector> connector_; |
| 137 | 132 |
| 138 // Server URL. | |
| 139 GURL cloud_print_server_url_; | |
| 140 // Proxy Id. | |
| 141 std::string proxy_id_; | |
| 142 // Print system settings. | |
| 143 scoped_ptr<DictionaryValue> print_system_settings_; | |
| 144 // OAuth client info. | 133 // OAuth client info. |
| 145 gaia::OAuthClientInfo oauth_client_info_; | 134 gaia::OAuthClientInfo oauth_client_info_; |
| 146 // Notification (xmpp) handler. | 135 // Notification (xmpp) handler. |
| 147 scoped_ptr<notifier::PushClient> push_client_; | 136 scoped_ptr<notifier::PushClient> push_client_; |
| 148 // Indicates whether XMPP notifications are currently enabled. | 137 // Indicates whether XMPP notifications are currently enabled. |
| 149 bool notifications_enabled_; | 138 bool notifications_enabled_; |
| 150 // The time when notifications were enabled. Valid only when | 139 // The time when notifications were enabled. Valid only when |
| 151 // notifications_enabled_ is true. | 140 // notifications_enabled_ is true. |
| 152 base::TimeTicks notifications_enabled_since_; | 141 base::TimeTicks notifications_enabled_since_; |
| 153 // Indicates whether a task to poll for jobs has been scheduled. | 142 // Indicates whether a task to poll for jobs has been scheduled. |
| 154 bool job_poll_scheduled_; | 143 bool job_poll_scheduled_; |
| 155 // Indicates whether we should poll for jobs when we lose XMPP connection. | 144 // Indicates whether we should poll for jobs when we lose XMPP connection. |
| 156 bool enable_job_poll_; | 145 bool enable_job_poll_; |
| 146 // Connector settings. |
| 147 ConnectorSettings settings_; |
| 157 scoped_ptr<CloudPrintTokenStore> token_store_; | 148 scoped_ptr<CloudPrintTokenStore> token_store_; |
| 158 | 149 |
| 159 DISALLOW_COPY_AND_ASSIGN(Core); | 150 DISALLOW_COPY_AND_ASSIGN(Core); |
| 160 }; | 151 }; |
| 161 | 152 |
| 162 CloudPrintProxyBackend::CloudPrintProxyBackend( | 153 CloudPrintProxyBackend::CloudPrintProxyBackend( |
| 163 CloudPrintProxyFrontend* frontend, | 154 CloudPrintProxyFrontend* frontend, |
| 164 const std::string& proxy_id, | 155 const ConnectorSettings& settings, |
| 165 const GURL& cloud_print_server_url, | |
| 166 const DictionaryValue* print_system_settings, | |
| 167 const gaia::OAuthClientInfo& oauth_client_info, | 156 const gaia::OAuthClientInfo& oauth_client_info, |
| 168 bool enable_job_poll) | 157 bool enable_job_poll) |
| 169 : core_thread_("Chrome_CloudPrintProxyCoreThread"), | 158 : core_thread_("Chrome_CloudPrintProxyCoreThread"), |
| 170 frontend_loop_(MessageLoop::current()), | 159 frontend_loop_(MessageLoop::current()), |
| 171 frontend_(frontend) { | 160 frontend_(frontend) { |
| 172 DCHECK(frontend_); | 161 DCHECK(frontend_); |
| 173 core_ = new Core(this, | 162 core_ = new Core(this, settings, oauth_client_info, enable_job_poll); |
| 174 proxy_id, | |
| 175 cloud_print_server_url, | |
| 176 print_system_settings, | |
| 177 oauth_client_info, | |
| 178 enable_job_poll); | |
| 179 } | 163 } |
| 180 | 164 |
| 181 CloudPrintProxyBackend::~CloudPrintProxyBackend() { | 165 CloudPrintProxyBackend::~CloudPrintProxyBackend() { |
| 182 DCHECK(!core_); | 166 DCHECK(!core_); |
| 183 } | 167 } |
| 184 | 168 |
| 185 bool CloudPrintProxyBackend::InitializeWithLsid( | 169 bool CloudPrintProxyBackend::InitializeWithLsid( |
| 186 const std::string& lsid, | 170 const std::string& lsid, |
| 187 const std::string& proxy_id, | |
| 188 const std::string& last_robot_refresh_token, | 171 const std::string& last_robot_refresh_token, |
| 189 const std::string& last_robot_email, | 172 const std::string& last_robot_email, |
| 190 const std::string& last_user_email) { | 173 const std::string& last_user_email) { |
| 191 if (!core_thread_.Start()) | 174 if (!core_thread_.Start()) |
| 192 return false; | 175 return false; |
| 193 core_thread_.message_loop()->PostTask( | 176 core_thread_.message_loop()->PostTask( |
| 194 FROM_HERE, | 177 FROM_HERE, |
| 195 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithLsid, | 178 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithLsid, |
| 196 core_.get(), lsid, proxy_id, last_robot_refresh_token, | 179 core_.get(), lsid, last_robot_refresh_token, last_robot_email, |
| 197 last_robot_email, last_user_email)); | 180 last_user_email)); |
| 198 return true; | 181 return true; |
| 199 } | 182 } |
| 200 | 183 |
| 201 bool CloudPrintProxyBackend::InitializeWithToken( | 184 bool CloudPrintProxyBackend::InitializeWithToken( |
| 202 const std::string& cloud_print_token, | 185 const std::string& cloud_print_token) { |
| 203 const std::string& proxy_id) { | |
| 204 if (!core_thread_.Start()) | 186 if (!core_thread_.Start()) |
| 205 return false; | 187 return false; |
| 206 core_thread_.message_loop()->PostTask( | 188 core_thread_.message_loop()->PostTask( |
| 207 FROM_HERE, | 189 FROM_HERE, |
| 208 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithToken, | 190 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithToken, |
| 209 core_.get(), cloud_print_token, proxy_id)); | 191 core_.get(), cloud_print_token)); |
| 210 return true; | 192 return true; |
| 211 } | 193 } |
| 212 | 194 |
| 213 bool CloudPrintProxyBackend::InitializeWithRobotToken( | 195 bool CloudPrintProxyBackend::InitializeWithRobotToken( |
| 214 const std::string& robot_oauth_refresh_token, | 196 const std::string& robot_oauth_refresh_token, |
| 215 const std::string& robot_email, | 197 const std::string& robot_email) { |
| 216 const std::string& proxy_id) { | |
| 217 if (!core_thread_.Start()) | 198 if (!core_thread_.Start()) |
| 218 return false; | 199 return false; |
| 219 core_thread_.message_loop()->PostTask( | 200 core_thread_.message_loop()->PostTask( |
| 220 FROM_HERE, | 201 FROM_HERE, |
| 221 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotToken, | 202 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotToken, |
| 222 core_.get(), robot_oauth_refresh_token, robot_email, | 203 core_.get(), robot_oauth_refresh_token, robot_email)); |
| 223 proxy_id)); | |
| 224 return true; | 204 return true; |
| 225 } | 205 } |
| 226 | 206 |
| 227 bool CloudPrintProxyBackend::InitializeWithRobotAuthCode( | 207 bool CloudPrintProxyBackend::InitializeWithRobotAuthCode( |
| 228 const std::string& robot_oauth_auth_code, | 208 const std::string& robot_oauth_auth_code, |
| 229 const std::string& robot_email, | 209 const std::string& robot_email) { |
| 230 const std::string& proxy_id) { | |
| 231 if (!core_thread_.Start()) | 210 if (!core_thread_.Start()) |
| 232 return false; | 211 return false; |
| 233 core_thread_.message_loop()->PostTask( | 212 core_thread_.message_loop()->PostTask( |
| 234 FROM_HERE, | 213 FROM_HERE, |
| 235 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode, | 214 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode, |
| 236 core_.get(), robot_oauth_auth_code, robot_email, proxy_id)); | 215 core_.get(), robot_oauth_auth_code, robot_email)); |
| 237 return true; | 216 return true; |
| 238 } | 217 } |
| 239 | 218 |
| 240 void CloudPrintProxyBackend::Shutdown() { | 219 void CloudPrintProxyBackend::Shutdown() { |
| 241 core_thread_.message_loop()->PostTask( | 220 core_thread_.message_loop()->PostTask( |
| 242 FROM_HERE, | 221 FROM_HERE, |
| 243 base::Bind(&CloudPrintProxyBackend::Core::DoShutdown, core_.get())); | 222 base::Bind(&CloudPrintProxyBackend::Core::DoShutdown, core_.get())); |
| 244 core_thread_.Stop(); | 223 core_thread_.Stop(); |
| 245 core_ = NULL; // Releases reference to core_. | 224 core_ = NULL; // Releases reference to core_. |
| 246 } | 225 } |
| 247 | 226 |
| 248 void CloudPrintProxyBackend::UnregisterPrinters() { | 227 void CloudPrintProxyBackend::UnregisterPrinters() { |
| 249 core_thread_.message_loop()->PostTask( | 228 core_thread_.message_loop()->PostTask( |
| 250 FROM_HERE, | 229 FROM_HERE, |
| 251 base::Bind(&CloudPrintProxyBackend::Core::DoUnregisterPrinters, | 230 base::Bind(&CloudPrintProxyBackend::Core::DoUnregisterPrinters, |
| 252 core_.get())); | 231 core_.get())); |
| 253 } | 232 } |
| 254 | 233 |
| 255 CloudPrintProxyBackend::Core::Core( | 234 CloudPrintProxyBackend::Core::Core( |
| 256 CloudPrintProxyBackend* backend, | 235 CloudPrintProxyBackend* backend, |
| 257 const std::string& proxy_id, | 236 const ConnectorSettings& settings, |
| 258 const GURL& cloud_print_server_url, | |
| 259 const DictionaryValue* print_system_settings, | |
| 260 const gaia::OAuthClientInfo& oauth_client_info, | 237 const gaia::OAuthClientInfo& oauth_client_info, |
| 261 bool enable_job_poll) | 238 bool enable_job_poll) |
| 262 : backend_(backend), | 239 : backend_(backend), |
| 263 cloud_print_server_url_(cloud_print_server_url), | |
| 264 proxy_id_(proxy_id), | |
| 265 oauth_client_info_(oauth_client_info), | 240 oauth_client_info_(oauth_client_info), |
| 266 notifications_enabled_(false), | 241 notifications_enabled_(false), |
| 267 job_poll_scheduled_(false), | 242 job_poll_scheduled_(false), |
| 268 enable_job_poll_(enable_job_poll) { | 243 enable_job_poll_(enable_job_poll) { |
| 269 if (print_system_settings) { | 244 settings_.CopyFrom(settings); |
| 270 // It is possible to have no print settings specified. | |
| 271 print_system_settings_.reset(print_system_settings->DeepCopy()); | |
| 272 } | |
| 273 } | 245 } |
| 274 | 246 |
| 275 void CloudPrintProxyBackend::Core::CreateAuthAndConnector() { | 247 void CloudPrintProxyBackend::Core::CreateAuthAndConnector() { |
| 276 if (!auth_.get()) { | 248 if (!auth_.get()) { |
| 277 auth_ = new CloudPrintAuth(this, | 249 auth_ = new CloudPrintAuth(this, |
| 278 cloud_print_server_url_, | 250 settings_.cloud_print_server_url(), |
| 279 oauth_client_info_, | 251 oauth_client_info_, |
| 280 proxy_id_); | 252 settings_.proxy_id()); |
| 281 } | 253 } |
| 282 | 254 |
| 283 if (!connector_.get()) { | 255 if (!connector_.get()) { |
| 284 connector_ = new CloudPrintConnector(this, | 256 connector_ = new CloudPrintConnector(this, settings_); |
| 285 proxy_id_, | |
| 286 cloud_print_server_url_, | |
| 287 print_system_settings_.get()); | |
| 288 } | 257 } |
| 289 } | 258 } |
| 290 | 259 |
| 291 void CloudPrintProxyBackend::Core::DestroyAuthAndConnector() { | 260 void CloudPrintProxyBackend::Core::DestroyAuthAndConnector() { |
| 292 auth_ = NULL; | 261 auth_ = NULL; |
| 293 connector_ = NULL; | 262 connector_ = NULL; |
| 294 } | 263 } |
| 295 | 264 |
| 296 void CloudPrintProxyBackend::Core::DoInitializeWithLsid( | 265 void CloudPrintProxyBackend::Core::DoInitializeWithLsid( |
| 297 const std::string& lsid, | 266 const std::string& lsid, |
| 298 const std::string& proxy_id, | |
| 299 const std::string& last_robot_refresh_token, | 267 const std::string& last_robot_refresh_token, |
| 300 const std::string& last_robot_email, | 268 const std::string& last_robot_email, |
| 301 const std::string& last_user_email) { | 269 const std::string& last_user_email) { |
| 302 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 270 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 303 CreateAuthAndConnector(); | 271 CreateAuthAndConnector(); |
| 304 // Note: The GAIA login is synchronous but that should be OK because we are in | 272 // Note: The GAIA login is synchronous but that should be OK because we are in |
| 305 // the CloudPrintProxyCoreThread and we cannot really do anything else until | 273 // the CloudPrintProxyCoreThread and we cannot really do anything else until |
| 306 // the GAIA signin is successful. | 274 // the GAIA signin is successful. |
| 307 auth_->AuthenticateWithLsid(lsid, last_robot_refresh_token, | 275 auth_->AuthenticateWithLsid(lsid, last_robot_refresh_token, |
| 308 last_robot_email, last_user_email); | 276 last_robot_email, last_user_email); |
| 309 } | 277 } |
| 310 | 278 |
| 311 void CloudPrintProxyBackend::Core::DoInitializeWithToken( | 279 void CloudPrintProxyBackend::Core::DoInitializeWithToken( |
| 312 const std::string& cloud_print_token, | 280 const std::string& cloud_print_token) { |
| 313 const std::string& proxy_id) { | |
| 314 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 281 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 315 CreateAuthAndConnector(); | 282 CreateAuthAndConnector(); |
| 316 auth_->AuthenticateWithToken(cloud_print_token); | 283 auth_->AuthenticateWithToken(cloud_print_token); |
| 317 } | 284 } |
| 318 | 285 |
| 319 void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken( | 286 void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken( |
| 320 const std::string& robot_oauth_refresh_token, | 287 const std::string& robot_oauth_refresh_token, |
| 321 const std::string& robot_email, | 288 const std::string& robot_email) { |
| 322 const std::string& proxy_id) { | |
| 323 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 289 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 324 CreateAuthAndConnector(); | 290 CreateAuthAndConnector(); |
| 325 auth_->AuthenticateWithRobotToken(robot_oauth_refresh_token, robot_email); | 291 auth_->AuthenticateWithRobotToken(robot_oauth_refresh_token, robot_email); |
| 326 } | 292 } |
| 327 | 293 |
| 328 void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode( | 294 void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode( |
| 329 const std::string& robot_oauth_auth_code, | 295 const std::string& robot_oauth_auth_code, |
| 330 const std::string& robot_email, | 296 const std::string& robot_email) { |
| 331 const std::string& proxy_id) { | |
| 332 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 297 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 333 CreateAuthAndConnector(); | 298 CreateAuthAndConnector(); |
| 334 auth_->AuthenticateWithRobotAuthCode(robot_oauth_auth_code, robot_email); | 299 auth_->AuthenticateWithRobotAuthCode(robot_oauth_auth_code, robot_email); |
| 335 } | 300 } |
| 336 | 301 |
| 337 void CloudPrintProxyBackend::Core::OnAuthenticationComplete( | 302 void CloudPrintProxyBackend::Core::OnAuthenticationComplete( |
| 338 const std::string& access_token, | 303 const std::string& access_token, |
| 339 const std::string& robot_oauth_refresh_token, | 304 const std::string& robot_oauth_refresh_token, |
| 340 const std::string& robot_email, | 305 const std::string& robot_email, |
| 341 const std::string& user_email) { | 306 const std::string& user_email) { |
| 342 CloudPrintTokenStore* token_store = GetTokenStore(); | 307 CloudPrintTokenStore* token_store = GetTokenStore(); |
| 343 bool first_time = token_store->token().empty(); | 308 bool first_time = token_store->token().empty(); |
| 344 token_store->SetToken(access_token); | 309 token_store->SetToken(access_token); |
| 345 // Let the frontend know that we have authenticated. | 310 // Let the frontend know that we have authenticated. |
| 346 backend_->frontend_loop_->PostTask( | 311 backend_->frontend_loop_->PostTask( |
| 347 FROM_HERE, | 312 FROM_HERE, |
| 348 base::Bind(&Core::NotifyAuthenticated, this, robot_oauth_refresh_token, | 313 base::Bind(&Core::NotifyAuthenticated, this, robot_oauth_refresh_token, |
| 349 robot_email, user_email)); | 314 robot_email, user_email)); |
| 350 if (first_time) { | 315 if (first_time) { |
| 351 InitNotifications(robot_email, access_token); | 316 InitNotifications(robot_email, access_token); |
| 352 } else { | 317 } else { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 notifier::Subscription subscription; | 362 notifier::Subscription subscription; |
| 398 subscription.channel = kCloudPrintPushNotificationsSource; | 363 subscription.channel = kCloudPrintPushNotificationsSource; |
| 399 subscription.from = kCloudPrintPushNotificationsSource; | 364 subscription.from = kCloudPrintPushNotificationsSource; |
| 400 push_client_->UpdateSubscriptions( | 365 push_client_->UpdateSubscriptions( |
| 401 notifier::SubscriptionList(1, subscription)); | 366 notifier::SubscriptionList(1, subscription)); |
| 402 push_client_->UpdateCredentials(robot_email, access_token); | 367 push_client_->UpdateCredentials(robot_email, access_token); |
| 403 } | 368 } |
| 404 | 369 |
| 405 void CloudPrintProxyBackend::Core::DoShutdown() { | 370 void CloudPrintProxyBackend::Core::DoShutdown() { |
| 406 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 371 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 407 VLOG(1) << "CP_CONNECTOR: Shutdown connector, id: " << proxy_id_; | 372 VLOG(1) << "CP_CONNECTOR: Shutdown connector, id: " << settings_.proxy_id(); |
| 408 | 373 |
| 409 if (connector_->IsRunning()) | 374 if (connector_->IsRunning()) |
| 410 connector_->Stop(); | 375 connector_->Stop(); |
| 411 | 376 |
| 412 // Important to delete the PushClient on this thread. | 377 // Important to delete the PushClient on this thread. |
| 413 if (push_client_.get()) { | 378 if (push_client_.get()) { |
| 414 push_client_->RemoveObserver(this); | 379 push_client_->RemoveObserver(this); |
| 415 } | 380 } |
| 416 push_client_.reset(); | 381 push_client_.reset(); |
| 417 notifications_enabled_ = false; | 382 notifications_enabled_ = false; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 const std::string& auth_token, | 463 const std::string& auth_token, |
| 499 const std::list<std::string>& printer_ids) { | 464 const std::list<std::string>& printer_ids) { |
| 500 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 465 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
| 501 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); | 466 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); |
| 502 } | 467 } |
| 503 | 468 |
| 504 void CloudPrintProxyBackend::Core::OnNotificationsEnabled() { | 469 void CloudPrintProxyBackend::Core::OnNotificationsEnabled() { |
| 505 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 470 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 506 notifications_enabled_ = true; | 471 notifications_enabled_ = true; |
| 507 notifications_enabled_since_ = base::TimeTicks::Now(); | 472 notifications_enabled_since_ = base::TimeTicks::Now(); |
| 508 VLOG(1) << "Notifications for connector " << proxy_id_ | 473 VLOG(1) << "Notifications for connector " << settings_.proxy_id() |
| 509 << " were enabled at " | 474 << " were enabled at " |
| 510 << notifications_enabled_since_.ToInternalValue(); | 475 << notifications_enabled_since_.ToInternalValue(); |
| 511 // Notifications just got re-enabled. In this case we want to schedule | 476 // Notifications just got re-enabled. In this case we want to schedule |
| 512 // a poll once for jobs we might have missed when we were dark. | 477 // a poll once for jobs we might have missed when we were dark. |
| 513 // Note that ScheduleJobPoll will not schedule again if a job poll task is | 478 // Note that ScheduleJobPoll will not schedule again if a job poll task is |
| 514 // already scheduled. | 479 // already scheduled. |
| 515 ScheduleJobPoll(); | 480 ScheduleJobPoll(); |
| 516 } | 481 } |
| 517 | 482 |
| 518 void CloudPrintProxyBackend::Core::OnNotificationsDisabled( | 483 void CloudPrintProxyBackend::Core::OnNotificationsDisabled( |
| 519 notifier::NotificationsDisabledReason reason) { | 484 notifier::NotificationsDisabledReason reason) { |
| 520 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 485 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 521 notifications_enabled_ = false; | 486 notifications_enabled_ = false; |
| 522 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled."; | 487 LOG(ERROR) << "Notifications for connector " << settings_.proxy_id() |
| 488 << " disabled."; |
| 523 notifications_enabled_since_ = base::TimeTicks(); | 489 notifications_enabled_since_ = base::TimeTicks(); |
| 524 // We just lost notifications. This this case we want to schedule a | 490 // We just lost notifications. This this case we want to schedule a |
| 525 // job poll if enable_job_poll_ is true. | 491 // job poll if enable_job_poll_ is true. |
| 526 if (enable_job_poll_) | 492 if (enable_job_poll_) |
| 527 ScheduleJobPoll(); | 493 ScheduleJobPoll(); |
| 528 } | 494 } |
| 529 | 495 |
| 530 | 496 |
| 531 void CloudPrintProxyBackend::Core::OnIncomingNotification( | 497 void CloudPrintProxyBackend::Core::OnIncomingNotification( |
| 532 const notifier::Notification& notification) { | 498 const notifier::Notification& notification) { |
| 533 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 499 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 534 VLOG(1) << "CP_CONNECTOR: Incoming notification."; | 500 VLOG(1) << "CP_CONNECTOR: Incoming notification."; |
| 535 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, | 501 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, |
| 536 notification.channel.c_str())) | 502 notification.channel.c_str())) |
| 537 HandlePrinterNotification(notification.data); | 503 HandlePrinterNotification(notification.data); |
| 538 } | 504 } |
| 505 |
| OLD | NEW |