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 #ifndef CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
13 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 14 #include "sync/notifier/invalidation_util.h" |
14 | 15 |
15 class Profile; | 16 class Profile; |
16 | 17 |
17 namespace syncer { | 18 namespace syncer { |
18 class SyncNotifierObserver; | 19 class SyncNotifierObserver; |
19 } // namespace | 20 } // namespace |
20 | 21 |
21 namespace browser_sync { | 22 namespace browser_sync { |
22 | 23 |
23 // A bridge that converts Chrome events on the UI thread to sync | 24 // A bridge that converts Chrome events on the UI thread to sync |
24 // notifications on the sync task runner. | 25 // notifications on the sync task runner. |
25 // | 26 // |
26 // Listens to NOTIFICATION_SYNC_REFRESH_LOCAL and | 27 // Listens to NOTIFICATION_SYNC_REFRESH_LOCAL and |
27 // NOTIFICATION_SYNC_REFRESH_REMOTE (on the UI thread) and triggers | 28 // NOTIFICATION_SYNC_REFRESH_REMOTE (on the UI thread) and triggers |
28 // each observer's OnIncomingNotification method on these | 29 // each observer's OnIncomingNotification method on these |
29 // notifications (on the sync task runner). | 30 // notifications (on the sync task runner). |
30 class ChromeSyncNotificationBridge : public content::NotificationObserver { | 31 class ChromeSyncNotificationBridge : public content::NotificationObserver { |
31 public: | 32 public: |
32 // Must be created and destroyed on the UI thread. | 33 // Must be created and destroyed on the UI thread. |
33 ChromeSyncNotificationBridge( | 34 ChromeSyncNotificationBridge( |
34 const Profile* profile, | 35 const Profile* profile, |
35 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner); | 36 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner); |
36 virtual ~ChromeSyncNotificationBridge(); | 37 virtual ~ChromeSyncNotificationBridge(); |
37 | 38 |
38 // Must be called on the UI thread. | 39 // Must be called on the UI thread. |
39 void UpdateEnabledTypes(const syncer::ModelTypeSet enabled_types); | 40 void UpdateEnabledTypes(const syncer::ModelTypeSet enabled_types); |
40 | 41 |
41 // Must be called on the sync task runner. | 42 // Must be called on the sync task runner. |
42 virtual void AddObserver(syncer::SyncNotifierObserver* observer); | 43 virtual void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, |
43 virtual void RemoveObserver(syncer::SyncNotifierObserver* observer); | 44 const syncer::ObjectIdSet& ids); |
44 | 45 |
45 // NotificationObserver implementation. Called on UI thread. | 46 // NotificationObserver implementation. Called on UI thread. |
46 virtual void Observe(int type, | 47 virtual void Observe(int type, |
47 const content::NotificationSource& source, | 48 const content::NotificationSource& source, |
48 const content::NotificationDetails& details) OVERRIDE; | 49 const content::NotificationDetails& details) OVERRIDE; |
49 | 50 |
50 private: | 51 private: |
51 // Inner class to hold all the bits used on |sync_task_runner_|. | 52 // Inner class to hold all the bits used on |sync_task_runner_|. |
52 class Core; | 53 class Core; |
53 | 54 |
54 const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; | 55 const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
55 | 56 |
56 // Created on the UI thread, used only on |sync_task_runner_|. | 57 // Created on the UI thread, used only on |sync_task_runner_|. |
57 const scoped_refptr<Core> core_; | 58 const scoped_refptr<Core> core_; |
58 | 59 |
59 // Used only on the UI thread. | 60 // Used only on the UI thread. |
60 content::NotificationRegistrar registrar_; | 61 content::NotificationRegistrar registrar_; |
61 syncer::ModelTypeSet enabled_types_; | 62 syncer::ModelTypeSet enabled_types_; |
62 }; | 63 }; |
63 | 64 |
64 } // namespace browser_sync | 65 } // namespace browser_sync |
65 | 66 |
66 #endif // CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ | 67 #endif // CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_ |
OLD | NEW |