summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/notifier/registration_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/sync/notifier/registration_manager.h')
-rw-r--r--chrome/browser/sync/notifier/registration_manager.h117
1 files changed, 25 insertions, 92 deletions
diff --git a/chrome/browser/sync/notifier/registration_manager.h b/chrome/browser/sync/notifier/registration_manager.h
index ea46127..d7edb04 100644
--- a/chrome/browser/sync/notifier/registration_manager.h
+++ b/chrome/browser/sync/notifier/registration_manager.h
@@ -12,59 +12,35 @@
#include <map>
#include "base/basictypes.h"
-#include "base/time.h"
-#include "base/timer.h"
+#include "base/gtest_prod_util.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/sync/syncable/model_type.h"
-// For invalidation::RegistrationState.
#include "google/cacheinvalidation/invalidation-client.h"
namespace sync_notifier {
-// Manages the details of registering types for invalidation.
-// Implements exponential backoff for repeated registration attempts
-// to the invalidation client.
-//
-// TODO(akalin): Consolidate exponential backoff code. Other
-// implementations include the syncer thread (both versions) and XMPP
-// retries. The most sophisticated one is URLRequestThrottler; making
-// that generic should work for everyone.
class RegistrationManager {
- public:
- // Constants for exponential backoff (used by tests).
- static const int kInitialRegistrationDelaySeconds;
- static const int kRegistrationDelayExponent;
- static const double kRegistrationDelayMaxJitter;
- static const int kMinRegistrationDelaySeconds;
- static const int kMaxRegistrationDelaySeconds;
-
- // Types used by testing functions.
- struct PendingRegistrationInfo {
- // Last time a registration request was actually sent.
- base::Time last_registration_request;
- // Time the registration was attempted.
- base::Time registration_attempt;
- // The calculated delay of the pending registration (which may be
- // negative).
- base::TimeDelta delay;
- // The delay of the timer, which should be max(delay, 0).
- base::TimeDelta actual_delay;
- };
- // Map from types with pending registrations to info about the
- // pending registration.
- typedef std::map<syncable::ModelType, PendingRegistrationInfo>
- PendingRegistrationMap;
+ friend class RegistrationManagerTest;
+
+ FRIEND_TEST_ALL_PREFIXES(RegistrationManagerTest, RegisterType);
+ FRIEND_TEST_ALL_PREFIXES(RegistrationManagerTest, UnregisterType);
+ FRIEND_TEST_ALL_PREFIXES(RegistrationManagerTest, MarkRegistrationLost);
+ FRIEND_TEST_ALL_PREFIXES(RegistrationManagerTest, MarkAllRegistrationsLost);
+ public:
// Does not take ownership of |invalidation_client_|.
explicit RegistrationManager(
invalidation::InvalidationClient* invalidation_client);
~RegistrationManager();
- // Registers all types included in the given set and sets all other
- // types to be unregistered.
void SetRegisteredTypes(const syncable::ModelTypeSet& types);
+ // Returns true iff |model_type| is currently registered.
+ //
+ // Currently only used by unit tests.
+ bool IsRegistered(syncable::ModelType model_type) const;
+
// Marks the registration for the |model_type| lost and re-registers
// it.
void MarkRegistrationLost(syncable::ModelType model_type);
@@ -72,69 +48,26 @@ class RegistrationManager {
// Marks all registrations lost and re-registers them.
void MarkAllRegistrationsLost();
- // The functions below should only be used in tests.
-
- // Gets all currently-registered types.
- syncable::ModelTypeSet GetRegisteredTypes() const;
-
- // Gets all pending registrations and their next min delays.
- PendingRegistrationMap GetPendingRegistrations() const;
+ private:
+ typedef std::map<syncable::ModelType, invalidation::RegistrationState>
+ RegistrationStatusMap;
- // Run pending registrations immediately.
- void FirePendingRegistrationsForTest();
+ // Registers the given |model_type|, which must be valid.
+ void RegisterType(syncable::ModelType model_type);
- private:
- struct RegistrationStatus {
- // The model type for which this is the status.
- syncable::ModelType model_type;
- // The parent registration manager.
- RegistrationManager* registration_manager;
-
- // The current registration state.
- invalidation::RegistrationState state;
- // When we last sent a registration request.
- base::Time last_registration_request;
- // When we last tried to register.
- base::Time last_registration_attempt;
- // The calculated delay of any pending registration (which may be
- // negative).
- base::TimeDelta delay;
- // The minimum time to wait until any next registration attempt.
- // Increased after each consecutive failure.
- base::TimeDelta next_delay;
- // The actual timer for registration.
- base::OneShotTimer<RegistrationStatus> registration_timer;
-
- RegistrationStatus();
-
- // Calls registration_manager->DoRegister(model_type). (needed by
- // |registration_timer|).
- void DoRegister();
- };
-
- // If |is_retry| is not set, registers the given type immediately
- // and resets all backoff parameters. If |is_retry| is set,
- // registers the given type at some point in the future and
- // increases the delay until the next retry.
- void TryRegisterType(syncable::ModelType model_type,
- bool is_retry);
-
- // Registers the given type, which must be valid, immediately.
- // Updates |last_registration| in the appropriate
- // RegistrationStatus. Should only be called by
- // RegistrationStatus::DoRegister().
- void DoRegisterType(syncable::ModelType model_type);
-
- // Unregisters the given type, which must be valid.
void UnregisterType(syncable::ModelType model_type);
- // Returns true iff the given type, which must be valid, is registered.
- bool IsTypeRegistered(syncable::ModelType model_type) const;
+ // Calls invalidation_client_->Register() on |object_id|. sets
+ // it->second to UNREGISTERED -> PENDING.
+ void RegisterObject(const invalidation::ObjectId& object_id,
+ RegistrationStatusMap::iterator it);
+
+ void OnRegister(const invalidation::RegistrationUpdateResult& result);
base::NonThreadSafe non_thread_safe_;
- RegistrationStatus registration_statuses_[syncable::MODEL_TYPE_COUNT];
// Weak pointer.
invalidation::InvalidationClient* invalidation_client_;
+ RegistrationStatusMap registration_status_;
DISALLOW_COPY_AND_ASSIGN(RegistrationManager);
};