Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/extensions/extension_sync_service.cc

Issue 2054773002: Replace the WAS_INSTALLED_BY_CUSTODIAN creation flag with a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the build Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Note: this may cause an existing version of the extension to be reloaded.
322 extensions::util::SetWasInstalledByCustodian(
323 extension_sync_data.id(), profile_,
324 extension_sync_data.installed_by_custodian());
325
318 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS 326 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS
319 : syncer::EXTENSIONS; 327 : syncer::EXTENSIONS;
320 const std::string& id = extension_sync_data.id(); 328 const std::string& id = extension_sync_data.id();
321 SyncBundle* bundle = GetSyncBundle(type); 329 SyncBundle* bundle = GetSyncBundle(type);
322 DCHECK(bundle->IsSyncing()); 330 DCHECK(bundle->IsSyncing());
323 // Note: |extension| may be null if it hasn't been installed yet. 331 // Note: |extension| may be null if it hasn't been installed yet.
324 const Extension* extension = 332 const Extension* extension =
325 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); 333 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id);
326 if (extension && !IsCorrectSyncType(*extension, type)) { 334 if (extension && !IsCorrectSyncType(*extension, type)) {
327 // The installed item isn't the same type as the sync data item, so we need 335 // 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
496 // If the extension is installed but outdated, store the new version. 504 // If the extension is installed but outdated, store the new version.
497 pending_updates_[id] = 505 pending_updates_[id] =
498 PendingUpdate(extension_sync_data.version(), reenable_after_update); 506 PendingUpdate(extension_sync_data.version(), reenable_after_update);
499 check_for_updates = true; 507 check_for_updates = true;
500 } else if (state == NOT_INSTALLED) { 508 } else if (state == NOT_INSTALLED) {
501 if (!extension_service()->pending_extension_manager()->AddFromSync( 509 if (!extension_service()->pending_extension_manager()->AddFromSync(
502 id, 510 id,
503 extension_sync_data.update_url(), 511 extension_sync_data.update_url(),
504 extension_sync_data.version(), 512 extension_sync_data.version(),
505 ShouldAllowInstall, 513 ShouldAllowInstall,
506 extension_sync_data.remote_install(), 514 extension_sync_data.remote_install())) {
507 extension_sync_data.installed_by_custodian())) {
508 LOG(WARNING) << "Could not add pending extension for " << id; 515 LOG(WARNING) << "Could not add pending extension for " << id;
509 // This means that the extension is already pending installation, with a 516 // This means that the extension is already pending installation, with a
510 // non-INTERNAL location. Add to pending_sync_data, even though it will 517 // 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 518 // never be removed (we'll never install a syncable version of the
512 // extension), so that GetAllSyncData() continues to send it. 519 // extension), so that GetAllSyncData() continues to send it.
513 } 520 }
514 // Track pending extensions so that we can return them in GetAllSyncData(). 521 // Track pending extensions so that we can return them in GetAllSyncData().
515 bundle->AddPendingExtensionData(extension_sync_data); 522 bundle->AddPendingExtensionData(extension_sync_data);
516 check_for_updates = true; 523 check_for_updates = true;
517 } 524 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 sync_data_list->push_back(CreateSyncData(*extension)); 710 sync_data_list->push_back(CreateSyncData(*extension));
704 } 711 }
705 } 712 }
706 } 713 }
707 714
708 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { 715 bool ExtensionSyncService::ShouldSync(const Extension& extension) const {
709 // Themes are handled by the ThemeSyncableService. 716 // Themes are handled by the ThemeSyncableService.
710 return extensions::util::ShouldSync(&extension, profile_) && 717 return extensions::util::ShouldSync(&extension, profile_) &&
711 !extension.is_theme(); 718 !extension.is_theme();
712 } 719 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_sync_data.cc ('k') | chrome/browser/extensions/extension_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698