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 #include "chrome/browser/extensions/extension_sync_data.h" | 5 #include "chrome/browser/extensions/extension_sync_data.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/extensions/app_sync_data.h" | 8 #include "chrome/browser/extensions/app_sync_data.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/common/extensions/manifest_url_handler.h" | 10 #include "chrome/common/extensions/manifest_url_handler.h" |
11 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
12 #include "sync/api/sync_data.h" | 12 #include "sync/api/sync_data.h" |
13 #include "sync/protocol/extension_specifics.pb.h" | 13 #include "sync/protocol/extension_specifics.pb.h" |
14 #include "sync/protocol/sync.pb.h" | 14 #include "sync/protocol/sync.pb.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 ExtensionSyncData::ExtensionSyncData() | 18 ExtensionSyncData::ExtensionSyncData() |
19 : uninstalled_(false), | 19 : uninstalled_(false), |
20 enabled_(false), | 20 enabled_(false), |
21 incognito_enabled_(false) { | 21 incognito_enabled_(false), |
| 22 remote_install_(false) { |
22 } | 23 } |
23 | 24 |
24 ExtensionSyncData::ExtensionSyncData(const syncer::SyncData& sync_data) | 25 ExtensionSyncData::ExtensionSyncData(const syncer::SyncData& sync_data) |
25 : uninstalled_(false), | 26 : uninstalled_(false), |
26 enabled_(false), | 27 enabled_(false), |
27 incognito_enabled_(false) { | 28 incognito_enabled_(false), |
| 29 remote_install_(false) { |
28 PopulateFromSyncData(sync_data); | 30 PopulateFromSyncData(sync_data); |
29 } | 31 } |
30 | 32 |
31 ExtensionSyncData::ExtensionSyncData(const syncer::SyncChange& sync_change) | 33 ExtensionSyncData::ExtensionSyncData(const syncer::SyncChange& sync_change) |
32 : uninstalled_( | 34 : uninstalled_(sync_change.change_type() == |
33 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE), | 35 syncer::SyncChange::ACTION_DELETE), |
34 enabled_(false), | 36 enabled_(false), |
35 incognito_enabled_(false) { | 37 incognito_enabled_(false), |
| 38 remote_install_(false) { |
36 PopulateFromSyncData(sync_change.sync_data()); | 39 PopulateFromSyncData(sync_change.sync_data()); |
37 } | 40 } |
38 | 41 |
39 ExtensionSyncData::ExtensionSyncData(const Extension& extension, | 42 ExtensionSyncData::ExtensionSyncData(const Extension& extension, |
40 bool enabled, | 43 bool enabled, |
41 bool incognito_enabled) | 44 bool incognito_enabled, |
42 : id_(extension.id()), | 45 bool remote_install) |
| 46 : id_(extension.id()), |
43 uninstalled_(false), | 47 uninstalled_(false), |
44 enabled_(enabled), | 48 enabled_(enabled), |
45 incognito_enabled_(incognito_enabled), | 49 incognito_enabled_(incognito_enabled), |
| 50 remote_install_(remote_install), |
46 version_(extension.from_bookmark() ? base::Version("0") | 51 version_(extension.from_bookmark() ? base::Version("0") |
47 : *extension.version()), | 52 : *extension.version()), |
48 update_url_(ManifestURL::GetUpdateURL(&extension)), | 53 update_url_(ManifestURL::GetUpdateURL(&extension)), |
49 name_(extension.non_localized_name()) { | 54 name_(extension.non_localized_name()) { |
50 } | 55 } |
51 | 56 |
52 ExtensionSyncData::~ExtensionSyncData() {} | 57 ExtensionSyncData::~ExtensionSyncData() {} |
53 | 58 |
54 syncer::SyncData ExtensionSyncData::GetSyncData() const { | 59 syncer::SyncData ExtensionSyncData::GetSyncData() const { |
55 sync_pb::EntitySpecifics specifics; | 60 sync_pb::EntitySpecifics specifics; |
56 PopulateExtensionSpecifics(specifics.mutable_extension()); | 61 PopulateExtensionSpecifics(specifics.mutable_extension()); |
57 | 62 |
58 return syncer::SyncData::CreateLocalData(id_, name_, specifics); | 63 return syncer::SyncData::CreateLocalData(id_, name_, specifics); |
59 } | 64 } |
60 | 65 |
61 syncer::SyncChange ExtensionSyncData::GetSyncChange( | 66 syncer::SyncChange ExtensionSyncData::GetSyncChange( |
62 syncer::SyncChange::SyncChangeType change_type) const { | 67 syncer::SyncChange::SyncChangeType change_type) const { |
63 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); | 68 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); |
64 } | 69 } |
65 | 70 |
66 void ExtensionSyncData::PopulateExtensionSpecifics( | 71 void ExtensionSyncData::PopulateExtensionSpecifics( |
67 sync_pb::ExtensionSpecifics* specifics) const { | 72 sync_pb::ExtensionSpecifics* specifics) const { |
68 DCHECK(Extension::IdIsValid(id_)); | 73 DCHECK(Extension::IdIsValid(id_)); |
69 specifics->set_id(id_); | 74 specifics->set_id(id_); |
70 specifics->set_update_url(update_url_.spec()); | 75 specifics->set_update_url(update_url_.spec()); |
71 specifics->set_version(version_.GetString()); | 76 specifics->set_version(version_.GetString()); |
72 specifics->set_enabled(enabled_); | 77 specifics->set_enabled(enabled_); |
73 specifics->set_incognito_enabled(incognito_enabled_); | 78 specifics->set_incognito_enabled(incognito_enabled_); |
| 79 specifics->set_remote_install(remote_install_); |
74 specifics->set_name(name_); | 80 specifics->set_name(name_); |
75 } | 81 } |
76 | 82 |
77 void ExtensionSyncData::PopulateFromExtensionSpecifics( | 83 void ExtensionSyncData::PopulateFromExtensionSpecifics( |
78 const sync_pb::ExtensionSpecifics& specifics) { | 84 const sync_pb::ExtensionSpecifics& specifics) { |
79 if (!Extension::IdIsValid(specifics.id())) { | 85 if (!Extension::IdIsValid(specifics.id())) { |
80 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 86 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
81 } | 87 } |
82 | 88 |
83 Version specifics_version(specifics.version()); | 89 Version specifics_version(specifics.version()); |
84 if (!specifics_version.IsValid()) | 90 if (!specifics_version.IsValid()) |
85 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 91 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
86 | 92 |
87 // The update URL must be either empty or valid. | 93 // The update URL must be either empty or valid. |
88 GURL specifics_update_url(specifics.update_url()); | 94 GURL specifics_update_url(specifics.update_url()); |
89 if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) { | 95 if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) { |
90 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 96 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
91 } | 97 } |
92 | 98 |
93 id_ = specifics.id(); | 99 id_ = specifics.id(); |
94 update_url_ = specifics_update_url; | 100 update_url_ = specifics_update_url; |
95 version_ = specifics_version; | 101 version_ = specifics_version; |
96 enabled_ = specifics.enabled(); | 102 enabled_ = specifics.enabled(); |
97 incognito_enabled_ = specifics.incognito_enabled(); | 103 incognito_enabled_ = specifics.incognito_enabled(); |
| 104 remote_install_ = specifics.remote_install(); |
98 name_ = specifics.name(); | 105 name_ = specifics.name(); |
99 } | 106 } |
100 | 107 |
101 void ExtensionSyncData::set_uninstalled(bool uninstalled) { | 108 void ExtensionSyncData::set_uninstalled(bool uninstalled) { |
102 uninstalled_ = uninstalled; | 109 uninstalled_ = uninstalled; |
103 } | 110 } |
104 | 111 |
105 void ExtensionSyncData::PopulateFromSyncData( | 112 void ExtensionSyncData::PopulateFromSyncData( |
106 const syncer::SyncData& sync_data) { | 113 const syncer::SyncData& sync_data) { |
107 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); | 114 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); |
108 | 115 |
109 if (entity_specifics.has_extension()) { | 116 if (entity_specifics.has_extension()) { |
110 PopulateFromExtensionSpecifics(entity_specifics.extension()); | 117 PopulateFromExtensionSpecifics(entity_specifics.extension()); |
111 } else { | 118 } else { |
112 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; | 119 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; |
113 } | 120 } |
114 } | 121 } |
115 | 122 |
116 } // namespace extensions | 123 } // namespace extensions |
OLD | NEW |