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 // An implementation of SyncNotifier that wraps InvalidationNotifier | 5 // An implementation of SyncNotifier that wraps InvalidationNotifier |
6 // on its own thread. | 6 // on its own thread. |
7 | 7 |
8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | |
19 #include "jingle/notifier/base/notifier_options.h" | 18 #include "jingle/notifier/base/notifier_options.h" |
20 #include "sync/internal_api/public/util/weak_handle.h" | 19 #include "sync/internal_api/public/util/weak_handle.h" |
| 20 #include "sync/notifier/invalidation_notifier_base.h" |
21 #include "sync/notifier/invalidation_state_tracker.h" | 21 #include "sync/notifier/invalidation_state_tracker.h" |
22 #include "sync/notifier/sync_notifier.h" | |
23 #include "sync/notifier/sync_notifier_observer.h" | 22 #include "sync/notifier/sync_notifier_observer.h" |
24 | 23 |
25 namespace base { | 24 namespace base { |
26 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
27 } // namespace base | 26 } // namespace base |
28 | 27 |
29 namespace syncer { | 28 namespace syncer { |
30 | 29 |
31 class NonBlockingInvalidationNotifier | 30 class NonBlockingInvalidationNotifier |
32 : public SyncNotifier, | 31 : public InvalidationNotifierBase, |
33 // SyncNotifierObserver to "observe" our Core via WeakHandle. | 32 // SyncNotifierObserver to "observe" our Core via WeakHandle. |
34 public SyncNotifierObserver { | 33 public SyncNotifierObserver { |
35 public: | 34 public: |
36 // |invalidation_state_tracker| must be initialized. | 35 // |invalidation_state_tracker| must be initialized. |
37 NonBlockingInvalidationNotifier( | 36 NonBlockingInvalidationNotifier( |
38 const notifier::NotifierOptions& notifier_options, | 37 const notifier::NotifierOptions& notifier_options, |
39 const InvalidationVersionMap& initial_max_invalidation_versions, | 38 const InvalidationVersionMap& initial_max_invalidation_versions, |
40 const std::string& initial_invalidation_state, | 39 const std::string& initial_invalidation_state, |
41 const syncer::WeakHandle<InvalidationStateTracker>& | 40 const syncer::WeakHandle<InvalidationStateTracker>& |
42 invalidation_state_tracker, | 41 invalidation_state_tracker, |
43 const std::string& client_info); | 42 const std::string& client_info); |
44 | 43 |
45 virtual ~NonBlockingInvalidationNotifier(); | 44 virtual ~NonBlockingInvalidationNotifier(); |
46 | 45 |
47 // SyncNotifier implementation. | 46 // SyncNotifier implementation. |
48 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 47 virtual void AddHandler(SyncNotifierObserver* observer) OVERRIDE; |
49 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 48 virtual void RemoveHandler(SyncNotifierObserver* observer) OVERRIDE; |
| 49 virtual void ReloadHandlers() OVERRIDE; |
50 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 50 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
51 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 51 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
52 virtual void UpdateCredentials( | 52 virtual void UpdateCredentials( |
53 const std::string& email, const std::string& token) OVERRIDE; | 53 const std::string& email, const std::string& token) OVERRIDE; |
54 virtual void UpdateEnabledTypes( | |
55 syncer::ModelTypeSet enabled_types) OVERRIDE; | |
56 virtual void SendNotification( | 54 virtual void SendNotification( |
57 syncer::ModelTypeSet changed_types) OVERRIDE; | 55 syncer::ModelTypeSet changed_types) OVERRIDE; |
58 | 56 |
59 // SyncNotifierObserver implementation. | 57 // SyncNotifierObserver implementation. |
| 58 virtual ObjectIdSet GetHandledIds() OVERRIDE; |
60 virtual void OnNotificationsEnabled() OVERRIDE; | 59 virtual void OnNotificationsEnabled() OVERRIDE; |
61 virtual void OnNotificationsDisabled( | 60 virtual void OnNotificationsDisabled( |
62 NotificationsDisabledReason reason) OVERRIDE; | 61 NotificationsDisabledReason reason) OVERRIDE; |
63 virtual void OnIncomingNotification( | 62 virtual void OnIncomingNotification( |
64 const syncer::ModelTypePayloadMap& type_payloads, | 63 const ObjectIdPayloadMap& id_payloads, |
65 IncomingNotificationSource source) OVERRIDE; | 64 IncomingNotificationSource source) OVERRIDE; |
66 | 65 |
67 private: | 66 private: |
68 class Core; | 67 class Core; |
69 | 68 |
70 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; | 69 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; |
71 | 70 |
72 // Our observers (which must live on the parent thread). | |
73 ObserverList<SyncNotifierObserver> observers_; | |
74 | |
75 // The real guts of NonBlockingInvalidationNotifier, which allows | 71 // The real guts of NonBlockingInvalidationNotifier, which allows |
76 // this class to live completely on the parent thread. | 72 // this class to live completely on the parent thread. |
77 scoped_refptr<Core> core_; | 73 scoped_refptr<Core> core_; |
78 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | 74 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
79 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 75 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
80 | 76 |
81 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); | 77 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); |
82 }; | 78 }; |
83 | 79 |
84 } // namespace syncer | 80 } // namespace syncer |
85 | 81 |
86 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | 82 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |