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

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

Issue 221963003: Reduce dependency of TiclInvalidationService on Profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_listen_notifications. Created 6 years, 8 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
« no previous file with comments | « sync/notifier/invalidation_state_tracker.h ('k') | sync/notifier/non_blocking_invalidator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_INVALIDATOR_H_ 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.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 "jingle/notifier/base/notifier_options.h" 18 #include "jingle/notifier/base/notifier_options.h"
19 #include "sync/base/sync_export.h" 19 #include "sync/base/sync_export.h"
20 #include "sync/internal_api/public/util/weak_handle.h"
21 #include "sync/notifier/invalidation_handler.h"
22 #include "sync/notifier/invalidation_state_tracker.h" 20 #include "sync/notifier/invalidation_state_tracker.h"
23 #include "sync/notifier/invalidator.h" 21 #include "sync/notifier/invalidator.h"
24 #include "sync/notifier/invalidator_registrar.h" 22 #include "sync/notifier/invalidator_registrar.h"
23 #include "sync/notifier/invalidator_state.h"
24 #include "sync/notifier/unacked_invalidation_set.h"
25 25
26 namespace base { 26 namespace base {
27 class SingleThreadTaskRunner; 27 class SingleThreadTaskRunner;
28 } // namespace base 28 } // namespace base
29 29
30 namespace syncer { 30 namespace syncer {
31 class SyncNetworkChannel; 31 class SyncNetworkChannel;
32 class GCMNetworkChannelDelegate; 32 class GCMNetworkChannelDelegate;
33 33
34 // Callback type for function that creates SyncNetworkChannel. This function 34 // Callback type for function that creates SyncNetworkChannel. This function
35 // gets passed into NonBlockingInvalidator constructor. 35 // gets passed into NonBlockingInvalidator constructor.
36 typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)> 36 typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)>
37 NetworkChannelCreator; 37 NetworkChannelCreator;
38 38
39 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator 39 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator
40 : public Invalidator, 40 : public Invalidator,
41 // InvalidationHandler to "observe" our Core via WeakHandle. 41 public InvalidationStateTracker {
42 public InvalidationHandler {
43 public: 42 public:
44 // |invalidation_state_tracker| must be initialized. 43 // |invalidation_state_tracker| must be initialized and must outlive |this|.
45 NonBlockingInvalidator( 44 NonBlockingInvalidator(
46 NetworkChannelCreator network_channel_creator, 45 NetworkChannelCreator network_channel_creator,
47 const std::string& invalidator_client_id, 46 const std::string& invalidator_client_id,
48 const UnackedInvalidationsMap& saved_invalidations, 47 const UnackedInvalidationsMap& saved_invalidations,
49 const std::string& invalidation_bootstrap_data, 48 const std::string& invalidation_bootstrap_data,
50 const WeakHandle<InvalidationStateTracker>& 49 InvalidationStateTracker* invalidation_state_tracker,
51 invalidation_state_tracker,
52 const std::string& client_info, 50 const std::string& client_info,
53 const scoped_refptr<net::URLRequestContextGetter>& 51 const scoped_refptr<net::URLRequestContextGetter>&
54 request_context_getter); 52 request_context_getter);
55 53
56 virtual ~NonBlockingInvalidator(); 54 virtual ~NonBlockingInvalidator();
57 55
58 // Invalidator implementation. 56 // Invalidator implementation.
59 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; 57 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE;
60 virtual void UpdateRegisteredIds(InvalidationHandler* handler, 58 virtual void UpdateRegisteredIds(InvalidationHandler* handler,
61 const ObjectIdSet& ids) OVERRIDE; 59 const ObjectIdSet& ids) OVERRIDE;
62 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; 60 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE;
63 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; 61 virtual InvalidatorState GetInvalidatorState() const OVERRIDE;
64 virtual void UpdateCredentials( 62 virtual void UpdateCredentials(
65 const std::string& email, const std::string& token) OVERRIDE; 63 const std::string& email, const std::string& token) OVERRIDE;
66 virtual void RequestDetailedStatus( 64 virtual void RequestDetailedStatus(
67 base::Callback<void(const base::DictionaryValue&)> callback) const 65 base::Callback<void(const base::DictionaryValue&)> callback) const
68 OVERRIDE; 66 OVERRIDE;
69 67
70 // InvalidationHandler implementation.
71 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
72 virtual void OnIncomingInvalidation(
73 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
74 virtual std::string GetOwnerName() const OVERRIDE;
75
76 // Static functions to construct callback that creates network channel for 68 // Static functions to construct callback that creates network channel for
77 // SyncSystemResources. The goal is to pass network channel to invalidator at 69 // SyncSystemResources. The goal is to pass network channel to invalidator at
78 // the same time not exposing channel specific parameters to invalidator and 70 // the same time not exposing channel specific parameters to invalidator and
79 // channel implementation to client of invalidator. 71 // channel implementation to client of invalidator.
80 static NetworkChannelCreator MakePushClientChannelCreator( 72 static NetworkChannelCreator MakePushClientChannelCreator(
81 const notifier::NotifierOptions& notifier_options); 73 const notifier::NotifierOptions& notifier_options);
82 static NetworkChannelCreator MakeGCMNetworkChannelCreator( 74 static NetworkChannelCreator MakeGCMNetworkChannelCreator(
83 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
84 scoped_ptr<GCMNetworkChannelDelegate> delegate); 76 scoped_ptr<GCMNetworkChannelDelegate> delegate);
77
78 // These methods are forwarded to the invalidation_state_tracker_.
79 virtual void ClearAndSetNewClientId(const std::string& data) OVERRIDE;
80 virtual std::string GetInvalidatorClientId() const OVERRIDE;
81 virtual void SetBootstrapData(const std::string& data) OVERRIDE;
82 virtual std::string GetBootstrapData() const OVERRIDE;
83 virtual void SetSavedInvalidations(
84 const UnackedInvalidationsMap& states) OVERRIDE;
85 virtual UnackedInvalidationsMap GetSavedInvalidations() const OVERRIDE;
86 virtual void Clear() OVERRIDE;
87
85 private: 88 private:
89 void OnInvalidatorStateChange(InvalidatorState state);
90 void OnIncomingInvalidation(const ObjectIdInvalidationMap& invalidation_map);
91 std::string GetOwnerName() const;
92
93 friend class NonBlockingInvalidatorTestDelegate;
94
86 struct InitializeOptions; 95 struct InitializeOptions;
87 class Core; 96 class Core;
88 97
89 InvalidatorRegistrar registrar_; 98 InvalidatorRegistrar registrar_;
99 InvalidationStateTracker* invalidation_state_tracker_;
90 100
91 // The real guts of NonBlockingInvalidator, which allows this class to live 101 // The real guts of NonBlockingInvalidator, which allows this class to live
92 // completely on the parent thread. 102 // completely on the parent thread.
93 scoped_refptr<Core> core_; 103 scoped_refptr<Core> core_;
94 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; 104 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
95 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 105 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
96 106
97 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; 107 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_;
98 108
99 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); 109 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator);
100 }; 110 };
101 111
102 } // namespace syncer 112 } // namespace syncer
103 113
104 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ 114 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
OLDNEW
« no previous file with comments | « sync/notifier/invalidation_state_tracker.h ('k') | sync/notifier/non_blocking_invalidator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698