| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "chrome/browser/drive/drive_notification_observer.h" | 11 #include "chrome/browser/drive/drive_notification_observer.h" |
| 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 13 #include "sync/notifier/invalidation_handler.h" | 13 #include "sync/notifier/invalidation_handler.h" |
| 14 | 14 |
| 15 class Profile; | |
| 16 class ProfileSyncService; | 15 class ProfileSyncService; |
| 17 | 16 |
| 17 namespace invalidation { |
| 18 class InvalidationService; |
| 19 } |
| 20 |
| 18 namespace drive { | 21 namespace drive { |
| 19 | 22 |
| 20 // Informs observers when they should check Google Drive for updates. | 23 // Informs observers when they should check Google Drive for updates. |
| 21 // Conditions under which updates should be searched: | 24 // Conditions under which updates should be searched: |
| 22 // 1. XMPP invalidation is received from Google Drive. | 25 // 1. XMPP invalidation is received from Google Drive. |
| 23 // 2. Polling timer counts down. | 26 // 2. Polling timer counts down. |
| 24 class DriveNotificationManager | 27 class DriveNotificationManager |
| 25 : public BrowserContextKeyedService, | 28 : public BrowserContextKeyedService, |
| 26 public syncer::InvalidationHandler { | 29 public syncer::InvalidationHandler { |
| 27 public: | 30 public: |
| 28 explicit DriveNotificationManager(Profile* profile); | 31 explicit DriveNotificationManager( |
| 32 invalidation::InvalidationService* invalidation_service); |
| 29 virtual ~DriveNotificationManager(); | 33 virtual ~DriveNotificationManager(); |
| 30 | 34 |
| 31 // BrowserContextKeyedService override. | 35 // BrowserContextKeyedService override. |
| 32 virtual void Shutdown() OVERRIDE; | 36 virtual void Shutdown() OVERRIDE; |
| 33 | 37 |
| 34 // syncer::InvalidationHandler implementation. | 38 // syncer::InvalidationHandler implementation. |
| 35 virtual void OnInvalidatorStateChange( | 39 virtual void OnInvalidatorStateChange( |
| 36 syncer::InvalidatorState state) OVERRIDE; | 40 syncer::InvalidatorState state) OVERRIDE; |
| 37 virtual void OnIncomingInvalidation( | 41 virtual void OnIncomingInvalidation( |
| 38 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 42 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 // Notifies the observers that it's time to check for updates. | 66 // Notifies the observers that it's time to check for updates. |
| 63 // |source| indicates where the notification comes from. | 67 // |source| indicates where the notification comes from. |
| 64 void NotifyObserversToUpdate(NotificationSource source); | 68 void NotifyObserversToUpdate(NotificationSource source); |
| 65 | 69 |
| 66 // Registers for Google Drive invalidation notifications through XMPP. | 70 // Registers for Google Drive invalidation notifications through XMPP. |
| 67 void RegisterDriveNotifications(); | 71 void RegisterDriveNotifications(); |
| 68 | 72 |
| 69 // Returns a string representation of NotificationSource. | 73 // Returns a string representation of NotificationSource. |
| 70 static std::string NotificationSourceToString(NotificationSource source); | 74 static std::string NotificationSourceToString(NotificationSource source); |
| 71 | 75 |
| 72 Profile* profile_; | 76 invalidation::InvalidationService* invalidation_service_; |
| 73 ObserverList<DriveNotificationObserver> observers_; | 77 ObserverList<DriveNotificationObserver> observers_; |
| 74 | 78 |
| 75 // True when Drive File Sync Service is registered for Drive notifications. | 79 // True when Drive File Sync Service is registered for Drive notifications. |
| 76 bool push_notification_registered_; | 80 bool push_notification_registered_; |
| 77 // True if the XMPP-based push notification is currently enabled. | 81 // True if the XMPP-based push notification is currently enabled. |
| 78 bool push_notification_enabled_; | 82 bool push_notification_enabled_; |
| 79 // True once observers are notified for the first time. | 83 // True once observers are notified for the first time. |
| 80 bool observers_notified_; | 84 bool observers_notified_; |
| 81 | 85 |
| 82 // The timer is used for polling based notification. XMPP should usually be | 86 // The timer is used for polling based notification. XMPP should usually be |
| 83 // used but notification is done per polling when XMPP is not working. | 87 // used but notification is done per polling when XMPP is not working. |
| 84 base::Timer polling_timer_; | 88 base::Timer polling_timer_; |
| 85 | 89 |
| 86 // Note: This should remain the last member so it'll be destroyed and | 90 // Note: This should remain the last member so it'll be destroyed and |
| 87 // invalidate its weak pointers before any other members are destroyed. | 91 // invalidate its weak pointers before any other members are destroyed. |
| 88 base::WeakPtrFactory<DriveNotificationManager> weak_ptr_factory_; | 92 base::WeakPtrFactory<DriveNotificationManager> weak_ptr_factory_; |
| 89 | 93 |
| 90 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); | 94 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); |
| 91 }; | 95 }; |
| 92 | 96 |
| 93 } // namespace drive | 97 } // namespace drive |
| 94 | 98 |
| 95 #endif // CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ | 99 #endif // CHROME_BROWSER_DRIVE_DRIVE_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |