| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 void ExtensionService::CheckForUpdatesSoon() { | 1158 void ExtensionService::CheckForUpdatesSoon() { |
| 1159 if (updater()) { | 1159 if (updater()) { |
| 1160 updater()->CheckSoon(); | 1160 updater()->CheckSoon(); |
| 1161 } else { | 1161 } else { |
| 1162 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; | 1162 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 namespace { | 1166 namespace { |
| 1167 bool IsSyncableNone(const Extension& extension) { return false; } | 1167 bool IsSyncableNone(const Extension& extension) { return false; } |
| 1168 } // namespace | 1168 } // namespace |
| 1169 | 1169 |
| 1170 ExtensionService::SyncBundle::SyncBundle() | 1170 ExtensionService::SyncBundle::SyncBundle() |
| 1171 : filter(IsSyncableNone), | 1171 : filter(IsSyncableNone), |
| 1172 sync_processor(NULL) { | 1172 sync_processor(NULL) { |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 ExtensionService::SyncBundle::~SyncBundle() { | 1175 ExtensionService::SyncBundle::~SyncBundle() { |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { | 1178 bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 } | 1400 } |
| 1401 return; | 1401 return; |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 // Set user settings. | 1404 // Set user settings. |
| 1405 if (extension_sync_data.enabled()) { | 1405 if (extension_sync_data.enabled()) { |
| 1406 EnableExtension(id); | 1406 EnableExtension(id); |
| 1407 } else { | 1407 } else { |
| 1408 DisableExtension(id); | 1408 DisableExtension(id); |
| 1409 } | 1409 } |
| 1410 |
| 1411 // We need to cache some version information here because setting the |
| 1412 // incognito flag invalidates the |extension| pointer (it reloads the |
| 1413 // extension). |
| 1414 bool extension_installed = extension != NULL; |
| 1415 int result = extension ? |
| 1416 extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 1410 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); | 1417 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
| 1418 extension = NULL; // No longer safe to use. |
| 1411 | 1419 |
| 1412 if (extension) { | 1420 if (extension_installed) { |
| 1413 // If the extension is already installed, check if it's outdated. | 1421 // If the extension is already installed, check if it's outdated. |
| 1414 int result = extension->version()->CompareTo(extension_sync_data.version()); | |
| 1415 if (result < 0) { | 1422 if (result < 0) { |
| 1416 // Extension is outdated. | 1423 // Extension is outdated. |
| 1417 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; | 1424 bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
| 1418 CheckForUpdatesSoon(); | 1425 CheckForUpdatesSoon(); |
| 1419 } | 1426 } |
| 1420 } else { | 1427 } else { |
| 1421 // TODO(akalin): Replace silent update with a list of enabled | 1428 // TODO(akalin): Replace silent update with a list of enabled |
| 1422 // permissions. | 1429 // permissions. |
| 1423 const bool kInstallSilently = true; | 1430 const bool kInstallSilently = true; |
| 1424 if (!pending_extension_manager()->AddFromSync( | 1431 if (!pending_extension_manager()->AddFromSync( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 | 1468 |
| 1462 // Broadcast unloaded and loaded events to update browser state. Only bother | 1469 // Broadcast unloaded and loaded events to update browser state. Only bother |
| 1463 // if the value changed and the extension is actually enabled, since there is | 1470 // if the value changed and the extension is actually enabled, since there is |
| 1464 // no UI otherwise. | 1471 // no UI otherwise. |
| 1465 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); | 1472 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
| 1466 if (enabled == old_enabled) | 1473 if (enabled == old_enabled) |
| 1467 return; | 1474 return; |
| 1468 | 1475 |
| 1469 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); | 1476 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
| 1470 | 1477 |
| 1471 // If the extension is enabled (and not terminated), unload and | 1478 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
| 1472 // reload it to update UI. | 1479 extension) != extensions_.end(); |
| 1473 const Extension* enabled_extension = GetExtensionById(extension_id, false); | 1480 if (extension_is_enabled) |
| 1474 if (enabled_extension) { | 1481 ReloadExtension(extension->id()); |
| 1475 NotifyExtensionUnloaded( | |
| 1476 enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); | |
| 1477 NotifyExtensionLoaded(enabled_extension); | |
| 1478 } | |
| 1479 | 1482 |
| 1483 // Reloading the extension invalidates the |extension| pointer. |
| 1484 extension = GetInstalledExtension(extension_id); |
| 1480 if (extension) | 1485 if (extension) |
| 1481 SyncExtensionChangeIfNeeded(*extension); | 1486 SyncExtensionChangeIfNeeded(*extension); |
| 1482 } | 1487 } |
| 1483 | 1488 |
| 1484 void ExtensionService::SetAppNotificationSetupDone( | 1489 void ExtensionService::SetAppNotificationSetupDone( |
| 1485 const std::string& extension_id, | 1490 const std::string& extension_id, |
| 1486 bool value) { | 1491 bool value) { |
| 1487 const Extension* extension = GetInstalledExtension(extension_id); | 1492 const Extension* extension = GetInstalledExtension(extension_id); |
| 1488 // This method is called when the user sets up app notifications. | 1493 // This method is called when the user sets up app notifications. |
| 1489 // So it is not expected to be called until the extension is installed. | 1494 // So it is not expected to be called until the extension is installed. |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2480 | 2485 |
| 2481 ExtensionService::NaClModuleInfoList::iterator | 2486 ExtensionService::NaClModuleInfoList::iterator |
| 2482 ExtensionService::FindNaClModule(const GURL& url) { | 2487 ExtensionService::FindNaClModule(const GURL& url) { |
| 2483 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2488 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2484 iter != nacl_module_list_.end(); ++iter) { | 2489 iter != nacl_module_list_.end(); ++iter) { |
| 2485 if (iter->url == url) | 2490 if (iter->url == url) |
| 2486 return iter; | 2491 return iter; |
| 2487 } | 2492 } |
| 2488 return nacl_module_list_.end(); | 2493 return nacl_module_list_.end(); |
| 2489 } | 2494 } |
| OLD | NEW |