OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // A simple wrapper around invalidation::InvalidationClient that | 5 // A simple wrapper around invalidation::InvalidationClient that |
6 // handles all the startup/shutdown details and hookups. | 6 // handles all the startup/shutdown details and hookups. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ |
9 #define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 9 #define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/non_thread_safe.h" | 14 #include "base/non_thread_safe.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
16 #include "chrome/browser/sync/notifier/chrome_system_resources.h" | 16 #include "chrome/browser/sync/notifier/chrome_system_resources.h" |
| 17 #include "chrome/browser/sync/syncable/model_type.h" |
17 #include "google/cacheinvalidation/invalidation-client.h" | 18 #include "google/cacheinvalidation/invalidation-client.h" |
18 | 19 |
19 namespace buzz { | 20 namespace buzz { |
20 class XmppClient; | 21 class XmppClient; |
21 } // namespace | 22 } // namespace |
22 | 23 |
23 namespace sync_notifier { | 24 namespace sync_notifier { |
24 | 25 |
25 class CacheInvalidationPacketHandler; | 26 class CacheInvalidationPacketHandler; |
26 | 27 |
27 // TODO(akalin): Hook this up to a NetworkChangeNotifier so we can | 28 // TODO(akalin): Hook this up to a NetworkChangeNotifier so we can |
28 // properly notify invalidation_client_. | 29 // properly notify invalidation_client_. |
29 | 30 |
30 class ChromeInvalidationClient { | 31 class ChromeInvalidationClient : public invalidation::InvalidationListener { |
31 public: | 32 public: |
| 33 class Listener { |
| 34 public: |
| 35 virtual ~Listener(); |
| 36 |
| 37 virtual void OnInvalidate(syncable::ModelType model_type) = 0; |
| 38 |
| 39 virtual void OnInvalidateAll() = 0; |
| 40 }; |
| 41 |
32 ChromeInvalidationClient(); | 42 ChromeInvalidationClient(); |
33 | 43 |
34 ~ChromeInvalidationClient(); | 44 // Calls Stop(). |
| 45 virtual ~ChromeInvalidationClient(); |
35 | 46 |
36 // Does not take ownership of |listener| nor |xmpp_client|. | 47 // Does not take ownership of |listener| nor |xmpp_client|. |
37 void Start( | 48 void Start( |
38 const std::string& client_id, | 49 const std::string& client_id, Listener* listener, |
39 invalidation::InvalidationListener* listener, | |
40 buzz::XmppClient* xmpp_client); | 50 buzz::XmppClient* xmpp_client); |
41 | 51 |
42 void Stop(); | 52 void Stop(); |
43 | 53 |
44 // The following functions must only be called between calls to | 54 // Register the sync types that we're interested in getting |
45 // Start() and Stop(). See invalidation-client.h for documentation. | 55 // notifications for. Must only be called between calls to Start() |
| 56 // and Stop(). |
| 57 void RegisterTypes(); |
46 | 58 |
47 void Register(const invalidation::ObjectId& oid, | 59 // invalidation::InvalidationListener implementation. |
48 invalidation::RegistrationCallback* callback); | 60 // |
| 61 // TODO(akalin): Move these into a private inner class. |
49 | 62 |
50 void Unregister(const invalidation::ObjectId& oid, | 63 virtual void Invalidate(const invalidation::Invalidation& invalidation, |
51 invalidation::RegistrationCallback* callback); | 64 invalidation::Closure* callback); |
| 65 |
| 66 virtual void InvalidateAll(invalidation::Closure* callback); |
| 67 |
| 68 virtual void AllRegistrationsLost(invalidation::Closure* callback); |
| 69 |
| 70 virtual void RegistrationLost(const invalidation::ObjectId& object_id, |
| 71 invalidation::Closure* callback); |
52 | 72 |
53 private: | 73 private: |
54 NonThreadSafe non_thread_safe_; | 74 NonThreadSafe non_thread_safe_; |
55 ChromeSystemResources chrome_system_resources_; | 75 ChromeSystemResources chrome_system_resources_; |
| 76 Listener* listener_; |
56 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; | 77 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |
57 scoped_ptr<CacheInvalidationPacketHandler> | 78 scoped_ptr<CacheInvalidationPacketHandler> |
58 cache_invalidation_packet_handler_; | 79 cache_invalidation_packet_handler_; |
59 | 80 |
| 81 void OnRegister(const invalidation::RegistrationUpdateResult& result); |
| 82 |
60 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); | 83 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); |
61 }; | 84 }; |
62 | 85 |
63 } // namespace sync_notifier | 86 } // namespace sync_notifier |
64 | 87 |
65 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 88 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ |
OLD | NEW |