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 16 matching lines...) Expand all Loading... | |
| 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" | |
| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 << "Got " << type << " ModelType"; | 193 << "Got " << type << " ModelType"; |
| 193 | 194 |
| 194 SyncBundle* bundle = GetSyncBundle(type); | 195 SyncBundle* bundle = GetSyncBundle(type); |
| 195 bundle->StartSyncing(std::move(sync_processor)); | 196 bundle->StartSyncing(std::move(sync_processor)); |
| 196 | 197 |
| 197 // Apply the initial sync data, filtering out any items where we have more | 198 // Apply the initial sync data, filtering out any items where we have more |
| 198 // recent local changes. Also tell the SyncBundle the extension IDs. | 199 // recent local changes. Also tell the SyncBundle the extension IDs. |
| 199 for (const syncer::SyncData& sync_data : initial_sync_data) { | 200 for (const syncer::SyncData& sync_data : initial_sync_data) { |
| 200 std::unique_ptr<ExtensionSyncData> extension_sync_data( | 201 std::unique_ptr<ExtensionSyncData> extension_sync_data( |
| 201 ExtensionSyncData::CreateFromSyncData(sync_data)); | 202 ExtensionSyncData::CreateFromSyncData(sync_data)); |
| 203 | |
|
Marc Treib
2016/06/13 09:37:14
Please avoid unnecessary changes like this.
mamir
2016/06/13 11:30:16
Sorry.
Overlooked it after removing a LOG statemen
| |
| 202 // If the extension has local state that needs to be synced, ignore this | 204 // If the extension has local state that needs to be synced, ignore this |
| 203 // change (we assume the local state is more recent). | 205 // change (we assume the local state is more recent). |
| 204 if (extension_sync_data && | 206 if (extension_sync_data && |
| 205 !ExtensionPrefs::Get(profile_)->NeedsSync(extension_sync_data->id())) { | 207 !ExtensionPrefs::Get(profile_)->NeedsSync(extension_sync_data->id())) { |
| 206 ApplySyncData(*extension_sync_data); | 208 ApplySyncData(*extension_sync_data); |
| 207 } | 209 } |
| 208 } | 210 } |
| 209 | 211 |
| 210 // Now push the local state to sync. | 212 // Now push the local state to sync. |
| 211 // Note: We'd like to only send out changes for extensions which have | 213 // Note: We'd like to only send out changes for extensions which have |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 } | 310 } |
| 309 return result; | 311 return result; |
| 310 } | 312 } |
| 311 | 313 |
| 312 void ExtensionSyncService::ApplySyncData( | 314 void ExtensionSyncService::ApplySyncData( |
| 313 const ExtensionSyncData& extension_sync_data) { | 315 const ExtensionSyncData& extension_sync_data) { |
| 314 // Ignore any pref change notifications etc. while we're applying incoming | 316 // Ignore any pref change notifications etc. while we're applying incoming |
| 315 // sync data, so that we don't end up notifying ourselves. | 317 // sync data, so that we don't end up notifying ourselves. |
| 316 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); | 318 base::AutoReset<bool> ignore_updates(&ignore_updates_, true); |
| 317 | 319 |
| 320 #if defined(ENABLE_SUPERVISED_USERS) | |
|
Marc Treib
2016/06/13 09:37:14
I don't think this needs an #ifdef. All the other
mamir
2016/06/13 11:30:16
Done.
| |
| 321 if (extension_sync_data.installed_by_custodian()) { | |
| 322 extensions::util::SetIsInstalledByCustodian(extension_sync_data.id(), | |
| 323 profile_, true); | |
| 324 } | |
| 325 #endif | |
| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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())) { | 516 extension_sync_data.installed_by_custodian())) { |
|
Marc Treib
2016/06/13 09:37:14
Is it still necessary to pass the installed_by_cus
mamir
2016/06/13 11:30:16
It not necessary anymore, you are right.
Done!
| |
| 508 LOG(WARNING) << "Could not add pending extension for " << id; | 517 LOG(WARNING) << "Could not add pending extension for " << id; |
| 509 // This means that the extension is already pending installation, with a | 518 // This means that the extension is already pending installation, with a |
| 510 // non-INTERNAL location. Add to pending_sync_data, even though it will | 519 // 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 | 520 // never be removed (we'll never install a syncable version of the |
| 512 // extension), so that GetAllSyncData() continues to send it. | 521 // extension), so that GetAllSyncData() continues to send it. |
| 513 } | 522 } |
| 514 // Track pending extensions so that we can return them in GetAllSyncData(). | 523 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 515 bundle->AddPendingExtensionData(extension_sync_data); | 524 bundle->AddPendingExtensionData(extension_sync_data); |
| 516 check_for_updates = true; | 525 check_for_updates = true; |
| 517 } | 526 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 sync_data_list->push_back(CreateSyncData(*extension)); | 712 sync_data_list->push_back(CreateSyncData(*extension)); |
| 704 } | 713 } |
| 705 } | 714 } |
| 706 } | 715 } |
| 707 | 716 |
| 708 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { | 717 bool ExtensionSyncService::ShouldSync(const Extension& extension) const { |
| 709 // Themes are handled by the ThemeSyncableService. | 718 // Themes are handled by the ThemeSyncableService. |
| 710 return extensions::util::ShouldSync(&extension, profile_) && | 719 return extensions::util::ShouldSync(&extension, profile_) && |
| 711 !extension.is_theme(); | 720 !extension.is_theme(); |
| 712 } | 721 } |
| OLD | NEW |