Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: sync/notifier/non_blocking_invalidation_notifier.h

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FOR_THE_HORDE Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "jingle/notifier/base/notifier_options.h" 17 #include "jingle/notifier/base/notifier_options.h"
19 #include "sync/internal_api/public/util/weak_handle.h" 18 #include "sync/internal_api/public/util/weak_handle.h"
20 #include "sync/notifier/invalidation_state_tracker.h" 19 #include "sync/notifier/invalidation_state_tracker.h"
21 #include "sync/notifier/sync_notifier.h" 20 #include "sync/notifier/sync_notifier.h"
21 #include "sync/notifier/sync_notifier_helper.h"
22 #include "sync/notifier/sync_notifier_observer.h" 22 #include "sync/notifier/sync_notifier_observer.h"
23 23
24 namespace base { 24 namespace base {
25 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
26 } // namespace base 26 } // namespace base
27 27
28 namespace syncer { 28 namespace syncer {
29 29
30 class NonBlockingInvalidationNotifier 30 class NonBlockingInvalidationNotifier
31 : public SyncNotifier, 31 : public SyncNotifier,
32 // SyncNotifierObserver to "observe" our Core via WeakHandle. 32 // SyncNotifierObserver to "observe" our Core via WeakHandle.
33 public SyncNotifierObserver { 33 public SyncNotifierObserver {
34 public: 34 public:
35 // |invalidation_state_tracker| must be initialized. 35 // |invalidation_state_tracker| must be initialized.
36 NonBlockingInvalidationNotifier( 36 NonBlockingInvalidationNotifier(
37 const notifier::NotifierOptions& notifier_options, 37 const notifier::NotifierOptions& notifier_options,
38 const InvalidationVersionMap& initial_max_invalidation_versions, 38 const InvalidationVersionMap& initial_max_invalidation_versions,
39 const std::string& initial_invalidation_state, 39 const std::string& initial_invalidation_state,
40 const WeakHandle<InvalidationStateTracker>& 40 const WeakHandle<InvalidationStateTracker>&
41 invalidation_state_tracker, 41 invalidation_state_tracker,
42 const std::string& client_info); 42 const std::string& client_info);
43 43
44 virtual ~NonBlockingInvalidationNotifier(); 44 virtual ~NonBlockingInvalidationNotifier();
45 45
46 // SyncNotifier implementation. 46 // SyncNotifier implementation.
47 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; 47 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler,
48 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; 48 const ObjectIdSet& ids) OVERRIDE;
49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; 49 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; 50 virtual void SetStateDeprecated(const std::string& state) OVERRIDE;
51 virtual void UpdateCredentials( 51 virtual void UpdateCredentials(
52 const std::string& email, const std::string& token) OVERRIDE; 52 const std::string& email, const std::string& token) OVERRIDE;
53 virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) OVERRIDE;
54 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; 53 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE;
55 54
56 // SyncNotifierObserver implementation. 55 // SyncNotifierObserver implementation.
57 virtual void OnNotificationsEnabled() OVERRIDE; 56 virtual void OnNotificationsEnabled() OVERRIDE;
58 virtual void OnNotificationsDisabled( 57 virtual void OnNotificationsDisabled(
59 NotificationsDisabledReason reason) OVERRIDE; 58 NotificationsDisabledReason reason) OVERRIDE;
60 virtual void OnIncomingNotification( 59 virtual void OnIncomingNotification(
61 const ModelTypePayloadMap& type_payloads, 60 const ObjectIdPayloadMap& id_payloads,
62 IncomingNotificationSource source) OVERRIDE; 61 IncomingNotificationSource source) OVERRIDE;
63 62
64 private: 63 private:
65 class Core; 64 class Core;
66 65
67 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; 66 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_;
68 67
69 // Our observers (which must live on the parent thread). 68 SyncNotifierHelper helper_;
70 ObserverList<SyncNotifierObserver> observers_;
71 69
72 // The real guts of NonBlockingInvalidationNotifier, which allows 70 // The real guts of NonBlockingInvalidationNotifier, which allows
73 // this class to live completely on the parent thread. 71 // this class to live completely on the parent thread.
74 scoped_refptr<Core> core_; 72 scoped_refptr<Core> core_;
75 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; 73 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
76 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 74 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
77 75
78 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); 76 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier);
79 }; 77 };
80 78
81 } // namespace syncer 79 } // namespace syncer
82 80
83 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ 81 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698