| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 197 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 198 extensions_enabled_ = false; | 198 extensions_enabled_ = false; |
| 199 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { | 199 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 200 extensions_enabled_ = false; | 200 extensions_enabled_ = false; |
| 201 } | 201 } |
| 202 | 202 |
| 203 registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 203 registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
| 204 NotificationService::AllSources()); | 204 NotificationService::AllSources()); |
| 205 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 205 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
| 206 Source<Profile>(profile_)); | 206 Source<Profile>(profile_)); |
| 207 prefs->AddPrefObserver(prefs::kExtensionInstallAllowList, this); |
| 208 prefs->AddPrefObserver(prefs::kExtensionInstallDenyList, this); |
| 207 | 209 |
| 208 // Set up the ExtensionUpdater | 210 // Set up the ExtensionUpdater |
| 209 if (autoupdate_enabled) { | 211 if (autoupdate_enabled) { |
| 210 int update_frequency = kDefaultUpdateFrequencySeconds; | 212 int update_frequency = kDefaultUpdateFrequencySeconds; |
| 211 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { | 213 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
| 212 base::StringToInt(command_line->GetSwitchValueASCII( | 214 base::StringToInt(command_line->GetSwitchValueASCII( |
| 213 switches::kExtensionsUpdateFrequency), | 215 switches::kExtensionsUpdateFrequency), |
| 214 &update_frequency); | 216 &update_frequency); |
| 215 } | 217 } |
| 216 updater_ = new ExtensionUpdater(this, prefs, update_frequency); | 218 updater_ = new ExtensionUpdater(this, prefs, update_frequency); |
| 217 } | 219 } |
| 218 | 220 |
| 219 backend_ = new ExtensionsServiceBackend(install_directory_); | 221 backend_ = new ExtensionsServiceBackend(install_directory_); |
| 220 | 222 |
| 221 // Use monochrome icons for omnibox icons. | 223 // Use monochrome icons for Omnibox icons. |
| 222 omnibox_icon_manager_.set_monochrome(true); | 224 omnibox_icon_manager_.set_monochrome(true); |
| 223 } | 225 } |
| 224 | 226 |
| 225 ExtensionsService::~ExtensionsService() { | 227 ExtensionsService::~ExtensionsService() { |
| 226 UnloadAllExtensions(); | 228 UnloadAllExtensions(); |
| 227 if (updater_.get()) { | 229 if (updater_.get()) { |
| 228 updater_->Stop(); | 230 updater_->Stop(); |
| 229 } | 231 } |
| 230 } | 232 } |
| 231 | 233 |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 789 } |
| 788 } | 790 } |
| 789 | 791 |
| 790 // UnloadExtension will change the extensions_ list. So, we should | 792 // UnloadExtension will change the extensions_ list. So, we should |
| 791 // call it outside the iterator loop. | 793 // call it outside the iterator loop. |
| 792 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { | 794 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
| 793 UnloadExtension(to_be_removed[i]); | 795 UnloadExtension(to_be_removed[i]); |
| 794 } | 796 } |
| 795 } | 797 } |
| 796 | 798 |
| 799 void ExtensionsService::DestroyingProfile() { |
| 800 profile_->GetPrefs()->RemovePrefObserver( |
| 801 prefs::kExtensionInstallAllowList, this); |
| 802 profile_->GetPrefs()->RemovePrefObserver( |
| 803 prefs::kExtensionInstallDenyList, this); |
| 804 |
| 805 profile_ = NULL; |
| 806 } |
| 807 |
| 808 void ExtensionsService::CheckAdminBlacklist() { |
| 809 std::vector<std::string> to_be_removed; |
| 810 // Loop through extensions list, unload installed extensions. |
| 811 for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 812 iter != extensions_.end(); ++iter) { |
| 813 Extension* extension = (*iter); |
| 814 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) |
| 815 to_be_removed.push_back(extension->id()); |
| 816 } |
| 817 |
| 818 // UnloadExtension will change the extensions_ list. So, we should |
| 819 // call it outside the iterator loop. |
| 820 for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
| 821 UnloadExtension(to_be_removed[i]); |
| 822 } |
| 823 |
| 797 bool ExtensionsService::IsIncognitoEnabled(const Extension* extension) { | 824 bool ExtensionsService::IsIncognitoEnabled(const Extension* extension) { |
| 798 // If this is a component extension we always allow it to work in incognito | 825 // If this is a component extension we always allow it to work in incognito |
| 799 // mode. | 826 // mode. |
| 800 if (extension->location() == Extension::COMPONENT) | 827 if (extension->location() == Extension::COMPONENT) |
| 801 return true; | 828 return true; |
| 802 | 829 |
| 803 // Check the prefs. | 830 // Check the prefs. |
| 804 return extension_prefs_->IsIncognitoEnabled(extension->id()); | 831 return extension_prefs_->IsIncognitoEnabled(extension->id()); |
| 805 } | 832 } |
| 806 | 833 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 } | 1357 } |
| 1331 if (iter == ExtensionHost::recently_deleted()->end()) | 1358 if (iter == ExtensionHost::recently_deleted()->end()) |
| 1332 CHECK(host->GetURL().spec().size() + 1 != 0); | 1359 CHECK(host->GetURL().spec().size() + 1 != 0); |
| 1333 | 1360 |
| 1334 // Unload the entire extension. We want it to be in a consistent state: | 1361 // Unload the entire extension. We want it to be in a consistent state: |
| 1335 // either fully working or not loaded at all, but never half-crashed. | 1362 // either fully working or not loaded at all, but never half-crashed. |
| 1336 UnloadExtension(host->extension()->id()); | 1363 UnloadExtension(host->extension()->id()); |
| 1337 break; | 1364 break; |
| 1338 } | 1365 } |
| 1339 | 1366 |
| 1367 case NotificationType::PREF_CHANGED: { |
| 1368 std::string* pref_name = Details<std::string>(details).ptr(); |
| 1369 DCHECK(*pref_name == prefs::kExtensionInstallAllowList || |
| 1370 *pref_name == prefs::kExtensionInstallDenyList); |
| 1371 CheckAdminBlacklist(); |
| 1372 break; |
| 1373 } |
| 1374 |
| 1340 default: | 1375 default: |
| 1341 NOTREACHED() << "Unexpected notification type."; | 1376 NOTREACHED() << "Unexpected notification type."; |
| 1342 } | 1377 } |
| 1343 } | 1378 } |
| 1344 | 1379 |
| 1345 bool ExtensionsService::HasApps() { | 1380 bool ExtensionsService::HasApps() { |
| 1346 if (!extensions_enabled_) | 1381 if (!extensions_enabled_) |
| 1347 return false; | 1382 return false; |
| 1348 | 1383 |
| 1349 for (ExtensionList::const_iterator it = extensions_.begin(); | 1384 for (ExtensionList::const_iterator it = extensions_.begin(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 // Finish installing on UI thread. | 1590 // Finish installing on UI thread. |
| 1556 ChromeThread::PostTask( | 1591 ChromeThread::PostTask( |
| 1557 ChromeThread::UI, FROM_HERE, | 1592 ChromeThread::UI, FROM_HERE, |
| 1558 NewRunnableMethod( | 1593 NewRunnableMethod( |
| 1559 frontend_, | 1594 frontend_, |
| 1560 &ExtensionsService::ContinueLoadAllExtensions, | 1595 &ExtensionsService::ContinueLoadAllExtensions, |
| 1561 extensions_to_reload, | 1596 extensions_to_reload, |
| 1562 start_time, | 1597 start_time, |
| 1563 true)); | 1598 true)); |
| 1564 } | 1599 } |
| OLD | NEW |