Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 344543006: Disable ephemeral apps after they stop running (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments and refactoring Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 external_extension_providers_.clear(); 156 external_extension_providers_.clear();
157 } 157 }
158 158
159 void ExtensionService::AddProviderForTesting( 159 void ExtensionService::AddProviderForTesting(
160 extensions::ExternalProviderInterface* test_provider) { 160 extensions::ExternalProviderInterface* test_provider) {
161 CHECK(test_provider); 161 CHECK(test_provider);
162 external_extension_providers_.push_back( 162 external_extension_providers_.push_back(
163 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); 163 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
164 } 164 }
165 165
166 void ExtensionService::BlacklistExtensionForTest(
167 const std::string& extension_id) {
168 ExtensionIdSet blocked;
169 ExtensionIdSet unchanged;
170 blocked.insert(extension_id);
171 UpdateBlockedExtensions(blocked, unchanged);
172 }
173
166 bool ExtensionService::OnExternalExtensionUpdateUrlFound( 174 bool ExtensionService::OnExternalExtensionUpdateUrlFound(
167 const std::string& id, 175 const std::string& id,
168 const std::string& install_parameter, 176 const std::string& install_parameter,
169 const GURL& update_url, 177 const GURL& update_url,
170 Manifest::Location location, 178 Manifest::Location location,
171 int creation_flags, 179 int creation_flags,
172 bool mark_acknowledged) { 180 bool mark_acknowledged) {
173 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 181 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174 CHECK(Extension::IdIsValid(id)); 182 CHECK(Extension::IdIsValid(id));
175 183
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 846
839 if (extension_sync_service_) 847 if (extension_sync_service_)
840 extension_sync_service_->SyncEnableExtension(*extension); 848 extension_sync_service_->SyncEnableExtension(*extension);
841 } 849 }
842 850
843 void ExtensionService::DisableExtension( 851 void ExtensionService::DisableExtension(
844 const std::string& extension_id, 852 const std::string& extension_id,
845 Extension::DisableReason disable_reason) { 853 Extension::DisableReason disable_reason) {
846 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 854 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
847 855
848 // The extension may have been disabled already. 856 // The extension may have been disabled already. Just add a disable reason.
849 if (!IsExtensionEnabled(extension_id)) 857 if (!IsExtensionEnabled(extension_id)) {
858 extension_prefs_->AddDisableReason(extension_id, disable_reason);
850 return; 859 return;
860 }
851 861
852 const Extension* extension = GetInstalledExtension(extension_id); 862 const Extension* extension = GetInstalledExtension(extension_id);
853 // |extension| can be NULL if sync disables an extension that is not 863 // |extension| can be NULL if sync disables an extension that is not
854 // installed yet. 864 // installed yet.
855 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but 865 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
856 // can be uninstalled by the browser if the user sets extension-specific 866 // can be uninstalled by the browser if the user sets extension-specific
857 // preferences. 867 // preferences.
858 if (extension && 868 if (extension &&
859 disable_reason != Extension::DISABLE_RELOAD && 869 disable_reason != Extension::DISABLE_RELOAD &&
860 !system_->management_policy()->UserMayModifySettings(extension, NULL) && 870 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 extension->GetType(), 100); 1661 extension->GetType(), 100);
1652 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", 1662 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
1653 extension->location(), Manifest::NUM_LOCATIONS); 1663 extension->location(), Manifest::NUM_LOCATIONS);
1654 RecordPermissionMessagesHistogram(extension, 1664 RecordPermissionMessagesHistogram(extension,
1655 "Extensions.Permissions_Install2"); 1665 "Extensions.Permissions_Install2");
1656 } else { 1666 } else {
1657 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", 1667 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1658 extension->GetType(), 100); 1668 extension->GetType(), 100);
1659 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", 1669 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
1660 extension->location(), Manifest::NUM_LOCATIONS); 1670 extension->location(), Manifest::NUM_LOCATIONS);
1671
1672 // A fully installed app cannot be demoted to an ephemeral app.
1673 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1674 !extension_prefs_->IsEphemeralApp(id)) {
1675 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1676 }
1661 } 1677 }
1662 1678
1663 const Extension::State initial_state = 1679 const Extension::State initial_state =
1664 initial_enable ? Extension::ENABLED : Extension::DISABLED; 1680 initial_enable ? Extension::ENABLED : Extension::DISABLED;
1665 if (ShouldDelayExtensionUpdate( 1681 if (ShouldDelayExtensionUpdate(
1666 id, 1682 id,
1667 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { 1683 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
1668 extension_prefs_->SetDelayedInstallInfo( 1684 extension_prefs_->SetDelayedInstallInfo(
1669 extension, 1685 extension,
1670 initial_state, 1686 initial_state,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 if (!is_from_sync) { 1846 if (!is_from_sync) {
1831 // Reset the sort ordinals of the app to ensure it is added to the default 1847 // Reset the sort ordinals of the app to ensure it is added to the default
1832 // position, like newly installed apps would. 1848 // position, like newly installed apps would.
1833 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); 1849 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
1834 } 1850 }
1835 1851
1836 extension_prefs_->app_sorting()->EnsureValidOrdinals( 1852 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1837 extension->id(), syncer::StringOrdinal()); 1853 extension->id(), syncer::StringOrdinal());
1838 } 1854 }
1839 1855
1840 if (!is_from_sync) {
1841 // Cached ephemeral apps may be updated and disabled due to permissions
1842 // increase. The app can be enabled as the install was user-acknowledged.
1843 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
1844 GrantPermissionsAndEnableExtension(extension);
1845 }
1846
1847 // Remove the ephemeral flags from the preferences. 1856 // Remove the ephemeral flags from the preferences.
1848 extension_prefs_->OnEphemeralAppPromoted(extension->id()); 1857 extension_prefs_->OnEphemeralAppPromoted(extension->id());
1849 1858
1850 // Fire install-related events to allow observers to handle the promotion 1859 // Fire install-related events to allow observers to handle the promotion
1851 // of the ephemeral app. 1860 // of the ephemeral app.
1852 extensions::InstalledExtensionInfo details( 1861 extensions::InstalledExtensionInfo details(
1853 extension, 1862 extension,
1854 true /* is update */, 1863 true /* is update */,
1855 true /* from ephemeral */, 1864 true /* from ephemeral */,
1856 extension->name() /* old name */); 1865 extension->name() /* old name */);
1857 content::NotificationService::current()->Notify( 1866 content::NotificationService::current()->Notify(
1858 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, 1867 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1859 content::Source<Profile>(profile_), 1868 content::Source<Profile>(profile_),
1860 content::Details<const extensions::InstalledExtensionInfo>(&details)); 1869 content::Details<const extensions::InstalledExtensionInfo>(&details));
1861 1870
1862 registry_->TriggerOnWillBeInstalled( 1871 registry_->TriggerOnWillBeInstalled(
1863 extension, 1872 extension,
1864 true /* is update */, 1873 true /* is update */,
1865 true /* from ephemeral */, 1874 true /* from ephemeral */,
1866 extension->name() /* old name */); 1875 extension->name() /* old name */);
1867 1876
1868 if (registry_->enabled_extensions().Contains(extension->id())) { 1877 if (registry_->enabled_extensions().Contains(extension->id())) {
1878 // If the app is already enabled and loaded, fire the load events to allow
1879 // observers to handle the promotion of the ephemeral app.
1869 content::NotificationService::current()->Notify( 1880 content::NotificationService::current()->Notify(
1870 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 1881 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
1871 content::Source<Profile>(profile_), 1882 content::Source<Profile>(profile_),
1872 content::Details<const Extension>(extension)); 1883 content::Details<const Extension>(extension));
1873 1884
1874 registry_->TriggerOnLoaded(extension); 1885 registry_->TriggerOnLoaded(extension);
1886 } else {
1887 // Cached ephemeral apps may be updated and disabled due to permissions
1888 // increase. The app can be enabled (as long as no other disable reasons
1889 // exist) as the install was user-acknowledged.
1890 int disable_mask = Extension::DISABLE_NONE;
1891 if (!is_from_sync)
1892 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE;
1893
1894 int other_disable_reasons =
1895 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask;
1896 if (!other_disable_reasons) {
1897 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
1898 GrantPermissionsAndEnableExtension(extension);
1899 else
1900 EnableExtension(extension->id());
1901 }
1875 } 1902 }
1876 1903
1877 registry_->TriggerOnInstalled(extension, true); 1904 registry_->TriggerOnInstalled(extension, true);
1878 1905
1879 if (!is_from_sync && extension_sync_service_) 1906 if (!is_from_sync && extension_sync_service_)
1880 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); 1907 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1881 } 1908 }
1882 1909
1883 const Extension* ExtensionService::GetPendingExtensionUpdate( 1910 const Extension* ExtensionService::GetPendingExtensionUpdate(
1884 const std::string& id) const { 1911 const std::string& id) const {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 } 2360 }
2334 2361
2335 void ExtensionService::OnProfileDestructionStarted() { 2362 void ExtensionService::OnProfileDestructionStarted() {
2336 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2363 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2337 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2364 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2338 it != ids_to_unload.end(); 2365 it != ids_to_unload.end();
2339 ++it) { 2366 ++it) {
2340 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2367 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2341 } 2368 }
2342 } 2369 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/notifications/message_center_settings_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698