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 "sync/api/sync_change.h"
20 class ExtensionSpecifics
;
23 namespace extensions
{
27 // A class that encapsulates the synced properties of an Extension.
28 class ExtensionSyncData
{
30 enum OptionalBoolean
{
37 ExtensionSyncData(const Extension
& extension
,
39 bool incognito_enabled
,
41 OptionalBoolean all_urls_enabled
);
44 // For constructing an ExtensionSyncData from received sync data.
45 // May return null if the sync data was invalid.
46 static scoped_ptr
<ExtensionSyncData
> CreateFromSyncData(
47 const syncer::SyncData
& sync_data
);
48 static scoped_ptr
<ExtensionSyncData
> CreateFromSyncChange(
49 const syncer::SyncChange
& sync_change
);
51 // Retrieve sync data from this class.
52 syncer::SyncData
GetSyncData() const;
53 syncer::SyncChange
GetSyncChange(
54 syncer::SyncChange::SyncChangeType change_type
) const;
56 // Convert an ExtensionSyncData back out to a sync structure.
57 void PopulateExtensionSpecifics(sync_pb::ExtensionSpecifics
* specifics
) const;
59 // Populate this class from sync inputs. Returns true if the input was valid.
60 bool PopulateFromExtensionSpecifics(
61 const sync_pb::ExtensionSpecifics
& specifics
);
63 void set_uninstalled(bool uninstalled
);
65 const std::string
& id() const { return id_
; }
67 // Version-independent properties (i.e., used even when the
68 // version of the currently-installed extension doesn't match
70 bool uninstalled() const { return uninstalled_
; }
71 bool enabled() const { return enabled_
; }
72 bool incognito_enabled() const { return incognito_enabled_
; }
73 bool remote_install() const { return remote_install_
; }
74 OptionalBoolean
all_urls_enabled() const { return all_urls_enabled_
; }
75 bool installed_by_custodian() const { return installed_by_custodian_
; }
77 // Version-dependent properties (i.e., should be used only when the
78 // version of the currenty-installed extension matches |version|).
79 const Version
& version() const { return version_
; }
80 const GURL
& update_url() const { return update_url_
; }
81 // Used only for debugging.
82 const std::string
& name() const { return name_
; }
85 // Populate this class from sync inputs.
86 bool PopulateFromSyncData(const syncer::SyncData
& sync_data
);
91 bool incognito_enabled_
;
93 OptionalBoolean all_urls_enabled_
;
94 bool installed_by_custodian_
;
100 } // namespace extensions
102 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_