| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 521 } |
| 522 | 522 |
| 523 bool ExtensionsService::IsDownloadFromMiniGallery(const GURL& download_url) { | 523 bool ExtensionsService::IsDownloadFromMiniGallery(const GURL& download_url) { |
| 524 return StartsWithASCII(download_url.spec(), | 524 return StartsWithASCII(download_url.spec(), |
| 525 extension_urls::kMiniGalleryDownloadPrefix, | 525 extension_urls::kMiniGalleryDownloadPrefix, |
| 526 false); // case_sensitive | 526 false); // case_sensitive |
| 527 } | 527 } |
| 528 | 528 |
| 529 ExtensionsService::ExtensionsService(Profile* profile, | 529 ExtensionsService::ExtensionsService(Profile* profile, |
| 530 const CommandLine* command_line, | 530 const CommandLine* command_line, |
| 531 PrefService* prefs, | |
| 532 const FilePath& install_directory, | 531 const FilePath& install_directory, |
| 533 bool autoupdate_enabled) | 532 bool autoupdate_enabled) |
| 534 : profile_(profile), | 533 : profile_(profile), |
| 535 extension_prefs_(new ExtensionPrefs(prefs, install_directory)), | 534 extension_prefs_(new ExtensionPrefs(profile->GetPrefs(), |
| 535 install_directory)), |
| 536 install_directory_(install_directory), | 536 install_directory_(install_directory), |
| 537 extensions_enabled_(true), | 537 extensions_enabled_(true), |
| 538 show_extensions_prompts_(true), | 538 show_extensions_prompts_(true), |
| 539 ready_(false), | 539 ready_(false), |
| 540 ALLOW_THIS_IN_INITIALIZER_LIST(toolbar_model_(this)) { | 540 ALLOW_THIS_IN_INITIALIZER_LIST(toolbar_model_(this)) { |
| 541 // Figure out if extension installation should be enabled. | 541 // Figure out if extension installation should be enabled. |
| 542 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 542 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 543 extensions_enabled_ = false; | 543 extensions_enabled_ = false; |
| 544 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { | 544 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 545 extensions_enabled_ = false; | 545 extensions_enabled_ = false; |
| 546 } | 546 } |
| 547 | 547 |
| 548 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 548 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
| 549 NotificationService::AllSources()); | 549 NotificationService::AllSources()); |
| 550 prefs->AddPrefObserver(prefs::kExtensionInstallAllowList, this); | 550 pref_change_registrar_.Init(profile->GetPrefs()); |
| 551 prefs->AddPrefObserver(prefs::kExtensionInstallDenyList, this); | 551 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 552 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
| 552 | 553 |
| 553 // Set up the ExtensionUpdater | 554 // Set up the ExtensionUpdater |
| 554 if (autoupdate_enabled) { | 555 if (autoupdate_enabled) { |
| 555 int update_frequency = kDefaultUpdateFrequencySeconds; | 556 int update_frequency = kDefaultUpdateFrequencySeconds; |
| 556 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { | 557 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
| 557 base::StringToInt(command_line->GetSwitchValueASCII( | 558 base::StringToInt(command_line->GetSwitchValueASCII( |
| 558 switches::kExtensionsUpdateFrequency), | 559 switches::kExtensionsUpdateFrequency), |
| 559 &update_frequency); | 560 &update_frequency); |
| 560 } | 561 } |
| 561 updater_ = new ExtensionUpdater(this, prefs, update_frequency); | 562 updater_ = new ExtensionUpdater(this, |
| 563 profile->GetPrefs(), |
| 564 update_frequency); |
| 562 } | 565 } |
| 563 | 566 |
| 564 backend_ = new ExtensionsServiceBackend(install_directory_, | 567 backend_ = new ExtensionsServiceBackend(install_directory_, |
| 565 extensions_enabled_); | 568 extensions_enabled_); |
| 566 | 569 |
| 567 // Use monochrome icons for Omnibox icons. | 570 // Use monochrome icons for Omnibox icons. |
| 568 omnibox_popup_icon_manager_.set_monochrome(true); | 571 omnibox_popup_icon_manager_.set_monochrome(true); |
| 569 omnibox_icon_manager_.set_monochrome(true); | 572 omnibox_icon_manager_.set_monochrome(true); |
| 570 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, | 573 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
| 571 0, kOmniboxIconPaddingRight)); | 574 0, kOmniboxIconPaddingRight)); |
| 572 } | 575 } |
| 573 | 576 |
| 574 ExtensionsService::~ExtensionsService() { | 577 ExtensionsService::~ExtensionsService() { |
| 578 DCHECK(!profile_); // Profile should have told us it's going away. |
| 575 UnloadAllExtensions(); | 579 UnloadAllExtensions(); |
| 576 if (updater_.get()) { | 580 if (updater_.get()) { |
| 577 updater_->Stop(); | 581 updater_->Stop(); |
| 578 } | 582 } |
| 579 } | 583 } |
| 580 | 584 |
| 581 void ExtensionsService::InitEventRouters() { | 585 void ExtensionsService::InitEventRouters() { |
| 582 ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); | 586 ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); |
| 583 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); | 587 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); |
| 584 ExtensionBrowserEventRouter::GetInstance()->Init(profile_); | 588 ExtensionBrowserEventRouter::GetInstance()->Init(profile_); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 } | 1183 } |
| 1180 | 1184 |
| 1181 // UnloadExtension will change the extensions_ list. So, we should | 1185 // UnloadExtension will change the extensions_ list. So, we should |
| 1182 // call it outside the iterator loop. | 1186 // call it outside the iterator loop. |
| 1183 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { | 1187 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
| 1184 UnloadExtension(to_be_removed[i]); | 1188 UnloadExtension(to_be_removed[i]); |
| 1185 } | 1189 } |
| 1186 } | 1190 } |
| 1187 | 1191 |
| 1188 void ExtensionsService::DestroyingProfile() { | 1192 void ExtensionsService::DestroyingProfile() { |
| 1189 profile_->GetPrefs()->RemovePrefObserver( | 1193 pref_change_registrar_.RemoveAll(); |
| 1190 prefs::kExtensionInstallAllowList, this); | |
| 1191 profile_->GetPrefs()->RemovePrefObserver( | |
| 1192 prefs::kExtensionInstallDenyList, this); | |
| 1193 | |
| 1194 profile_ = NULL; | 1194 profile_ = NULL; |
| 1195 toolbar_model_.DestroyingProfile(); |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 void ExtensionsService::CheckAdminBlacklist() { | 1198 void ExtensionsService::CheckAdminBlacklist() { |
| 1198 std::vector<std::string> to_be_removed; | 1199 std::vector<std::string> to_be_removed; |
| 1199 // Loop through extensions list, unload installed extensions. | 1200 // Loop through extensions list, unload installed extensions. |
| 1200 for (ExtensionList::const_iterator iter = extensions_.begin(); | 1201 for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1201 iter != extensions_.end(); ++iter) { | 1202 iter != extensions_.end(); ++iter) { |
| 1202 Extension* extension = (*iter); | 1203 Extension* extension = (*iter); |
| 1203 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) | 1204 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) |
| 1204 to_be_removed.push_back(extension->id()); | 1205 to_be_removed.push_back(extension->id()); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1793 return false; | 1794 return false; |
| 1794 | 1795 |
| 1795 for (ExtensionList::const_iterator it = extensions_.begin(); | 1796 for (ExtensionList::const_iterator it = extensions_.begin(); |
| 1796 it != extensions_.end(); ++it) { | 1797 it != extensions_.end(); ++it) { |
| 1797 if ((*it)->is_app()) | 1798 if ((*it)->is_app()) |
| 1798 return true; | 1799 return true; |
| 1799 } | 1800 } |
| 1800 | 1801 |
| 1801 return false; | 1802 return false; |
| 1802 } | 1803 } |
| OLD | NEW |