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_->HasDisableReason(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_->HasDisableReason(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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 LOG(WARNING) << "Extension with id " << id | 462 LOG(WARNING) << "Extension with id " << id |
459 << " from sync was uninstalled as external extension"; | 463 << " from sync was uninstalled as external extension"; |
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. |
| 472 // However if the extension is marked as a remote install in sync, we know |
| 473 // what the disable reason is, so set it to that directly. Note that when |
| 474 // CheckPermissionsIncrease runs, it might still add permissions increase |
| 475 // as a disable reason for the extension. |
468 if (extension_sync_data.enabled()) | 476 if (extension_sync_data.enabled()) |
469 extension_service_->EnableExtension(id); | 477 extension_service_->EnableExtension(id); |
470 else if (!IsPendingEnable(id)) | 478 else if (!IsPendingEnable(id)) { |
471 extension_service_->DisableExtension( | 479 if (extension_sync_data.remote_install()) { |
472 id, Extension::DISABLE_UNKNOWN_FROM_SYNC); | 480 extension_service_->DisableExtension(id, |
| 481 Extension::DISABLE_REMOTE_INSTALL); |
| 482 } else { |
| 483 extension_service_->DisableExtension( |
| 484 id, Extension::DISABLE_UNKNOWN_FROM_SYNC); |
| 485 } |
| 486 } |
473 | 487 |
474 // We need to cache some version information here because setting the | 488 // We need to cache some version information here because setting the |
475 // incognito flag invalidates the |extension| pointer (it reloads the | 489 // incognito flag invalidates the |extension| pointer (it reloads the |
476 // extension). | 490 // extension). |
477 bool extension_installed = (extension != NULL); | 491 bool extension_installed = (extension != NULL); |
478 int result = extension ? | 492 int result = extension ? |
479 extension->version()->CompareTo(extension_sync_data.version()) : 0; | 493 extension->version()->CompareTo(extension_sync_data.version()) : 0; |
480 extensions::util::SetIsIncognitoEnabled( | 494 extensions::util::SetIsIncognitoEnabled( |
481 id, profile_, extension_sync_data.incognito_enabled()); | 495 id, profile_, extension_sync_data.incognito_enabled()); |
482 extension = NULL; // No longer safe to use. | 496 extension = NULL; // No longer safe to use. |
(...skipping 11 matching lines...) Expand all Loading... |
494 | 508 |
495 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); | 509 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); |
496 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = | 510 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = |
497 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : | 511 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : |
498 extensions::sync_helper::IsSyncableExtension; | 512 extensions::sync_helper::IsSyncableExtension; |
499 | 513 |
500 if (!extension_service_->pending_extension_manager()->AddFromSync( | 514 if (!extension_service_->pending_extension_manager()->AddFromSync( |
501 id, | 515 id, |
502 extension_sync_data.update_url(), | 516 extension_sync_data.update_url(), |
503 filter, | 517 filter, |
504 kInstallSilently)) { | 518 kInstallSilently, |
| 519 extension_sync_data.remote_install())) { |
505 LOG(WARNING) << "Could not add pending extension for " << id; | 520 LOG(WARNING) << "Could not add pending extension for " << id; |
506 // This means that the extension is already pending installation, with a | 521 // This means that the extension is already pending installation, with a |
507 // non-INTERNAL location. Add to pending_sync_data, even though it will | 522 // 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 | 523 // never be removed (we'll never install a syncable version of the |
509 // extension), so that GetAllSyncData() continues to send it. | 524 // extension), so that GetAllSyncData() continues to send it. |
510 } | 525 } |
511 // Track pending extensions so that we can return them in GetAllSyncData(). | 526 // Track pending extensions so that we can return them in GetAllSyncData(). |
512 return false; | 527 return false; |
513 } | 528 } |
514 | 529 |
515 return true; | 530 return true; |
516 } | 531 } |
517 | 532 |
518 void ExtensionSyncService::SyncExtensionChangeIfNeeded( | 533 void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
519 const Extension& extension) { | 534 const Extension& extension) { |
520 if (extensions::sync_helper::IsSyncableApp(&extension)) { | 535 if (extensions::sync_helper::IsSyncableApp(&extension)) { |
521 if (app_sync_bundle_.IsSyncing()) | 536 if (app_sync_bundle_.IsSyncing()) |
522 app_sync_bundle_.SyncChangeIfNeeded(extension); | 537 app_sync_bundle_.SyncChangeIfNeeded(extension); |
523 else if (extension_service_->is_ready() && !flare_.is_null()) | 538 else if (extension_service_->is_ready() && !flare_.is_null()) |
524 flare_.Run(syncer::APPS); | 539 flare_.Run(syncer::APPS); |
525 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { | 540 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
526 if (extension_sync_bundle_.IsSyncing()) | 541 if (extension_sync_bundle_.IsSyncing()) |
527 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 542 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
528 else if (extension_service_->is_ready() && !flare_.is_null()) | 543 else if (extension_service_->is_ready() && !flare_.is_null()) |
529 flare_.Run(syncer::EXTENSIONS); | 544 flare_.Run(syncer::EXTENSIONS); |
530 } | 545 } |
531 } | 546 } |
OLD | NEW |