extension_data.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
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#ifndef CHROME_BROWSER_SYNC_GLUE_EXTENSION_DATA_H_
6#define CHROME_BROWSER_SYNC_GLUE_EXTENSION_DATA_H_
7#pragma once
8
9// ExtensionData is the class used to manage the client and server
10// versions of the data for a particular extension.
11
12#include <map>
13
14#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
15
16namespace browser_sync {
17
18class ExtensionData {
19 public:
20  enum Source {
21    CLIENT,
22    SERVER,
23  };
24
25  // Returns an ExtensionData constructed from the given data from the
26  // given source.  merged_data() will be equal to |data| and
27  // NeedsUpdate(source) will return false.
28  static ExtensionData FromData(
29      Source source, const sync_pb::ExtensionSpecifics& data);
30
31  // Implicit copy constructor and assignment operator welcome.
32
33  // Returns the version of the data that all sources should
34  // eventually have.
35  const sync_pb::ExtensionSpecifics& merged_data() const;
36
37  // Returns whether or not the data from the given source needs to be
38  // updated from merged_data().
39  bool NeedsUpdate(Source source) const;
40
41  // Stores the given data as being from the given source, merging it
42  // into merged_data().  May change what NeedsUpdate() returns for
43  // any source.
44  void SetData(
45      Source source, bool merge_user_properties,
46      const sync_pb::ExtensionSpecifics& data);
47
48  // Marks the data from the given data as updated,
49  // i.e. NeedsUpdate(source) will return false.
50  void ResolveData(Source source);
51
52 private:
53  typedef std::map<Source, sync_pb::ExtensionSpecifics> SourceDataMap;
54  SourceDataMap source_data_;
55  sync_pb::ExtensionSpecifics merged_data_;
56
57  // This is private; clients must use FromData().
58  ExtensionData();
59};
60
61}  // namespace
62
63#endif  // CHROME_BROWSER_SYNC_GLUE_EXTENSION_DATA_H_
64