| 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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const std::string& access_token, | 81 const std::string& access_token, |
| 82 const std::string& robot_oauth_refresh_token, | 82 const std::string& robot_oauth_refresh_token, |
| 83 const std::string& robot_email, | 83 const std::string& robot_email, |
| 84 const std::string& user_email) OVERRIDE; | 84 const std::string& user_email) OVERRIDE; |
| 85 virtual void OnInvalidCredentials() OVERRIDE; | 85 virtual void OnInvalidCredentials() OVERRIDE; |
| 86 | 86 |
| 87 // CloudPrintConnector::Client implementation. | 87 // CloudPrintConnector::Client implementation. |
| 88 virtual void OnAuthFailed() OVERRIDE; | 88 virtual void OnAuthFailed() OVERRIDE; |
| 89 | 89 |
| 90 // notifier::PushClientObserver implementation. | 90 // notifier::PushClientObserver implementation. |
| 91 virtual void OnNotificationStateChange( | 91 virtual void OnPushClientStateChange( |
| 92 bool notifications_enabled) OVERRIDE; | 92 notifier::PushClientState push_client_state) OVERRIDE; |
| 93 virtual void OnIncomingNotification( | 93 virtual void OnIncomingNotification( |
| 94 const notifier::Notification& notification) OVERRIDE; | 94 const notifier::Notification& notification) OVERRIDE; |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 friend class base::RefCountedThreadSafe<Core>; | 97 friend class base::RefCountedThreadSafe<Core>; |
| 98 | 98 |
| 99 virtual ~Core() {} | 99 virtual ~Core() {} |
| 100 | 100 |
| 101 void CreateAuthAndConnector(); | 101 void CreateAuthAndConnector(); |
| 102 void DestroyAuthAndConnector(); | 102 void DestroyAuthAndConnector(); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 backend_->frontend_->OnPrintSystemUnavailable(); | 493 backend_->frontend_->OnPrintSystemUnavailable(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void CloudPrintProxyBackend::Core::NotifyUnregisterPrinters( | 496 void CloudPrintProxyBackend::Core::NotifyUnregisterPrinters( |
| 497 const std::string& auth_token, | 497 const std::string& auth_token, |
| 498 const std::list<std::string>& printer_ids) { | 498 const std::list<std::string>& printer_ids) { |
| 499 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 499 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
| 500 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); | 500 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); |
| 501 } | 501 } |
| 502 | 502 |
| 503 void CloudPrintProxyBackend::Core::OnNotificationStateChange( | 503 void CloudPrintProxyBackend::Core::OnPushClientStateChange( |
| 504 bool notification_enabled) { | 504 notifier::PushClientState push_client_state) { |
| 505 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 505 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 506 notifications_enabled_ = notification_enabled; | 506 notifications_enabled_ = (push_client_state == notifier::NOTIFICATIONS_ON); |
| 507 if (notifications_enabled_) { | 507 if (notifications_enabled_) { |
| 508 notifications_enabled_since_ = base::TimeTicks::Now(); | 508 notifications_enabled_since_ = base::TimeTicks::Now(); |
| 509 VLOG(1) << "Notifications for connector " << proxy_id_ | 509 VLOG(1) << "Notifications for connector " << proxy_id_ |
| 510 << " were enabled at " | 510 << " were enabled at " |
| 511 << notifications_enabled_since_.ToInternalValue(); | 511 << notifications_enabled_since_.ToInternalValue(); |
| 512 } else { | 512 } else { |
| 513 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled."; | 513 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled."; |
| 514 notifications_enabled_since_ = base::TimeTicks(); | 514 notifications_enabled_since_ = base::TimeTicks(); |
| 515 } | 515 } |
| 516 // A state change means one of two cases. | 516 // A state change means one of two cases. |
| 517 // Case 1: We just lost notifications. This this case we want to schedule a | 517 // Case 1: We just lost notifications. This this case we want to schedule a |
| 518 // job poll if enable_job_poll_ is true. | 518 // job poll if enable_job_poll_ is true. |
| 519 // Case 2: Notifications just got re-enabled. In this case we want to schedule | 519 // Case 2: Notifications just got re-enabled. In this case we want to schedule |
| 520 // a poll once for jobs we might have missed when we were dark. | 520 // a poll once for jobs we might have missed when we were dark. |
| 521 // Note that ScheduleJobPoll will not schedule again if a job poll task is | 521 // Note that ScheduleJobPoll will not schedule again if a job poll task is |
| 522 // already scheduled. | 522 // already scheduled. |
| 523 if (enable_job_poll_ || notifications_enabled_) | 523 if (enable_job_poll_ || notifications_enabled_) |
| 524 ScheduleJobPoll(); | 524 ScheduleJobPoll(); |
| 525 } | 525 } |
| 526 | 526 |
| 527 | 527 |
| 528 void CloudPrintProxyBackend::Core::OnIncomingNotification( | 528 void CloudPrintProxyBackend::Core::OnIncomingNotification( |
| 529 const notifier::Notification& notification) { | 529 const notifier::Notification& notification) { |
| 530 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 530 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 531 VLOG(1) << "CP_CONNECTOR: Incoming notification."; | 531 VLOG(1) << "CP_CONNECTOR: Incoming notification."; |
| 532 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, | 532 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, |
| 533 notification.channel.c_str())) | 533 notification.channel.c_str())) |
| 534 HandlePrinterNotification(notification.data); | 534 HandlePrinterNotification(notification.data); |
| 535 } | 535 } |
| OLD | NEW |