Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_service.h" | 5 #include "chrome/browser/extensions/extension_sync_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 // for older Chrome versions (<M48). | 273 // for older Chrome versions (<M48). |
| 274 bool enabled = (disable_reasons == Extension::DISABLE_NONE); | 274 bool enabled = (disable_reasons == Extension::DISABLE_NONE); |
| 275 enabled = enabled && | 275 enabled = enabled && |
| 276 extension_prefs->GetExtensionBlacklistState(extension.id()) == | 276 extension_prefs->GetExtensionBlacklistState(extension.id()) == |
| 277 extensions::NOT_BLACKLISTED; | 277 extensions::NOT_BLACKLISTED; |
| 278 bool incognito_enabled = extensions::util::IsIncognitoEnabled(id, profile_); | 278 bool incognito_enabled = extensions::util::IsIncognitoEnabled(id, profile_); |
| 279 bool remote_install = | 279 bool remote_install = |
| 280 extension_prefs->HasDisableReason(id, Extension::DISABLE_REMOTE_INSTALL); | 280 extension_prefs->HasDisableReason(id, Extension::DISABLE_REMOTE_INSTALL); |
| 281 ExtensionSyncData::OptionalBoolean allowed_on_all_url = | 281 ExtensionSyncData::OptionalBoolean allowed_on_all_url = |
| 282 GetAllowedOnAllUrlsOptionalBoolean(id, profile_); | 282 GetAllowedOnAllUrlsOptionalBoolean(id, profile_); |
| 283 bool installed_by_custodian = | |
| 284 extensions::util::WasInstalledByCustodian(id, profile_); | |
| 283 AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting(); | 285 AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting(); |
| 284 | 286 |
| 285 ExtensionSyncData result = extension.is_app() | 287 ExtensionSyncData result = extension.is_app() |
| 286 ? ExtensionSyncData( | 288 ? ExtensionSyncData( |
| 287 extension, enabled, disable_reasons, incognito_enabled, | 289 extension, enabled, disable_reasons, incognito_enabled, |
| 288 remote_install, allowed_on_all_url, | 290 remote_install, allowed_on_all_url, |
| 291 installed_by_custodian, | |
| 289 app_sorting->GetAppLaunchOrdinal(id), | 292 app_sorting->GetAppLaunchOrdinal(id), |
| 290 app_sorting->GetPageOrdinal(id), | 293 app_sorting->GetPageOrdinal(id), |
| 291 extensions::GetLaunchTypePrefValue(extension_prefs, id)) | 294 extensions::GetLaunchTypePrefValue(extension_prefs, id)) |
| 292 : ExtensionSyncData( | 295 : ExtensionSyncData( |
| 293 extension, enabled, disable_reasons, incognito_enabled, | 296 extension, enabled, disable_reasons, incognito_enabled, |
| 294 remote_install, allowed_on_all_url); | 297 remote_install, allowed_on_all_url, installed_by_custodian); |
| 295 | 298 |
| 296 // If there's a pending update, send the new version to sync instead of the | 299 // If there's a pending update, send the new version to sync instead of the |
| 297 // installed one. | 300 // installed one. |
| 298 auto it = pending_updates_.find(id); | 301 auto it = pending_updates_.find(id); |
| 299 if (it != pending_updates_.end()) { | 302 if (it != pending_updates_.end()) { |
| 300 const base::Version& version = it->second.version; | 303 const base::Version& version = it->second.version; |
| 301 // If we have a pending version, it should be newer than the installed one. | 304 // If we have a pending version, it should be newer than the installed one. |
| 302 DCHECK_EQ(-1, extension.version()->CompareTo(version)); | 305 DCHECK_EQ(-1, extension.version()->CompareTo(version)); |
| 303 result.set_version(version); | 306 result.set_version(version); |
| 304 // If we'll re-enable the extension once it's updated, also send that back | 307 // If we'll re-enable the extension once it's updated, also send that back |
| 305 // to sync. | 308 // to sync. |
| 306 if (it->second.grant_permissions_and_reenable) | 309 if (it->second.grant_permissions_and_reenable) |
| 307 result.set_enabled(true); | 310 result.set_enabled(true); |
| 308 } | 311 } |
| 309 return result; | 312 return result; |
| 310 } | 313 } |
| 311 | 314 |
| 312 void ExtensionSyncService::ApplySyncData( | 315 void ExtensionSyncService::ApplySyncData( |
| 313 const ExtensionSyncData& extension_sync_data) { | 316 const ExtensionSyncData& extension_sync_data) { |
| 314 // Ignore any pref change notifications etc. while we're applying incoming | 317 // Ignore any pref change notifications etc. while we're applying incoming |
| 315 // sync data, so that we don't end up notifying ourselves. | 318 // sync data, so that we don't end up notifying ourselves. |
| 316 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); | 319 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); |
| 317 | 320 |
| 321 extensions::util::SetWasInstalledByCustodian( | |
|
Devlin
2016/06/20 17:09:24
It might be worth a comment:
// Note: this may cau
mamir
2016/06/21 11:38:22
Done.
| |
| 322 extension_sync_data.id(), profile_, | |
| 323 extension_sync_data.installed_by_custodian()); | |
| 324 | |
| 318 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS | 325 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS |
| 319 : syncer::EXTENSIONS; | 326 : syncer::EXTENSIONS; |
| 320 const std::string& id = extension_sync_data.id(); | 327 const std::string& id = extension_sync_data.id(); |
| 321 SyncBundle* bundle = GetSyncBundle(type); | 328 SyncBundle* bundle = GetSyncBundle(type); |
| 322 DCHECK(bundle->IsSyncing()); | 329 DCHECK(bundle->IsSyncing()); |
| 323 // Note: |extension| may be null if it hasn't been installed yet. | 330 // Note: |extension| may be null if it hasn't been installed yet. |
| 324 const Extension* extension = | 331 const Extension* extension = |
| 325 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); | 332 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); |
| 326 if (extension && !IsCorrectSyncType(*extension, type)) { | 333 if (extension && !IsCorrectSyncType(*extension, type)) { |
| 327 // The installed item isn't the same type as the sync data item, so we need | 334 // The installed item isn't the same type as the sync data item, so we need |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 // If the extension is installed but outdated, store the new version. | 503 // If the extension is installed but outdated, store the new version. |
| 497 pending_updates_[id] = | 504 pending_updates_[id] = |
| 498 PendingUpdate(extension_sync_data.version(), reenable_after_update); | 505 PendingUpdate(extension_sync_data.version(), reenable_after_update); |
| 499 check_for_updates = true; | 506 check_for_updates = true; |
| 500 } else if (state == NOT_INSTALLED) { | 507 } else if (state == NOT_INSTALLED) { |
| 501 if (!extension_service()->pending_extension_manager()->AddFromSync( | 508 if (!extension_service()->pending_extension_manager()->AddFromSync( |
| 502 id, | 509 id, |
| 503 extension_sync_data.update_url(), | 510 extension_sync_data.update_url(), |
| 504 extension_sync_data.version(), | 511 extension_sync_data.version(), |
| 505 ShouldAllowInstall, | 512 ShouldAllowInstall, |
| 506 extension_sync_data.remote_install(), | 513 extension_sync_data.remote_install())) { |
| 507 extension_sync_data.installed_by_custodian())) { | |
| 508 LOG(WARNING) << "Could not add pending extension for " << id; | 514 LOG(WARNING) << "Could not add pending extension for " << id; |
| 509 // This means that the extension is already pending installation, with a | 515 // This means that the extension is already pending installation, with a |
| 510 // non-INTERNAL location. Add to pending_sync_data, even though it will | 516 // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 511 // never be removed (we'll never install a syncable version of the | 517 // never be removed (we'll never install a syncable version of the |
| 512 // extension), so that GetAllSyncData() continues to send it. | 518 // extension), so that GetAllSyncData() continues to send it. |
| 513 } | 519 } |
| 514 // Track pending extensions so that we can return them in GetAllSyncData(). | 520 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 515 bundle->AddPendingExtensionData(extension_sync_data); | 521 bundle->AddPendingExtensionData(extension_sync_data); |
| 516 check_for_updates = true; | 522 check_for_updates = true; |
| 517 } | 523 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 sync_data_list->push_back(CreateSyncData(*extension)); | 709 sync_data_list->push_back(CreateSyncData(*extension)); |
| 704 } | 710 } |
| 705 } | 711 } |
| 706 } | 712 } |
| 707 | 713 |
| 708 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { | 714 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { |
| 709 // Themes are handled by the ThemeSyncableService. | 715 // Themes are handled by the ThemeSyncableService. |
| 710 return extensions::util::ShouldSync(&extension, profile_) && | 716 return extensions::util::ShouldSync(&extension, profile_) && |
| 711 !extension.is_theme(); | 717 !extension.is_theme(); |
| 712 } | 718 } |
| OLD | NEW |