1// Copyright 2014 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#ifndef COMPONENTS_INVALIDATION_INVALIDATOR_STORAGE_H_
6#define COMPONENTS_INVALIDATION_INVALIDATOR_STORAGE_H_
7
8#include "base/compiler_specific.h"
9#include "base/macros.h"
10#include "base/threading/thread_checker.h"
11#include "components/invalidation/invalidation_state_tracker.h"
12
13class PrefRegistrySimple;
14class PrefService;
15
16namespace user_prefs {
17class PrefRegistrySyncable;
18}
19
20namespace invalidation {
21
22// Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers
23// to use PrefService as persistence for invalidation state. It is not thread
24// safe, and lives on the UI thread.
25class InvalidatorStorage : public syncer::InvalidationStateTracker {
26 public:
27  // |pref_service| may not be NULL and must outlive |this|.
28  explicit InvalidatorStorage(PrefService* pref_service);
29  virtual ~InvalidatorStorage();
30
31  // Register prefs to be used by per-Profile instances of this class which
32  // store invalidation state in Profile prefs.
33  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
34
35  // Register prefs to be used by a device-global instance of this class which
36  // stores invalidation state in local state. This is used on Chrome OS only.
37  static void RegisterPrefs(PrefRegistrySimple* registry);
38
39  // InvalidationStateTracker implementation.
40  virtual void ClearAndSetNewClientId(const std::string& client_id) OVERRIDE;
41  virtual std::string GetInvalidatorClientId() const OVERRIDE;
42  virtual void SetBootstrapData(const std::string& data) OVERRIDE;
43  virtual std::string GetBootstrapData() const OVERRIDE;
44  virtual void SetSavedInvalidations(
45      const syncer::UnackedInvalidationsMap& map) OVERRIDE;
46  virtual syncer::UnackedInvalidationsMap GetSavedInvalidations()
47      const OVERRIDE;
48  virtual void Clear() OVERRIDE;
49
50 private:
51  base::ThreadChecker thread_checker_;
52
53  PrefService* const pref_service_;
54
55  DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage);
56};
57
58}  // namespace invalidation
59
60#endif  // COMPONENTS_INVALIDATION_INVALIDATOR_STORAGE_H_
61