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
3 // found in the LICENSE file.
5 // A simple wrapper around invalidation::InvalidationClient that
6 // handles all the startup/shutdown details and hookups.
8 #ifndef SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_
9 #define SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_
14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "google/cacheinvalidation/include/invalidation-listener.h"
20 #include "sync/notifier/chrome_system_resources.h"
21 #include "sync/notifier/invalidation_state_tracker.h"
22 #include "sync/notifier/state_writer.h"
23 #include "sync/syncable/model_type.h"
24 #include "sync/syncable/model_type_payload_map.h"
25 #include "sync/util/weak_handle.h"
28 class XmppTaskParentInterface
;
31 namespace sync_notifier
{
33 using invalidation::InvalidationListener
;
35 class CacheInvalidationPacketHandler
;
36 class RegistrationManager
;
38 // ChromeInvalidationClient is not thread-safe and lives on the sync
40 class ChromeInvalidationClient
41 : public InvalidationListener
,
48 virtual void OnInvalidate(
49 const syncable::ModelTypePayloadMap
& type_payloads
) = 0;
51 virtual void OnSessionStatusChanged(bool has_session
) = 0;
54 ChromeInvalidationClient();
57 virtual ~ChromeInvalidationClient();
59 // Does not take ownership of |listener| or |state_writer|.
60 // |invalidation_state_tracker| must be initialized.
61 // |base_task| must still be non-NULL.
63 const std::string
& client_id
, const std::string
& client_info
,
64 const std::string
& state
,
65 const InvalidationVersionMap
& initial_max_invalidation_versions
,
66 const browser_sync::WeakHandle
<InvalidationStateTracker
>&
67 invalidation_state_tracker
,
69 StateWriter
* state_writer
,
70 base::WeakPtr
<buzz::XmppTaskParentInterface
> base_task
);
74 // Changes the task used to |base_task|, which must still be
75 // non-NULL. Must only be called between calls to Start() and
77 void ChangeBaseTask(base::WeakPtr
<buzz::XmppTaskParentInterface
> base_task
);
79 // Register the sync types that we're interested in getting
80 // notifications for. May be called at any time.
81 void RegisterTypes(syncable::ModelTypeSet types
);
83 virtual void WriteState(const std::string
& state
) OVERRIDE
;
85 // invalidation::InvalidationListener implementation.
87 invalidation::InvalidationClient
* client
) OVERRIDE
;
88 virtual void Invalidate(
89 invalidation::InvalidationClient
* client
,
90 const invalidation::Invalidation
& invalidation
,
91 const invalidation::AckHandle
& ack_handle
) OVERRIDE
;
92 virtual void InvalidateUnknownVersion(
93 invalidation::InvalidationClient
* client
,
94 const invalidation::ObjectId
& object_id
,
95 const invalidation::AckHandle
& ack_handle
) OVERRIDE
;
96 virtual void InvalidateAll(
97 invalidation::InvalidationClient
* client
,
98 const invalidation::AckHandle
& ack_handle
) OVERRIDE
;
99 virtual void InformRegistrationStatus(
100 invalidation::InvalidationClient
* client
,
101 const invalidation::ObjectId
& object_id
,
102 InvalidationListener::RegistrationState reg_state
) OVERRIDE
;
103 virtual void InformRegistrationFailure(
104 invalidation::InvalidationClient
* client
,
105 const invalidation::ObjectId
& object_id
,
107 const std::string
& error_message
) OVERRIDE
;
108 virtual void ReissueRegistrations(
109 invalidation::InvalidationClient
* client
,
110 const std::string
& prefix
,
111 int prefix_length
) OVERRIDE
;
112 virtual void InformError(
113 invalidation::InvalidationClient
* client
,
114 const invalidation::ErrorInfo
& error_info
) OVERRIDE
;
117 friend class ChromeInvalidationClientTest
;
119 void EmitInvalidation(
120 syncable::ModelTypeSet types
, const std::string
& payload
);
122 base::NonThreadSafe non_thread_safe_
;
123 ChromeSystemResources chrome_system_resources_
;
124 InvalidationVersionMap max_invalidation_versions_
;
125 browser_sync::WeakHandle
<InvalidationStateTracker
>
126 invalidation_state_tracker_
;
128 StateWriter
* state_writer_
;
129 scoped_ptr
<invalidation::InvalidationClient
> invalidation_client_
;
130 scoped_ptr
<CacheInvalidationPacketHandler
>
131 cache_invalidation_packet_handler_
;
132 scoped_ptr
<RegistrationManager
> registration_manager_
;
133 // Stored to pass to |registration_manager_| on start.
134 syncable::ModelTypeSet registered_types_
;
137 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient
);
140 } // namespace sync_notifier
142 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_