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

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: Response to code review by Marc 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 16 matching lines...) Expand all
27 #include "extensions/browser/uninstall_reason.h" 27 #include "extensions/browser/uninstall_reason.h"
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 #include "extensions/common/extension_set.h" 29 #include "extensions/common/extension_set.h"
30 #include "extensions/common/image_util.h" 30 #include "extensions/common/image_util.h"
31 #include "extensions/common/permissions/permission_message_provider.h" 31 #include "extensions/common/permissions/permission_message_provider.h"
32 #include "extensions/common/permissions/permissions_data.h" 32 #include "extensions/common/permissions/permissions_data.h"
33 #include "sync/api/sync_change.h" 33 #include "sync/api/sync_change.h"
34 #include "sync/api/sync_error_factory.h" 34 #include "sync/api/sync_error_factory.h"
35 35
36 #if defined(ENABLE_SUPERVISED_USERS) 36 #if defined(ENABLE_SUPERVISED_USERS)
37 #include "chrome/browser/extensions/extension_util.h"
Marc Treib 2016/06/17 08:56:54 This needs to go out of the #ifdef
mamir 2016/06/17 16:12:54 Done.
37 #include "chrome/browser/supervised_user/supervised_user_service.h" 38 #include "chrome/browser/supervised_user/supervised_user_service.h"
38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 39 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
39 #endif 40 #endif
40 41
41 using extensions::AppSorting; 42 using extensions::AppSorting;
42 using extensions::Extension; 43 using extensions::Extension;
43 using extensions::ExtensionPrefs; 44 using extensions::ExtensionPrefs;
44 using extensions::ExtensionRegistry; 45 using extensions::ExtensionRegistry;
45 using extensions::ExtensionSet; 46 using extensions::ExtensionSet;
46 using extensions::ExtensionSyncData; 47 using extensions::ExtensionSyncData;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // for older Chrome versions (<M48). 274 // for older Chrome versions (<M48).
274 bool enabled = (disable_reasons == Extension::DISABLE_NONE); 275 bool enabled = (disable_reasons == Extension::DISABLE_NONE);
275 enabled = enabled && 276 enabled = enabled &&
276 extension_prefs->GetExtensionBlacklistState(extension.id()) == 277 extension_prefs->GetExtensionBlacklistState(extension.id()) ==
277 extensions::NOT_BLACKLISTED; 278 extensions::NOT_BLACKLISTED;
278 bool incognito_enabled = extensions::util::IsIncognitoEnabled(id, profile_); 279 bool incognito_enabled = extensions::util::IsIncognitoEnabled(id, profile_);
279 bool remote_install = 280 bool remote_install =
280 extension_prefs->HasDisableReason(id, Extension::DISABLE_REMOTE_INSTALL); 281 extension_prefs->HasDisableReason(id, Extension::DISABLE_REMOTE_INSTALL);
281 ExtensionSyncData::OptionalBoolean allowed_on_all_url = 282 ExtensionSyncData::OptionalBoolean allowed_on_all_url =
282 GetAllowedOnAllUrlsOptionalBoolean(id, profile_); 283 GetAllowedOnAllUrlsOptionalBoolean(id, profile_);
284 bool installed_by_custodian =
285 extensions::util::WasInstalledByCustodian(id, profile_);
283 AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting(); 286 AppSorting* app_sorting = ExtensionSystem::Get(profile_)->app_sorting();
284 287
285 ExtensionSyncData result = extension.is_app() 288 ExtensionSyncData result = extension.is_app()
286 ? ExtensionSyncData( 289 ? ExtensionSyncData(
287 extension, enabled, disable_reasons, incognito_enabled, 290 extension, enabled, disable_reasons, incognito_enabled,
288 remote_install, allowed_on_all_url, 291 remote_install, allowed_on_all_url,
292 installed_by_custodian,
289 app_sorting->GetAppLaunchOrdinal(id), 293 app_sorting->GetAppLaunchOrdinal(id),
290 app_sorting->GetPageOrdinal(id), 294 app_sorting->GetPageOrdinal(id),
291 extensions::GetLaunchTypePrefValue(extension_prefs, id)) 295 extensions::GetLaunchTypePrefValue(extension_prefs, id))
292 : ExtensionSyncData( 296 : ExtensionSyncData(
293 extension, enabled, disable_reasons, incognito_enabled, 297 extension, enabled, disable_reasons, incognito_enabled,
294 remote_install, allowed_on_all_url); 298 remote_install, allowed_on_all_url, installed_by_custodian);
295 299
296 // If there's a pending update, send the new version to sync instead of the 300 // If there's a pending update, send the new version to sync instead of the
297 // installed one. 301 // installed one.
298 auto it = pending_updates_.find(id); 302 auto it = pending_updates_.find(id);
299 if (it != pending_updates_.end()) { 303 if (it != pending_updates_.end()) {
300 const base::Version& version = it->second.version; 304 const base::Version& version = it->second.version;
301 // If we have a pending version, it should be newer than the installed one. 305 // If we have a pending version, it should be newer than the installed one.
302 DCHECK_EQ(-1, extension.version()->CompareTo(version)); 306 DCHECK_EQ(-1, extension.version()->CompareTo(version));
303 result.set_version(version); 307 result.set_version(version);
304 // If we'll re-enable the extension once it's updated, also send that back 308 // If we'll re-enable the extension once it's updated, also send that back
305 // to sync. 309 // to sync.
306 if (it->second.grant_permissions_and_reenable) 310 if (it->second.grant_permissions_and_reenable)
307 result.set_enabled(true); 311 result.set_enabled(true);
308 } 312 }
309 return result; 313 return result;
310 } 314 }
311 315
312 void ExtensionSyncService::ApplySyncData( 316 void ExtensionSyncService::ApplySyncData(
313 const ExtensionSyncData& extension_sync_data) { 317 const ExtensionSyncData& extension_sync_data) {
314 // Ignore any pref change notifications etc. while we're applying incoming 318 // Ignore any pref change notifications etc. while we're applying incoming
315 // sync data, so that we don't end up notifying ourselves. 319 // sync data, so that we don't end up notifying ourselves.
316 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); 320 base::AutoReset<bool> ignore_updates(&ignore_updates_, true);
317 321
322 if (extension_sync_data.installed_by_custodian()) {
Marc Treib 2016/06/17 08:56:54 Hm. Now that I see this, I kinda think we should t
mamir 2016/06/17 16:12:55 I agree. No thing should break because this flag i
323 extensions::util::SetWasInstalledByCustodian(extension_sync_data.id(),
324 profile_);
325 }
326
318 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS 327 syncer::ModelType type = extension_sync_data.is_app() ? syncer::APPS
319 : syncer::EXTENSIONS; 328 : syncer::EXTENSIONS;
320 const std::string& id = extension_sync_data.id(); 329 const std::string& id = extension_sync_data.id();
321 SyncBundle* bundle = GetSyncBundle(type); 330 SyncBundle* bundle = GetSyncBundle(type);
322 DCHECK(bundle->IsSyncing()); 331 DCHECK(bundle->IsSyncing());
323 // Note: |extension| may be null if it hasn't been installed yet. 332 // Note: |extension| may be null if it hasn't been installed yet.
324 const Extension* extension = 333 const Extension* extension =
325 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id); 334 ExtensionRegistry::Get(profile_)->GetInstalledExtension(id);
326 if (extension && !IsCorrectSyncType(*extension, type)) { 335 if (extension && !IsCorrectSyncType(*extension, type)) {
327 // The installed item isn't the same type as the sync data item, so we need 336 // 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. 505 // If the extension is installed but outdated, store the new version.
497 pending_updates_[id] = 506 pending_updates_[id] =
498 PendingUpdate(extension_sync_data.version(), reenable_after_update); 507 PendingUpdate(extension_sync_data.version(), reenable_after_update);
499 check_for_updates = true; 508 check_for_updates = true;
500 } else if (state == NOT_INSTALLED) { 509 } else if (state == NOT_INSTALLED) {
501 if (!extension_service()->pending_extension_manager()->AddFromSync( 510 if (!extension_service()->pending_extension_manager()->AddFromSync(
502 id, 511 id,
503 extension_sync_data.update_url(), 512 extension_sync_data.update_url(),
504 extension_sync_data.version(), 513 extension_sync_data.version(),
505 ShouldAllowInstall, 514 ShouldAllowInstall,
506 extension_sync_data.remote_install(), 515 extension_sync_data.remote_install())) {
507 extension_sync_data.installed_by_custodian())) {
508 LOG(WARNING) << "Could not add pending extension for " << id; 516 LOG(WARNING) << "Could not add pending extension for " << id;
509 // This means that the extension is already pending installation, with a 517 // This means that the extension is already pending installation, with a
510 // non-INTERNAL location. Add to pending_sync_data, even though it will 518 // 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 519 // never be removed (we'll never install a syncable version of the
512 // extension), so that GetAllSyncData() continues to send it. 520 // extension), so that GetAllSyncData() continues to send it.
513 } 521 }
514 // Track pending extensions so that we can return them in GetAllSyncData(). 522 // Track pending extensions so that we can return them in GetAllSyncData().
515 bundle->AddPendingExtensionData(extension_sync_data); 523 bundle->AddPendingExtensionData(extension_sync_data);
516 check_for_updates = true; 524 check_for_updates = true;
517 } 525 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 sync_data_list->push_back(CreateSyncData(*extension)); 711 sync_data_list->push_back(CreateSyncData(*extension));
704 } 712 }
705 } 713 }
706 } 714 }
707 715
708 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { 716 bool ExtensionSyncService::ShouldSync(const Extension& extension) const {
709 // Themes are handled by the ThemeSyncableService. 717 // Themes are handled by the ThemeSyncableService.
710 return extensions::util::ShouldSync(&extension, profile_) && 718 return extensions::util::ShouldSync(&extension, profile_) &&
711 !extension.is_theme(); 719 !extension.is_theme();
712 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698