• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_EXTENSIONS_EXTENSION_SYNC_DATA_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_
7 
8 #include <string>
9 
10 #include "base/version.h"
11 #include "sync/api/sync_change.h"
12 #include "url/gurl.h"
13 
14 namespace syncer {
15 class SyncData;
16 }
17 
18 namespace sync_pb {
19 class ExtensionSpecifics;
20 }
21 
22 namespace extensions {
23 
24 class Extension;
25 
26 // A class that encapsulates the synced properties of an Extension.
27 class ExtensionSyncData {
28  public:
29   ExtensionSyncData();
30   explicit ExtensionSyncData(const syncer::SyncData& sync_data);
31   explicit ExtensionSyncData(const syncer::SyncChange& sync_change);
32   ExtensionSyncData(const Extension& extension,
33                     bool enabled,
34                     bool incognito_enabled,
35                     bool remote_install);
36   ~ExtensionSyncData();
37 
38   // Retrieve sync data from this class.
39   syncer::SyncData GetSyncData() const;
40   syncer::SyncChange GetSyncChange(
41       syncer::SyncChange::SyncChangeType change_type) const;
42 
43   // Convert an ExtensionSyncData back out to a sync structure.
44   void PopulateExtensionSpecifics(sync_pb::ExtensionSpecifics* specifics) const;
45 
46   // Populate this class from sync inputs.
47   void PopulateFromExtensionSpecifics(
48       const sync_pb::ExtensionSpecifics& specifics);
49 
50   void set_uninstalled(bool uninstalled);
51 
id()52   const std::string& id() const { return id_; }
53 
54   // Version-independent properties (i.e., used even when the
55   // version of the currently-installed extension doesn't match
56   // |version|).
uninstalled()57   bool uninstalled() const { return uninstalled_; }
enabled()58   bool enabled() const { return enabled_; }
incognito_enabled()59   bool incognito_enabled() const { return incognito_enabled_; }
remote_install()60   bool remote_install() const { return remote_install_; }
61 
62   // Version-dependent properties (i.e., should be used only when the
63   // version of the currenty-installed extension matches |version|).
version()64   const Version& version() const { return version_; }
update_url()65   const GURL& update_url() const { return update_url_; }
66   // Used only for debugging.
name()67   const std::string& name() const { return name_; }
68 
69  private:
70   // Populate this class from sync inputs.
71   void PopulateFromSyncData(const syncer::SyncData& sync_data);
72 
73   std::string id_;
74   bool uninstalled_;
75   bool enabled_;
76   bool incognito_enabled_;
77   bool remote_install_;
78   Version version_;
79   GURL update_url_;
80   std::string name_;
81 };
82 
83 }  // namespace extensions
84 
85 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_
86