OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // A class that manages the registration of types for server-issued |
| 6 // notifications. |
| 7 |
| 8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_REGISTRATION_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SYNC_NOTIFIER_REGISTRATION_MANAGER_H_ |
| 10 |
| 11 #include <map> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "base/non_thread_safe.h" |
| 15 #include "chrome/browser/sync/syncable/model_type.h" |
| 16 |
| 17 namespace invalidation { |
| 18 class InvalidationClient; |
| 19 class ObjectId; |
| 20 class RegistrationUpdateResult; |
| 21 } // namespace |
| 22 |
| 23 namespace sync_notifier { |
| 24 |
| 25 class RegistrationManager { |
| 26 public: |
| 27 // Does not take ownership of |invalidation_client_|. |
| 28 explicit RegistrationManager( |
| 29 invalidation::InvalidationClient* invalidation_client); |
| 30 |
| 31 ~RegistrationManager(); |
| 32 |
| 33 // If |model_type| is valid, starts the process to register it and |
| 34 // returns true. Otherwise, returns false. |
| 35 bool RegisterType(syncable::ModelType model_type); |
| 36 |
| 37 // Returns true iff |model_type| has been successfully registered. |
| 38 // Note that IsRegistered(model_type) may not immediately (or ever) |
| 39 // return true after calling RegisterType(model_type). |
| 40 // |
| 41 // Currently only used by unit tests. |
| 42 bool IsRegistered(syncable::ModelType model_type) const; |
| 43 |
| 44 // TODO(akalin): We will eventually need an UnregisterType(). |
| 45 |
| 46 // Marks the registration for the |model_type| lost and re-registers |
| 47 // it. |
| 48 void MarkRegistrationLost(syncable::ModelType model_type); |
| 49 |
| 50 // Marks all registrations lost and re-registers them. |
| 51 void MarkAllRegistrationsLost(); |
| 52 |
| 53 private: |
| 54 enum RegistrationStatus { |
| 55 // Registration request has not yet been sent. |
| 56 UNREGISTERED, |
| 57 // Registration request has been sent; waiting on confirmation. |
| 58 PENDING, |
| 59 // Registration has been confirmed. |
| 60 REGISTERED, |
| 61 }; |
| 62 |
| 63 typedef std::map<syncable::ModelType, RegistrationStatus> |
| 64 RegistrationStatusMap; |
| 65 |
| 66 // Calls invalidation_client_->Register() on |object_id|. sets |
| 67 // it->second to UNREGISTERED -> PENDING. |
| 68 void RegisterObject(const invalidation::ObjectId& object_id, |
| 69 RegistrationStatusMap::iterator it); |
| 70 |
| 71 void OnRegister(const invalidation::RegistrationUpdateResult& result); |
| 72 |
| 73 NonThreadSafe non_thread_safe_; |
| 74 // Weak pointer. |
| 75 invalidation::InvalidationClient* invalidation_client_; |
| 76 RegistrationStatusMap registration_status_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(RegistrationManager); |
| 79 }; |
| 80 |
| 81 } // namespace sync_notifier |
| 82 |
| 83 #endif // CHROME_BROWSER_SYNC_NOTIFIER_REGISTRATION_MANAGER_H_ |
OLD | NEW |