OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/version.h" | 11 #include "base/version.h" |
11 #include "sync/api/sync_change.h" | 12 #include "sync/api/sync_change.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 namespace syncer { | 15 namespace syncer { |
15 class SyncData; | 16 class SyncData; |
16 } | 17 } |
17 | 18 |
18 namespace sync_pb { | 19 namespace sync_pb { |
19 class ExtensionSpecifics; | 20 class ExtensionSpecifics; |
20 } | 21 } |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 class Extension; | 25 class Extension; |
25 | 26 |
26 // A class that encapsulates the synced properties of an Extension. | 27 // A class that encapsulates the synced properties of an Extension. |
27 class ExtensionSyncData { | 28 class ExtensionSyncData { |
28 public: | 29 public: |
29 enum OptionalBoolean { | 30 enum OptionalBoolean { |
30 BOOLEAN_UNSET, | 31 BOOLEAN_UNSET, |
31 BOOLEAN_TRUE, | 32 BOOLEAN_TRUE, |
32 BOOLEAN_FALSE | 33 BOOLEAN_FALSE |
33 }; | 34 }; |
34 | 35 |
35 ExtensionSyncData(); | 36 ExtensionSyncData(); |
36 explicit ExtensionSyncData(const syncer::SyncData& sync_data); | |
37 explicit ExtensionSyncData(const syncer::SyncChange& sync_change); | |
38 ExtensionSyncData(const Extension& extension, | 37 ExtensionSyncData(const Extension& extension, |
39 bool enabled, | 38 bool enabled, |
40 bool incognito_enabled, | 39 bool incognito_enabled, |
41 bool remote_install, | 40 bool remote_install, |
42 OptionalBoolean all_urls_enabled); | 41 OptionalBoolean all_urls_enabled); |
43 ~ExtensionSyncData(); | 42 ~ExtensionSyncData(); |
44 | 43 |
| 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); |
| 50 |
45 // Retrieve sync data from this class. | 51 // Retrieve sync data from this class. |
46 syncer::SyncData GetSyncData() const; | 52 syncer::SyncData GetSyncData() const; |
47 syncer::SyncChange GetSyncChange( | 53 syncer::SyncChange GetSyncChange( |
48 syncer::SyncChange::SyncChangeType change_type) const; | 54 syncer::SyncChange::SyncChangeType change_type) const; |
49 | 55 |
50 // Convert an ExtensionSyncData back out to a sync structure. | 56 // Convert an ExtensionSyncData back out to a sync structure. |
51 void PopulateExtensionSpecifics(sync_pb::ExtensionSpecifics* specifics) const; | 57 void PopulateExtensionSpecifics(sync_pb::ExtensionSpecifics* specifics) const; |
52 | 58 |
53 // Populate this class from sync inputs. | 59 // Populate this class from sync inputs. Returns true if the input was valid. |
54 void PopulateFromExtensionSpecifics( | 60 bool PopulateFromExtensionSpecifics( |
55 const sync_pb::ExtensionSpecifics& specifics); | 61 const sync_pb::ExtensionSpecifics& specifics); |
56 | 62 |
57 void set_uninstalled(bool uninstalled); | 63 void set_uninstalled(bool uninstalled); |
58 | 64 |
59 const std::string& id() const { return id_; } | 65 const std::string& id() const { return id_; } |
60 | 66 |
61 // Version-independent properties (i.e., used even when the | 67 // Version-independent properties (i.e., used even when the |
62 // version of the currently-installed extension doesn't match | 68 // version of the currently-installed extension doesn't match |
63 // |version|). | 69 // |version|). |
64 bool uninstalled() const { return uninstalled_; } | 70 bool uninstalled() const { return uninstalled_; } |
65 bool enabled() const { return enabled_; } | 71 bool enabled() const { return enabled_; } |
66 bool incognito_enabled() const { return incognito_enabled_; } | 72 bool incognito_enabled() const { return incognito_enabled_; } |
67 bool remote_install() const { return remote_install_; } | 73 bool remote_install() const { return remote_install_; } |
68 OptionalBoolean all_urls_enabled() const { return all_urls_enabled_; } | 74 OptionalBoolean all_urls_enabled() const { return all_urls_enabled_; } |
69 bool installed_by_custodian() const { return installed_by_custodian_; } | 75 bool installed_by_custodian() const { return installed_by_custodian_; } |
70 | 76 |
71 // Version-dependent properties (i.e., should be used only when the | 77 // Version-dependent properties (i.e., should be used only when the |
72 // version of the currenty-installed extension matches |version|). | 78 // version of the currenty-installed extension matches |version|). |
73 const Version& version() const { return version_; } | 79 const Version& version() const { return version_; } |
74 const GURL& update_url() const { return update_url_; } | 80 const GURL& update_url() const { return update_url_; } |
75 // Used only for debugging. | 81 // Used only for debugging. |
76 const std::string& name() const { return name_; } | 82 const std::string& name() const { return name_; } |
77 | 83 |
78 private: | 84 private: |
79 // Populate this class from sync inputs. | 85 // Populate this class from sync inputs. |
80 void PopulateFromSyncData(const syncer::SyncData& sync_data); | 86 bool PopulateFromSyncData(const syncer::SyncData& sync_data); |
81 | 87 |
82 std::string id_; | 88 std::string id_; |
83 bool uninstalled_; | 89 bool uninstalled_; |
84 bool enabled_; | 90 bool enabled_; |
85 bool incognito_enabled_; | 91 bool incognito_enabled_; |
86 bool remote_install_; | 92 bool remote_install_; |
87 OptionalBoolean all_urls_enabled_; | 93 OptionalBoolean all_urls_enabled_; |
88 bool installed_by_custodian_; | 94 bool installed_by_custodian_; |
89 Version version_; | 95 Version version_; |
90 GURL update_url_; | 96 GURL update_url_; |
91 std::string name_; | 97 std::string name_; |
92 }; | 98 }; |
93 | 99 |
94 } // namespace extensions | 100 } // namespace extensions |
95 | 101 |
96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ | 102 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_DATA_H_ |
OLD | NEW |