[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_sync_data.h" |
| 6 | |
[email protected] | 418e953e | 2011-04-27 21:30:22 | [diff] [blame] | 7 | #include "base/logging.h" |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 8 | #include "base/metrics/histogram_macros.h" |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 10 | #include "chrome/browser/extensions/convert_web_app.h" |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_service.h" |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 12 | #include "chrome/common/extensions/manifest_handlers/app_icon_color_info.h" |
| 13 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
Christopher Lam | cec8c4f | 2017-10-16 01:38:43 | [diff] [blame] | 14 | #include "chrome/common/extensions/manifest_handlers/app_theme_color_info.h" |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 15 | #include "chrome/common/extensions/manifest_handlers/linked_app_icons.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 16 | #include "components/crx_file/id_util.h" |
skym | 7160384 | 2016-10-10 18:17:31 | [diff] [blame] | 17 | #include "components/sync/model/sync_data.h" |
Max Bogue | fef332d | 2016-07-28 22:09:09 | [diff] [blame] | 18 | #include "components/sync/protocol/app_specifics.pb.h" |
| 19 | #include "components/sync/protocol/extension_specifics.pb.h" |
| 20 | #include "components/sync/protocol/sync.pb.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 21 | #include "extensions/common/extension.h" |
rockot | d554614 | 2014-10-15 00:29:08 | [diff] [blame] | 22 | #include "extensions/common/manifest_url_handlers.h" |
[email protected] | 418e953e | 2011-04-27 21:30:22 | [diff] [blame] | 23 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 24 | using syncer::StringOrdinal; |
| 25 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 26 | namespace extensions { |
| 27 | |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | std::string GetExtensionSpecificsLogMessage( |
| 31 | const sync_pb::ExtensionSpecifics& specifics) { |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 32 | return base::StringPrintf( |
| 33 | "id: %s\nversion: %s\nupdate_url: %s\nenabled: %i\ndisable_reasons: %i", |
| 34 | specifics.id().c_str(), |
| 35 | specifics.version().c_str(), |
| 36 | specifics.update_url().c_str(), |
| 37 | specifics.enabled(), |
| 38 | specifics.disable_reasons()); |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 39 | } |
| 40 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 41 | enum BadSyncDataReason { |
| 42 | // Invalid extension ID. |
| 43 | BAD_EXTENSION_ID, |
| 44 | |
| 45 | // Invalid version. |
| 46 | BAD_VERSION, |
| 47 | |
| 48 | // Invalid update URL. |
| 49 | BAD_UPDATE_URL, |
| 50 | |
| 51 | // No ExtensionSpecifics in the EntitySpecifics. |
| 52 | NO_EXTENSION_SPECIFICS, |
| 53 | |
treib | 29e1b9b1 | 2015-11-11 08:50:56 | [diff] [blame] | 54 | // Not used anymore; still here because of UMA. |
| 55 | DEPRECATED_BAD_DISABLE_REASONS, |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 56 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 57 | // Must be at the end. |
| 58 | NUM_BAD_SYNC_DATA_REASONS |
| 59 | }; |
| 60 | |
| 61 | void RecordBadSyncData(BadSyncDataReason reason) { |
| 62 | UMA_HISTOGRAM_ENUMERATION("Extensions.BadSyncDataReason", reason, |
| 63 | NUM_BAD_SYNC_DATA_REASONS); |
| 64 | } |
| 65 | |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 66 | } // namespace |
| 67 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 68 | ExtensionSyncData::LinkedAppIconInfo::LinkedAppIconInfo() { |
| 69 | } |
| 70 | |
| 71 | ExtensionSyncData::LinkedAppIconInfo::~LinkedAppIconInfo() { |
| 72 | } |
| 73 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 74 | ExtensionSyncData::ExtensionSyncData() |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 75 | : is_app_(false), |
| 76 | uninstalled_(false), |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 77 | enabled_(false), |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 78 | supports_disable_reasons_(false), |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 79 | disable_reasons_(disable_reason::DISABLE_NONE), |
[email protected] | 075b392 | 2014-05-03 06:14:17 | [diff] [blame] | 80 | incognito_enabled_(false), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 81 | remote_install_(false), |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 82 | installed_by_custodian_(false), |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 83 | launch_type_(LAUNCH_TYPE_INVALID) {} |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 84 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 85 | ExtensionSyncData::ExtensionSyncData(const Extension& extension, |
| 86 | bool enabled, |
treib | c119232 | 2015-05-20 12:56:07 | [diff] [blame] | 87 | int disable_reasons, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 88 | bool incognito_enabled, |
rdevlin.cronin | d1aa852 | 2015-02-13 00:25:57 | [diff] [blame] | 89 | bool remote_install, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 90 | bool installed_by_custodian) |
Devlin Cronin | 93beb23d | 2018-05-04 21:17:35 | [diff] [blame] | 91 | : ExtensionSyncData(extension, |
| 92 | enabled, |
| 93 | disable_reasons, |
| 94 | incognito_enabled, |
| 95 | remote_install, |
Devlin Cronin | 93beb23d | 2018-05-04 21:17:35 | [diff] [blame] | 96 | installed_by_custodian, |
| 97 | StringOrdinal(), |
| 98 | StringOrdinal(), |
| 99 | LAUNCH_TYPE_INVALID) {} |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 100 | |
| 101 | ExtensionSyncData::ExtensionSyncData(const Extension& extension, |
| 102 | bool enabled, |
| 103 | int disable_reasons, |
| 104 | bool incognito_enabled, |
| 105 | bool remote_install, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 106 | bool installed_by_custodian, |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 107 | const StringOrdinal& app_launch_ordinal, |
| 108 | const StringOrdinal& page_ordinal, |
| 109 | extensions::LaunchType launch_type) |
| 110 | : is_app_(extension.is_app()), |
| 111 | id_(extension.id()), |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 112 | uninstalled_(false), |
| 113 | enabled_(enabled), |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 114 | supports_disable_reasons_(true), |
treib | c119232 | 2015-05-20 12:56:07 | [diff] [blame] | 115 | disable_reasons_(disable_reasons), |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 116 | incognito_enabled_(incognito_enabled), |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 117 | remote_install_(remote_install), |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 118 | installed_by_custodian_(installed_by_custodian), |
[email protected] | f4263c5 | 2014-04-09 12:40:51 | [diff] [blame] | 119 | version_(extension.from_bookmark() ? base::Version("0") |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 120 | : extension.version()), |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 121 | update_url_(ManifestURL::GetUpdateURL(&extension)), |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 122 | name_(extension.non_localized_name()), |
| 123 | app_launch_ordinal_(app_launch_ordinal), |
| 124 | page_ordinal_(page_ordinal), |
| 125 | launch_type_(launch_type) { |
| 126 | if (is_app_ && extension.from_bookmark()) { |
| 127 | bookmark_app_description_ = extension.description(); |
| 128 | bookmark_app_url_ = AppLaunchInfo::GetLaunchWebURL(&extension).spec(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 129 | bookmark_app_scope_ = GetScopeURLFromBookmarkApp(&extension).spec(); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 130 | bookmark_app_icon_color_ = AppIconColorInfo::GetIconColorString(&extension); |
Christopher Lam | cec8c4f | 2017-10-16 01:38:43 | [diff] [blame] | 131 | bookmark_app_theme_color_ = AppThemeColorInfo::GetThemeColor(&extension); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 132 | extensions::LinkedAppIcons icons = |
| 133 | LinkedAppIcons::GetLinkedAppIcons(&extension); |
| 134 | for (const auto& icon : icons.icons) { |
| 135 | LinkedAppIconInfo linked_icon; |
| 136 | linked_icon.url = icon.url; |
| 137 | linked_icon.size = icon.size; |
| 138 | linked_icons_.push_back(linked_icon); |
| 139 | } |
| 140 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 141 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 142 | |
vmpstr | b8aacbe | 2016-02-26 02:00:48 | [diff] [blame] | 143 | ExtensionSyncData::ExtensionSyncData(const ExtensionSyncData& other) = default; |
| 144 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 145 | ExtensionSyncData::~ExtensionSyncData() {} |
[email protected] | 418e953e | 2011-04-27 21:30:22 | [diff] [blame] | 146 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 147 | // static |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 148 | std::unique_ptr<ExtensionSyncData> ExtensionSyncData::CreateFromSyncData( |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 149 | const syncer::SyncData& sync_data) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 150 | std::unique_ptr<ExtensionSyncData> data(new ExtensionSyncData); |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 151 | if (data->PopulateFromSyncData(sync_data)) |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 152 | return data; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 153 | return nullptr; |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // static |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 157 | std::unique_ptr<ExtensionSyncData> ExtensionSyncData::CreateFromSyncChange( |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 158 | const syncer::SyncChange& sync_change) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 159 | std::unique_ptr<ExtensionSyncData> data( |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 160 | CreateFromSyncData(sync_change.sync_data())); |
| 161 | if (!data.get()) |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 162 | return nullptr; |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 163 | |
treib | ecc63c8d | 2015-09-07 16:34:47 | [diff] [blame] | 164 | if (sync_change.change_type() == syncer::SyncChange::ACTION_DELETE) |
| 165 | data->uninstalled_ = true; |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 166 | return data; |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 169 | syncer::SyncData ExtensionSyncData::GetSyncData() const { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 170 | sync_pb::EntitySpecifics specifics; |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 171 | if (is_app_) |
| 172 | ToAppSpecifics(specifics.mutable_app()); |
| 173 | else |
| 174 | ToExtensionSpecifics(specifics.mutable_extension()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 175 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 176 | return syncer::SyncData::CreateLocalData(id_, name_, specifics); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 177 | } |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 178 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 179 | syncer::SyncChange ExtensionSyncData::GetSyncChange( |
| 180 | syncer::SyncChange::SyncChangeType change_type) const { |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 181 | return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 182 | } |
| 183 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 184 | void ExtensionSyncData::ToExtensionSpecifics( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 185 | sync_pb::ExtensionSpecifics* specifics) const { |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 186 | DCHECK(crx_file::id_util::IdIsValid(id_)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 187 | specifics->set_id(id_); |
| 188 | specifics->set_update_url(update_url_.spec()); |
| 189 | specifics->set_version(version_.GetString()); |
| 190 | specifics->set_enabled(enabled_); |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 191 | if (supports_disable_reasons_) |
| 192 | specifics->set_disable_reasons(disable_reasons_); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 193 | specifics->set_incognito_enabled(incognito_enabled_); |
[email protected] | 075b392 | 2014-05-03 06:14:17 | [diff] [blame] | 194 | specifics->set_remote_install(remote_install_); |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 195 | specifics->set_installed_by_custodian(installed_by_custodian_); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 196 | specifics->set_name(name_); |
[email protected] | 0fac519c | 2011-08-19 18:05:57 | [diff] [blame] | 197 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 198 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 199 | void ExtensionSyncData::ToAppSpecifics(sync_pb::AppSpecifics* specifics) const { |
| 200 | DCHECK(specifics); |
| 201 | // Only sync the ordinal values and launch type if they are valid. |
| 202 | if (app_launch_ordinal_.IsValid()) |
| 203 | specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue()); |
| 204 | if (page_ordinal_.IsValid()) |
| 205 | specifics->set_page_ordinal(page_ordinal_.ToInternalValue()); |
| 206 | |
| 207 | sync_pb::AppSpecifics::LaunchType sync_launch_type = |
| 208 | static_cast<sync_pb::AppSpecifics::LaunchType>(launch_type_); |
| 209 | |
| 210 | // The corresponding validation of this value during processing of an |
treib | c349453 | 2015-07-21 14:51:45 | [diff] [blame] | 211 | // ExtensionSyncData is in ExtensionSyncService::ApplySyncData. |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 212 | if (launch_type_ >= LAUNCH_TYPE_FIRST && launch_type_ < NUM_LAUNCH_TYPES && |
| 213 | sync_pb::AppSpecifics_LaunchType_IsValid(sync_launch_type)) { |
| 214 | specifics->set_launch_type(sync_launch_type); |
| 215 | } |
| 216 | |
| 217 | if (!bookmark_app_url_.empty()) |
| 218 | specifics->set_bookmark_app_url(bookmark_app_url_); |
| 219 | |
| 220 | if (!bookmark_app_description_.empty()) |
| 221 | specifics->set_bookmark_app_description(bookmark_app_description_); |
| 222 | |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 223 | if (!bookmark_app_scope_.empty()) |
| 224 | specifics->set_bookmark_app_scope(bookmark_app_scope_); |
| 225 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 226 | if (!bookmark_app_icon_color_.empty()) |
| 227 | specifics->set_bookmark_app_icon_color(bookmark_app_icon_color_); |
| 228 | |
Christopher Lam | cec8c4f | 2017-10-16 01:38:43 | [diff] [blame] | 229 | if (bookmark_app_theme_color_) |
| 230 | specifics->set_bookmark_app_theme_color(bookmark_app_theme_color_.value()); |
| 231 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 232 | for (const auto& linked_icon : linked_icons_) { |
| 233 | sync_pb::LinkedAppIconInfo* linked_app_icon_info = |
| 234 | specifics->add_linked_app_icons(); |
Alan Cutter | 7fe2485bf | 2018-05-16 06:41:18 | [diff] [blame] | 235 | DCHECK(linked_icon.url.is_valid()); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 236 | linked_app_icon_info->set_url(linked_icon.url.spec()); |
| 237 | linked_app_icon_info->set_size(linked_icon.size); |
| 238 | } |
| 239 | |
| 240 | ToExtensionSpecifics(specifics->mutable_extension()); |
| 241 | } |
| 242 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 243 | bool ExtensionSyncData::PopulateFromExtensionSpecifics( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 244 | const sync_pb::ExtensionSpecifics& specifics) { |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 245 | if (!crx_file::id_util::IdIsValid(specifics.id())) { |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 246 | LOG(ERROR) << "Attempt to sync bad ExtensionSpecifics (bad ID):\n" |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 247 | << GetExtensionSpecificsLogMessage(specifics); |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 248 | RecordBadSyncData(BAD_EXTENSION_ID); |
| 249 | return false; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 250 | } |
| 251 | |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 252 | base::Version specifics_version(specifics.version()); |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 253 | if (!specifics_version.IsValid()) { |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 254 | LOG(ERROR) << "Attempt to sync bad ExtensionSpecifics (bad version):\n" |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 255 | << GetExtensionSpecificsLogMessage(specifics); |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 256 | RecordBadSyncData(BAD_VERSION); |
| 257 | return false; |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 258 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 259 | |
| 260 | // The update URL must be either empty or valid. |
| 261 | GURL specifics_update_url(specifics.update_url()); |
| 262 | if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) { |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 263 | LOG(ERROR) << "Attempt to sync bad ExtensionSpecifics (bad update URL):\n" |
yoz | 768503cd | 2015-02-24 03:40:31 | [diff] [blame] | 264 | << GetExtensionSpecificsLogMessage(specifics); |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 265 | RecordBadSyncData(BAD_UPDATE_URL); |
| 266 | return false; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | id_ = specifics.id(); |
| 270 | update_url_ = specifics_update_url; |
[email protected] | e1adb9a | 2011-09-09 17:42:52 | [diff] [blame] | 271 | version_ = specifics_version; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 272 | enabled_ = specifics.enabled(); |
treib | 231f2bb | 2015-06-09 12:46:24 | [diff] [blame] | 273 | supports_disable_reasons_ = specifics.has_disable_reasons(); |
treib | c119232 | 2015-05-20 12:56:07 | [diff] [blame] | 274 | disable_reasons_ = specifics.disable_reasons(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 275 | incognito_enabled_ = specifics.incognito_enabled(); |
[email protected] | 075b392 | 2014-05-03 06:14:17 | [diff] [blame] | 276 | remote_install_ = specifics.remote_install(); |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 277 | installed_by_custodian_ = specifics.installed_by_custodian(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 278 | name_ = specifics.name(); |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 279 | return true; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 280 | } |
| 281 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 282 | bool ExtensionSyncData::PopulateFromAppSpecifics( |
| 283 | const sync_pb::AppSpecifics& specifics) { |
| 284 | if (!PopulateFromExtensionSpecifics(specifics.extension())) |
| 285 | return false; |
| 286 | |
| 287 | is_app_ = true; |
| 288 | |
| 289 | app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); |
| 290 | page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); |
| 291 | |
| 292 | launch_type_ = specifics.has_launch_type() |
| 293 | ? static_cast<extensions::LaunchType>(specifics.launch_type()) |
| 294 | : LAUNCH_TYPE_INVALID; |
| 295 | |
| 296 | bookmark_app_url_ = specifics.bookmark_app_url(); |
| 297 | bookmark_app_description_ = specifics.bookmark_app_description(); |
Christopher Lam | cec8c4f | 2017-10-16 01:38:43 | [diff] [blame] | 298 | bookmark_app_scope_ = specifics.bookmark_app_scope(); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 299 | bookmark_app_icon_color_ = specifics.bookmark_app_icon_color(); |
Christopher Lam | cec8c4f | 2017-10-16 01:38:43 | [diff] [blame] | 300 | if (specifics.has_bookmark_app_theme_color()) |
| 301 | bookmark_app_theme_color_ = specifics.bookmark_app_theme_color(); |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 302 | |
| 303 | for (int i = 0; i < specifics.linked_app_icons_size(); ++i) { |
| 304 | const sync_pb::LinkedAppIconInfo& linked_app_icon_info = |
| 305 | specifics.linked_app_icons(i); |
| 306 | if (linked_app_icon_info.has_url() && linked_app_icon_info.has_size()) { |
| 307 | LinkedAppIconInfo linked_icon; |
| 308 | linked_icon.url = GURL(linked_app_icon_info.url()); |
| 309 | linked_icon.size = linked_app_icon_info.size(); |
| 310 | linked_icons_.push_back(linked_icon); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return true; |
| 315 | } |
| 316 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 317 | bool ExtensionSyncData::PopulateFromSyncData( |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 318 | const syncer::SyncData& sync_data) { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 319 | const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 320 | |
treib | 0c714f7c | 2015-07-08 10:04:58 | [diff] [blame] | 321 | if (entity_specifics.has_app()) |
| 322 | return PopulateFromAppSpecifics(entity_specifics.app()); |
| 323 | |
yoz | 87044453 | 2015-03-12 18:42:53 | [diff] [blame] | 324 | if (entity_specifics.has_extension()) |
| 325 | return PopulateFromExtensionSpecifics(entity_specifics.extension()); |
| 326 | |
| 327 | LOG(ERROR) << "Attempt to sync bad EntitySpecifics: no extension data."; |
| 328 | RecordBadSyncData(NO_EXTENSION_SPECIFICS); |
| 329 | return false; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 330 | } |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 331 | |
| 332 | } // namespace extensions |