Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/service/cloud_print/cloud_print_proxy_backend.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps, win compile error Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 OnNotificationsEnabled() OVERRIDE;
92 bool notifications_enabled) OVERRIDE; 92 virtual void OnNotificationsDisabled(
93 notifier::NotificationsDisabledReason reason) OVERRIDE;
93 virtual void OnIncomingNotification( 94 virtual void OnIncomingNotification(
94 const notifier::Notification& notification) OVERRIDE; 95 const notifier::Notification& notification) OVERRIDE;
95 96
96 private: 97 private:
97 friend class base::RefCountedThreadSafe<Core>; 98 friend class base::RefCountedThreadSafe<Core>;
98 99
99 virtual ~Core() {} 100 virtual ~Core() {}
100 101
101 void CreateAuthAndConnector(); 102 void CreateAuthAndConnector();
102 void DestroyAuthAndConnector(); 103 void DestroyAuthAndConnector();
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 backend_->frontend_->OnPrintSystemUnavailable(); 494 backend_->frontend_->OnPrintSystemUnavailable();
494 } 495 }
495 496
496 void CloudPrintProxyBackend::Core::NotifyUnregisterPrinters( 497 void CloudPrintProxyBackend::Core::NotifyUnregisterPrinters(
497 const std::string& auth_token, 498 const std::string& auth_token,
498 const std::list<std::string>& printer_ids) { 499 const std::list<std::string>& printer_ids) {
499 DCHECK(MessageLoop::current() == backend_->frontend_loop_); 500 DCHECK(MessageLoop::current() == backend_->frontend_loop_);
500 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); 501 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids);
501 } 502 }
502 503
503 void CloudPrintProxyBackend::Core::OnNotificationStateChange( 504 void CloudPrintProxyBackend::Core::OnNotificationsEnabled() {
504 bool notification_enabled) {
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_ = true;
507 if (notifications_enabled_) { 507 notifications_enabled_since_ = base::TimeTicks::Now();
508 notifications_enabled_since_ = base::TimeTicks::Now(); 508 VLOG(1) << "Notifications for connector " << proxy_id_
509 VLOG(1) << "Notifications for connector " << proxy_id_ 509 << " were enabled at "
510 << " were enabled at " 510 << notifications_enabled_since_.ToInternalValue();
511 << notifications_enabled_since_.ToInternalValue(); 511 // Notifications just got re-enabled. In this case we want to schedule
512 } else {
513 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled.";
514 notifications_enabled_since_ = base::TimeTicks();
515 }
516 // A state change means one of two cases.
517 // Case 1: We just lost notifications. This this case we want to schedule a
518 // job poll if enable_job_poll_ is true.
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. 512 // 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 513 // Note that ScheduleJobPoll will not schedule again if a job poll task is
522 // already scheduled. 514 // already scheduled.
523 if (enable_job_poll_ || notifications_enabled_) 515 ScheduleJobPoll();
516 }
517
518 void CloudPrintProxyBackend::Core::OnNotificationsDisabled(
519 notifier::NotificationsDisabledReason reason) {
520 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
521 notifications_enabled_ = false;
522 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled.";
523 notifications_enabled_since_ = base::TimeTicks();
524 // We just lost notifications. This this case we want to schedule a
525 // job poll if enable_job_poll_ is true.
526 if (enable_job_poll_)
524 ScheduleJobPoll(); 527 ScheduleJobPoll();
525 } 528 }
526 529
527 530
528 void CloudPrintProxyBackend::Core::OnIncomingNotification( 531 void CloudPrintProxyBackend::Core::OnIncomingNotification(
529 const notifier::Notification& notification) { 532 const notifier::Notification& notification) {
530 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 533 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
531 VLOG(1) << "CP_CONNECTOR: Incoming notification."; 534 VLOG(1) << "CP_CONNECTOR: Incoming notification.";
532 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, 535 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource,
533 notification.channel.c_str())) 536 notification.channel.c_str()))
534 HandlePrinterNotification(notification.data); 537 HandlePrinterNotification(notification.data);
535 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698