| 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 <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions(); | 247 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions(); |
| 248 | 248 |
| 249 return syncer::SyncError(); | 249 return syncer::SyncError(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 extensions::ExtensionSyncData ExtensionSyncService::GetExtensionSyncData( | 252 extensions::ExtensionSyncData ExtensionSyncService::GetExtensionSyncData( |
| 253 const Extension& extension) const { | 253 const Extension& extension) const { |
| 254 return extensions::ExtensionSyncData( | 254 return extensions::ExtensionSyncData( |
| 255 extension, | 255 extension, |
| 256 extension_service_->IsExtensionEnabled(extension.id()), | 256 extension_service_->IsExtensionEnabled(extension.id()), |
| 257 extensions::util::IsIncognitoEnabled(extension.id(), profile_)); | 257 extensions::util::IsIncognitoEnabled(extension.id(), profile_), |
| 258 extension_prefs_->GetDisableReasons(extension.id()) & |
| 259 Extension::DISABLE_REMOTE_INSTALL); |
| 258 } | 260 } |
| 259 | 261 |
| 260 extensions::AppSyncData ExtensionSyncService::GetAppSyncData( | 262 extensions::AppSyncData ExtensionSyncService::GetAppSyncData( |
| 261 const Extension& extension) const { | 263 const Extension& extension) const { |
| 262 return extensions::AppSyncData( | 264 return extensions::AppSyncData( |
| 263 extension, | 265 extension, |
| 264 extension_service_->IsExtensionEnabled(extension.id()), | 266 extension_service_->IsExtensionEnabled(extension.id()), |
| 265 extensions::util::IsIncognitoEnabled(extension.id(), profile_), | 267 extensions::util::IsIncognitoEnabled(extension.id(), profile_), |
| 268 extension_prefs_->GetDisableReasons(extension.id()) & |
| 269 Extension::DISABLE_REMOTE_INSTALL, |
| 266 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()), | 270 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()), |
| 267 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()), | 271 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()), |
| 268 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id())); | 272 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id())); |
| 269 } | 273 } |
| 270 | 274 |
| 271 std::vector<extensions::ExtensionSyncData> | 275 std::vector<extensions::ExtensionSyncData> |
| 272 ExtensionSyncService::GetExtensionSyncDataList() const { | 276 ExtensionSyncService::GetExtensionSyncDataList() const { |
| 273 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 277 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 274 std::vector<extensions::ExtensionSyncData> extension_sync_list; | 278 std::vector<extensions::ExtensionSyncData> extension_sync_list; |
| 275 extension_sync_bundle_.GetExtensionSyncDataListHelper( | 279 extension_sync_bundle_.GetExtensionSyncDataListHelper( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return true; | 464 return true; |
| 461 } | 465 } |
| 462 | 466 |
| 463 // Set user settings. | 467 // Set user settings. |
| 464 // If the extension has been disabled from sync, it may not have | 468 // If the extension has been disabled from sync, it may not have |
| 465 // been installed yet, so we don't know if the disable reason was a | 469 // been installed yet, so we don't know if the disable reason was a |
| 466 // permissions increase. That will be updated once CheckPermissionsIncrease | 470 // permissions increase. That will be updated once CheckPermissionsIncrease |
| 467 // is called for it. | 471 // is called for it. |
| 468 if (extension_sync_data.enabled()) | 472 if (extension_sync_data.enabled()) |
| 469 extension_service_->EnableExtension(id); | 473 extension_service_->EnableExtension(id); |
| 470 else if (!IsPendingEnable(id)) | 474 else if (!IsPendingEnable(id)) { |
| 471 extension_service_->DisableExtension( | 475 Extension::DisableReason reason = Extension::DISABLE_UNKNOWN_FROM_SYNC; |
| 472 id, Extension::DISABLE_UNKNOWN_FROM_SYNC); | 476 if (extension_sync_data.remote_install()) |
| 477 reason = Extension::DISABLE_REMOTE_INSTALL; |
| 478 extension_service_->DisableExtension(id, reason); |
| 479 } |
| 473 | 480 |
| 474 // We need to cache some version information here because setting the | 481 // We need to cache some version information here because setting the |
| 475 // incognito flag invalidates the |extension| pointer (it reloads the | 482 // incognito flag invalidates the |extension| pointer (it reloads the |
| 476 // extension). | 483 // extension). |
| 477 bool extension_installed = (extension != NULL); | 484 bool extension_installed = (extension != NULL); |
| 478 int result = extension ? | 485 int result = extension ? |
| 479 extension->version()->CompareTo(extension_sync_data.version()) : 0; | 486 extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 480 extensions::util::SetIsIncognitoEnabled( | 487 extensions::util::SetIsIncognitoEnabled( |
| 481 id, profile_, extension_sync_data.incognito_enabled()); | 488 id, profile_, extension_sync_data.incognito_enabled()); |
| 482 extension = NULL; // No longer safe to use. | 489 extension = NULL; // No longer safe to use. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 494 | 501 |
| 495 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); | 502 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); |
| 496 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = | 503 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = |
| 497 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : | 504 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : |
| 498 extensions::sync_helper::IsSyncableExtension; | 505 extensions::sync_helper::IsSyncableExtension; |
| 499 | 506 |
| 500 if (!extension_service_->pending_extension_manager()->AddFromSync( | 507 if (!extension_service_->pending_extension_manager()->AddFromSync( |
| 501 id, | 508 id, |
| 502 extension_sync_data.update_url(), | 509 extension_sync_data.update_url(), |
| 503 filter, | 510 filter, |
| 504 kInstallSilently)) { | 511 kInstallSilently, |
| 512 extension_sync_data.remote_install())) { |
| 505 LOG(WARNING) << "Could not add pending extension for " << id; | 513 LOG(WARNING) << "Could not add pending extension for " << id; |
| 506 // This means that the extension is already pending installation, with a | 514 // This means that the extension is already pending installation, with a |
| 507 // non-INTERNAL location. Add to pending_sync_data, even though it will | 515 // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 508 // never be removed (we'll never install a syncable version of the | 516 // never be removed (we'll never install a syncable version of the |
| 509 // extension), so that GetAllSyncData() continues to send it. | 517 // extension), so that GetAllSyncData() continues to send it. |
| 510 } | 518 } |
| 511 // Track pending extensions so that we can return them in GetAllSyncData(). | 519 // Track pending extensions so that we can return them in GetAllSyncData(). |
| 512 return false; | 520 return false; |
| 513 } | 521 } |
| 514 | 522 |
| 515 return true; | 523 return true; |
| 516 } | 524 } |
| 517 | 525 |
| 518 void ExtensionSyncService::SyncExtensionChangeIfNeeded( | 526 void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
| 519 const Extension& extension) { | 527 const Extension& extension) { |
| 520 if (extensions::sync_helper::IsSyncableApp(&extension)) { | 528 if (extensions::sync_helper::IsSyncableApp(&extension)) { |
| 521 if (app_sync_bundle_.IsSyncing()) | 529 if (app_sync_bundle_.IsSyncing()) |
| 522 app_sync_bundle_.SyncChangeIfNeeded(extension); | 530 app_sync_bundle_.SyncChangeIfNeeded(extension); |
| 523 else if (extension_service_->is_ready() && !flare_.is_null()) | 531 else if (extension_service_->is_ready() && !flare_.is_null()) |
| 524 flare_.Run(syncer::APPS); | 532 flare_.Run(syncer::APPS); |
| 525 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { | 533 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
| 526 if (extension_sync_bundle_.IsSyncing()) | 534 if (extension_sync_bundle_.IsSyncing()) |
| 527 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 535 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
| 528 else if (extension_service_->is_ready() && !flare_.is_null()) | 536 else if (extension_service_->is_ready() && !flare_.is_null()) |
| 529 flare_.Run(syncer::EXTENSIONS); | 537 flare_.Run(syncer::EXTENSIONS); |
| 530 } | 538 } |
| 531 } | 539 } |
| OLD | NEW |