Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / extension_sync_data.h
blob2d2c03ac187baffb008f0b600fa8c97dbd017d4a
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/version.h"
12 #include "extensions/common/constants.h"
13 #include "sync/api/string_ordinal.h"
14 #include "sync/api/sync_change.h"
15 #include "url/gurl.h"
17 namespace syncer {
18 class SyncData;
21 namespace sync_pb {
22 class AppSpecifics;
23 class ExtensionSpecifics;
26 namespace extensions {
28 class Extension;
30 // A class that encapsulates the synced properties of an App or Extension.
31 // Corresponds to an ExtensionSpecifics or an AppSpecifics proto (note that an
32 // AppSpecifics itself includes an ExtensionSpecifics).
33 class ExtensionSyncData {
34 public:
35 enum OptionalBoolean {
36 BOOLEAN_UNSET,
37 BOOLEAN_TRUE,
38 BOOLEAN_FALSE
41 struct LinkedAppIconInfo {
42 LinkedAppIconInfo();
43 ~LinkedAppIconInfo();
45 GURL url;
46 int size;
49 // Extension constructor.
50 ExtensionSyncData(const Extension& extension,
51 bool enabled,
52 int disable_reasons,
53 bool incognito_enabled,
54 bool remote_install,
55 OptionalBoolean all_urls_enabled);
56 // App constructor.
57 ExtensionSyncData(const Extension& extension,
58 bool enabled,
59 int disable_reasons,
60 bool incognito_enabled,
61 bool remote_install,
62 OptionalBoolean all_urls_enabled,
63 const syncer::StringOrdinal& app_launch_ordinal,
64 const syncer::StringOrdinal& page_ordinal,
65 extensions::LaunchType launch_type);
66 ~ExtensionSyncData();
68 // For constructing an ExtensionSyncData from received sync data.
69 // May return null if the sync data was invalid.
70 static scoped_ptr<ExtensionSyncData> CreateFromSyncData(
71 const syncer::SyncData& sync_data);
72 static scoped_ptr<ExtensionSyncData> CreateFromSyncChange(
73 const syncer::SyncChange& sync_change);
75 // Retrieve sync data from this class.
76 syncer::SyncData GetSyncData() const;
77 syncer::SyncChange GetSyncChange(
78 syncer::SyncChange::SyncChangeType change_type) const;
80 bool is_app() const { return is_app_; }
82 const std::string& id() const { return id_; }
84 // Version-independent properties (i.e., used even when the version of the
85 // currently-installed extension doesn't match |version|).
86 bool uninstalled() const { return uninstalled_; }
87 bool enabled() const { return enabled_; }
88 bool supports_disable_reasons() const { return supports_disable_reasons_; }
89 int disable_reasons() const { return disable_reasons_; }
90 bool incognito_enabled() const { return incognito_enabled_; }
91 bool remote_install() const { return remote_install_; }
92 OptionalBoolean all_urls_enabled() const { return all_urls_enabled_; }
93 bool installed_by_custodian() const { return installed_by_custodian_; }
95 // Version-dependent properties (i.e., should be used only when the
96 // version of the currently-installed extension matches |version|).
97 const base::Version& version() const { return version_; }
98 void set_version(const base::Version& version) { version_ = version; }
99 const GURL& update_url() const { return update_url_; }
100 // Used only for debugging.
101 const std::string& name() const { return name_; }
103 // Everything below is App-specific - only set for Apps, not Extensions.
105 // These ordinals aren't necessarily valid. Some applications don't have
106 // valid ordinals because they don't appear on the new tab page.
107 const syncer::StringOrdinal& app_launch_ordinal() const {
108 return app_launch_ordinal_;
110 const syncer::StringOrdinal& page_ordinal() const { return page_ordinal_; }
111 extensions::LaunchType launch_type() const { return launch_type_; }
112 const std::string& bookmark_app_url() const { return bookmark_app_url_; }
113 const std::string& bookmark_app_description() const {
114 return bookmark_app_description_;
116 const std::string& bookmark_app_icon_color() const {
117 return bookmark_app_icon_color_;
119 const std::vector<LinkedAppIconInfo>& linked_icons() const {
120 return linked_icons_;
123 private:
124 FRIEND_TEST_ALL_PREFIXES(ExtensionSyncDataTest,
125 ExtensionSyncDataForExtension);
127 ExtensionSyncData();
129 // Populate this class from sync inputs. Return true if the input was valid.
130 bool PopulateFromSyncData(const syncer::SyncData& sync_data);
131 bool PopulateFromExtensionSpecifics(
132 const sync_pb::ExtensionSpecifics& specifics);
133 bool PopulateFromAppSpecifics(const sync_pb::AppSpecifics& specifics);
135 // Convert an ExtensionSyncData back out to a sync ExtensionSpecifics.
136 void ToExtensionSpecifics(sync_pb::ExtensionSpecifics* specifics) const;
138 // Convert an ExtensionSyncData back out to a sync AppSpecifics.
139 void ToAppSpecifics(sync_pb::AppSpecifics* specifics) const;
141 bool is_app_;
143 std::string id_;
144 bool uninstalled_;
145 bool enabled_;
146 // |supports_disable_reasons_| is true if the optional |disable_reasons_| was
147 // set to some value in the extension_specifics.proto. If not,
148 // |disable_reasons_| is given a default value and |supports_disable_reasons_|
149 // is false.
150 bool supports_disable_reasons_;
151 int disable_reasons_;
152 bool incognito_enabled_;
153 bool remote_install_;
154 OptionalBoolean all_urls_enabled_;
155 bool installed_by_custodian_;
156 base::Version version_;
157 GURL update_url_;
158 std::string name_;
160 // App-specific fields.
161 syncer::StringOrdinal app_launch_ordinal_;
162 syncer::StringOrdinal page_ordinal_;
163 extensions::LaunchType launch_type_;
164 std::string bookmark_app_url_;
165 std::string bookmark_app_description_;
166 std::string bookmark_app_icon_color_;
167 std::vector<LinkedAppIconInfo> linked_icons_;
170 } // namespace extensions
172 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_