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/memory/weak_ptr.h" | |
8 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/timer.h" | |
9 #include "chrome/browser/google_apis/drive_notification_observer.h" | 11 #include "chrome/browser/google_apis/drive_notification_observer.h" |
10 #include "chrome/browser/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
11 #include "sync/notifier/invalidation_handler.h" | 13 #include "sync/notifier/invalidation_handler.h" |
12 | 14 |
13 class Profile; | 15 class Profile; |
16 class ProfileSyncService; | |
14 | 17 |
15 namespace google_apis { | 18 namespace google_apis { |
16 | 19 |
17 // Informs observers when they should check Google Drive for updates. | 20 // Informs observers when they should check Google Drive for updates. |
18 // Conditions under which updates should be searched: | 21 // Conditions under which updates should be searched: |
19 // 1. XMPP invalidation is received from Google Drive. | 22 // 1. XMPP invalidation is received from Google Drive. |
20 // TODO(calvinlo): Implement public syncer::InvalidationHandler interface. | |
21 // 2. Polling timer counts down. | 23 // 2. Polling timer counts down. |
22 // TODO(calvinlo): Also add in backup timer. | |
23 class DriveNotificationManager | 24 class DriveNotificationManager |
24 : public ProfileKeyedService, | 25 : public ProfileKeyedService, |
25 public syncer::InvalidationHandler { | 26 public syncer::InvalidationHandler, |
27 public base::SupportsWeakPtr<DriveNotificationManager> { | |
satorux1
2013/04/19 04:12:13
Please use WeakPtrFactory instead in favor of less
calvinlo
2013/04/19 06:15:09
Removed.
Thanks for the tip. Actually, after my
| |
26 public: | 28 public: |
27 explicit DriveNotificationManager(Profile* profile); | 29 explicit DriveNotificationManager(Profile* profile); |
28 virtual ~DriveNotificationManager(); | 30 virtual ~DriveNotificationManager(); |
29 | 31 |
30 // ProfileKeyedService override. | 32 // ProfileKeyedService override. |
31 virtual void Shutdown() OVERRIDE; | 33 virtual void Shutdown() OVERRIDE; |
32 | 34 |
33 // syncer::InvalidationHandler implementation. | 35 // syncer::InvalidationHandler implementation. |
34 virtual void OnInvalidatorStateChange( | 36 virtual void OnInvalidatorStateChange( |
35 syncer::InvalidatorState state) OVERRIDE; | 37 syncer::InvalidatorState state) OVERRIDE; |
36 virtual void OnIncomingInvalidation( | 38 virtual void OnIncomingInvalidation( |
37 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 39 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
38 | 40 |
39 void AddObserver(DriveNotificationObserver* observer); | 41 void AddObserver(DriveNotificationObserver* observer); |
40 void RemoveObserver(DriveNotificationObserver* observer); | 42 void RemoveObserver(DriveNotificationObserver* observer); |
43 bool IsPushNotificationEnabled(); | |
satorux1
2013/04/19 04:12:13
Function comment is missing.
calvinlo
2013/04/19 06:15:09
Done.
| |
41 | 44 |
42 private: | 45 private: |
43 void NotifyObserversToUpdate(); | 46 void NotifyObserversToUpdate(); |
44 | 47 |
45 // XMPP notification related methods. | 48 // XMPP notification related methods. |
46 void RegisterDriveNotifications(); | 49 void RegisterDriveNotifications(); |
47 bool IsDriveNotificationSupported(); | 50 |
48 void SetPushNotificationEnabled(syncer::InvalidatorState state); | 51 // Polling related methods. |
52 void SchedulePolling(int64 new_delay_sec); | |
49 | 53 |
50 Profile* profile_; | 54 Profile* profile_; |
55 ProfileSyncService* profile_sync_service_; | |
51 ObserverList<DriveNotificationObserver> observers_; | 56 ObserverList<DriveNotificationObserver> observers_; |
52 | 57 |
53 // XMPP notification related variables. | 58 // XMPP notification related variables. |
54 // True when Drive File Sync Service is registered for Drive notifications. | 59 // True when Drive File Sync Service is registered for Drive notifications. |
55 bool push_notification_registered_; | 60 bool push_notification_registered_; |
56 // True once the first drive notification is received with OK state. | 61 // True once the first drive notification is received with OK state. |
57 bool push_notification_enabled_; | 62 bool push_notification_enabled_; |
58 | 63 |
59 // TODO(calvinlo): Polling variables to go here. | 64 // Timer to trigger fetching changes for incremental sync. |
65 base::RepeatingTimer<DriveNotificationManager> polling_timer_; | |
satorux1
2013/04/19 04:12:13
I thought you wanted to remove the polling code??
calvinlo
2013/04/19 06:15:09
Removed. Sorry, I originally based this patch on h
| |
60 | 66 |
61 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); | 67 DISALLOW_COPY_AND_ASSIGN(DriveNotificationManager); |
62 }; | 68 }; |
63 | 69 |
64 } // namespace google_apis | 70 } // namespace google_apis |
65 | 71 |
66 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ | 72 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_NOTIFICATION_MANAGER_H_ |
OLD | NEW |