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_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ |
7 | 7 |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "chrome/browser/google_apis/drive_notification_observer.h" | 9 #include "chrome/browser/google_apis/drive_notification_observer.h" |
10 #include "chrome/browser/profiles/profile_keyed_service.h" | 10 #include "chrome/browser/profiles/profile_keyed_service.h" |
11 #include "sync/notifier/invalidation_handler.h" | 11 #include "sync/notifier/invalidation_handler.h" |
12 | 12 |
13 class Profile; | 13 class Profile; |
| 14 class ProfileSyncService; |
14 | 15 |
15 namespace google_apis { | 16 namespace google_apis { |
16 | 17 |
17 // Informs observers when they should check Google Drive for updates. | 18 // Informs observers when they should check Google Drive for updates. |
18 // Conditions under which updates should be searched: | 19 // Conditions under which updates should be searched: |
19 // 1. XMPP invalidation is received from Google Drive. | 20 // 1. XMPP invalidation is received from Google Drive. |
20 // TODO(calvinlo): Implement public syncer::InvalidationHandler interface. | |
21 // 2. Polling timer counts down. | 21 // 2. Polling timer counts down. |
22 // TODO(calvinlo): Also add in backup timer. | |
23 class DriveNotificationManager | 22 class DriveNotificationManager |
24 : public ProfileKeyedService, | 23 : public ProfileKeyedService, |
25 public syncer::InvalidationHandler { | 24 public syncer::InvalidationHandler { |
26 public: | 25 public: |
27 explicit DriveNotificationManager(Profile* profile); | 26 explicit DriveNotificationManager(Profile* profile); |
28 virtual ~DriveNotificationManager(); | 27 virtual ~DriveNotificationManager(); |
29 | 28 |
30 // ProfileKeyedService override. | 29 // ProfileKeyedService override. |
31 virtual void Shutdown() OVERRIDE; | 30 virtual void Shutdown() OVERRIDE; |
32 | 31 |
33 // syncer::InvalidationHandler implementation. | 32 // syncer::InvalidationHandler implementation. |
34 virtual void OnInvalidatorStateChange( | 33 virtual void OnInvalidatorStateChange( |
35 syncer::InvalidatorState state) OVERRIDE; | 34 syncer::InvalidatorState state) OVERRIDE; |
36 virtual void OnIncomingInvalidation( | 35 virtual void OnIncomingInvalidation( |
37 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 36 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
38 | 37 |
39 void AddObserver(DriveNotificationObserver* observer); | 38 void AddObserver(DriveNotificationObserver* observer); |
40 void RemoveObserver(DriveNotificationObserver* observer); | 39 void RemoveObserver(DriveNotificationObserver* observer); |
41 | 40 |
| 41 // True when XMPP notifications registered and enabled. False otherwise. |
| 42 bool IsPushNotificationEnabled(); |
| 43 |
42 private: | 44 private: |
43 void NotifyObserversToUpdate(); | 45 void NotifyObserversToUpdate(); |
44 | |
45 // XMPP notification related methods. | |
46 void RegisterDriveNotifications(); | 46 void RegisterDriveNotifications(); |
47 bool IsDriveNotificationSupported(); | |
48 void SetPushNotificationEnabled(syncer::InvalidatorState state); | |
49 | 47 |
50 Profile* profile_; | 48 Profile* profile_; |
51 ObserverList<DriveNotificationObserver> observers_; | 49 ObserverList<DriveNotificationObserver> observers_; |
52 | 50 |
53 // XMPP notification related variables. | |
54 // True when Drive File Sync Service is registered for Drive notifications. | 51 // True when Drive File Sync Service is registered for Drive notifications. |
55 bool push_notification_registered_; | 52 bool push_notification_registered_; |
56 // True once the first drive notification is received with OK state. | 53 // True once the first drive notification is received with OK state. |
57 bool push_notification_enabled_; | 54 bool push_notification_enabled_; |
58 | 55 |
59 // TODO(calvinlo): Polling variables to go here. | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); | 56 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); |
62 }; | 57 }; |
63 | 58 |
64 } // namespace google_apis | 59 } // namespace google_apis |
65 | 60 |
66 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ | 61 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ |
OLD | NEW |