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_
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"
23 class ExtensionSpecifics
;
26 namespace extensions
{
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
{
35 enum OptionalBoolean
{
41 struct LinkedAppIconInfo
{
49 // Extension constructor.
50 ExtensionSyncData(const Extension
& extension
,
53 bool incognito_enabled
,
55 OptionalBoolean all_urls_enabled
);
57 ExtensionSyncData(const Extension
& extension
,
60 bool incognito_enabled
,
62 OptionalBoolean all_urls_enabled
,
63 const syncer::StringOrdinal
& app_launch_ordinal
,
64 const syncer::StringOrdinal
& page_ordinal
,
65 extensions::LaunchType launch_type
);
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 void set_uninstalled(bool uninstalled
);
82 bool is_app() const { return is_app_
; }
84 const std::string
& id() const { return id_
; }
86 // Version-independent properties (i.e., used even when the version of the
87 // currently-installed extension doesn't match |version|).
88 bool uninstalled() const { return uninstalled_
; }
89 bool enabled() const { return enabled_
; }
90 bool supports_disable_reasons() const { return supports_disable_reasons_
; }
91 int disable_reasons() const { return disable_reasons_
; }
92 bool incognito_enabled() const { return incognito_enabled_
; }
93 bool remote_install() const { return remote_install_
; }
94 OptionalBoolean
all_urls_enabled() const { return all_urls_enabled_
; }
95 bool installed_by_custodian() const { return installed_by_custodian_
; }
97 // Version-dependent properties (i.e., should be used only when the
98 // version of the currently-installed extension matches |version|).
99 const Version
& version() const { return version_
; }
100 const GURL
& update_url() const { return update_url_
; }
101 // Used only for debugging.
102 const std::string
& name() const { return name_
; }
104 // Everything below is App-specific - only set for Apps, not Extensions.
106 // These ordinals aren't necessarily valid. Some applications don't have
107 // valid ordinals because they don't appear on the new tab page.
108 const syncer::StringOrdinal
& app_launch_ordinal() const {
109 return app_launch_ordinal_
;
111 const syncer::StringOrdinal
& page_ordinal() const { return page_ordinal_
; }
112 extensions::LaunchType
launch_type() const { return launch_type_
; }
113 const std::string
& bookmark_app_url() const { return bookmark_app_url_
; }
114 const std::string
& bookmark_app_description() const {
115 return bookmark_app_description_
;
117 const std::string
& bookmark_app_icon_color() const {
118 return bookmark_app_icon_color_
;
120 const std::vector
<LinkedAppIconInfo
>& linked_icons() const {
121 return linked_icons_
;
125 FRIEND_TEST_ALL_PREFIXES(ExtensionSyncDataTest
,
126 ExtensionSyncDataForExtension
);
130 // Populate this class from sync inputs. Return true if the input was valid.
131 bool PopulateFromSyncData(const syncer::SyncData
& sync_data
);
132 bool PopulateFromExtensionSpecifics(
133 const sync_pb::ExtensionSpecifics
& specifics
);
134 bool PopulateFromAppSpecifics(const sync_pb::AppSpecifics
& specifics
);
136 // Convert an ExtensionSyncData back out to a sync ExtensionSpecifics.
137 void ToExtensionSpecifics(sync_pb::ExtensionSpecifics
* specifics
) const;
139 // Convert an ExtensionSyncData back out to a sync AppSpecifics.
140 void ToAppSpecifics(sync_pb::AppSpecifics
* specifics
) const;
147 // |supports_disable_reasons_| is true if the optional |disable_reasons_| was
148 // set to some value in the extension_specifics.proto. If not,
149 // |disable_reasons_| is given a default value and |supports_disable_reasons_|
151 bool supports_disable_reasons_
;
152 int disable_reasons_
;
153 bool incognito_enabled_
;
154 bool remote_install_
;
155 OptionalBoolean all_urls_enabled_
;
156 bool installed_by_custodian_
;
161 // App-specific fields.
162 syncer::StringOrdinal app_launch_ordinal_
;
163 syncer::StringOrdinal page_ordinal_
;
164 extensions::LaunchType launch_type_
;
165 std::string bookmark_app_url_
;
166 std::string bookmark_app_description_
;
167 std::string bookmark_app_icon_color_
;
168 std::vector
<LinkedAppIconInfo
> linked_icons_
;
171 } // namespace extensions
173 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_