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
3 // found in the LICENSE file.
5 // An implementation of SyncNotifier that wraps InvalidationNotifier
8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "jingle/notifier/base/notifier_options.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"
23 #include "sync/notifier/invalidator.h"
24 #include "sync/notifier/invalidator_registrar.h"
27 class SingleThreadTaskRunner
;
31 class SyncNetworkChannel
;
32 class GCMNetworkChannelDelegate
;
34 // Callback type for function that creates SyncNetworkChannel. This function
35 // gets passed into NonBlockingInvalidator constructor.
36 typedef base::Callback
<scoped_ptr
<SyncNetworkChannel
>(void)>
37 NetworkChannelCreator
;
39 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator
41 // InvalidationHandler to "observe" our Core via WeakHandle.
42 public InvalidationHandler
{
44 // |invalidation_state_tracker| must be initialized.
45 NonBlockingInvalidator(
46 NetworkChannelCreator network_channel_creator
,
47 const std::string
& invalidator_client_id
,
48 const UnackedInvalidationsMap
& saved_invalidations
,
49 const std::string
& invalidation_bootstrap_data
,
50 const WeakHandle
<InvalidationStateTracker
>&
51 invalidation_state_tracker
,
52 const std::string
& client_info
,
53 const scoped_refptr
<net::URLRequestContextGetter
>&
54 request_context_getter
);
56 virtual ~NonBlockingInvalidator();
58 // Invalidator implementation.
59 virtual void RegisterHandler(InvalidationHandler
* handler
) OVERRIDE
;
60 virtual void UpdateRegisteredIds(InvalidationHandler
* handler
,
61 const ObjectIdSet
& ids
) OVERRIDE
;
62 virtual void UnregisterHandler(InvalidationHandler
* handler
) OVERRIDE
;
63 virtual InvalidatorState
GetInvalidatorState() const OVERRIDE
;
64 virtual void UpdateCredentials(
65 const std::string
& email
, const std::string
& token
) OVERRIDE
;
67 // InvalidationHandler implementation.
68 virtual void OnInvalidatorStateChange(InvalidatorState state
) OVERRIDE
;
69 virtual void OnIncomingInvalidation(
70 const ObjectIdInvalidationMap
& invalidation_map
) OVERRIDE
;
71 virtual std::string
GetOwnerName() const OVERRIDE
;
73 // Static functions to construct callback that creates network channel for
74 // SyncSystemResources. The goal is to pass network channel to invalidator at
75 // the same time not exposing channel specific parameters to invalidator and
76 // channel implementation to client of invalidator.
77 static NetworkChannelCreator
MakePushClientChannelCreator(
78 const notifier::NotifierOptions
& notifier_options
);
79 static NetworkChannelCreator
MakeGCMNetworkChannelCreator(
80 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter
,
81 scoped_ptr
<GCMNetworkChannelDelegate
> delegate
);
83 struct InitializeOptions
;
86 InvalidatorRegistrar registrar_
;
88 // The real guts of NonBlockingInvalidator, which allows this class to live
89 // completely on the parent thread.
90 scoped_refptr
<Core
> core_
;
91 scoped_refptr
<base::SingleThreadTaskRunner
> parent_task_runner_
;
92 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner_
;
94 base::WeakPtrFactory
<NonBlockingInvalidator
> weak_ptr_factory_
;
96 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator
);
101 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_