roll skia to 4057
[chromium-blink-merge.git] / sync / notifier / chrome_invalidation_client.h
blob45f50370ab5164d4039ed4d5432eaed619a7d46b
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.
4 //
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_
10 #pragma once
12 #include <string>
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"
27 namespace buzz {
28 class XmppTaskParentInterface;
29 } // namespace buzz
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
39 // thread.
40 class ChromeInvalidationClient
41 : public InvalidationListener,
42 public StateWriter {
43 public:
44 class Listener {
45 public:
46 virtual ~Listener();
48 virtual void OnInvalidate(
49 const syncable::ModelTypePayloadMap& type_payloads) = 0;
51 virtual void OnSessionStatusChanged(bool has_session) = 0;
54 ChromeInvalidationClient();
56 // Calls Stop().
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.
62 void Start(
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,
68 Listener* listener,
69 StateWriter* state_writer,
70 base::WeakPtr<buzz::XmppTaskParentInterface> base_task);
72 void Stop();
74 // Changes the task used to |base_task|, which must still be
75 // non-NULL. Must only be called between calls to Start() and
76 // Stop().
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.
86 virtual void Ready(
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,
106 bool is_transient,
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;
116 private:
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_;
127 Listener* listener_;
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_;
135 bool ticl_ready_;
137 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient);
140 } // namespace sync_notifier
142 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_