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

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

Issue 297263003: Optimize promotion of ephemeral apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 void ExtensionService::AddNewOrUpdatedExtension( 1884 void ExtensionService::AddNewOrUpdatedExtension(
1885 const Extension* extension, 1885 const Extension* extension,
1886 Extension::State initial_state, 1886 Extension::State initial_state,
1887 extensions::BlacklistState blacklist_state, 1887 extensions::BlacklistState blacklist_state,
1888 bool is_ephemeral, 1888 bool is_ephemeral,
1889 const syncer::StringOrdinal& page_ordinal, 1889 const syncer::StringOrdinal& page_ordinal,
1890 const std::string& install_parameter) { 1890 const std::string& install_parameter) {
1891 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1891 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1892 const bool blacklisted_for_malware = 1892 const bool blacklisted_for_malware =
1893 blacklist_state == extensions::BLACKLISTED_MALWARE; 1893 blacklist_state == extensions::BLACKLISTED_MALWARE;
1894 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
1894 extension_prefs_->OnExtensionInstalled(extension, 1895 extension_prefs_->OnExtensionInstalled(extension,
1895 initial_state, 1896 initial_state,
1896 blacklisted_for_malware, 1897 blacklisted_for_malware,
1897 is_ephemeral, 1898 is_ephemeral,
1898 page_ordinal, 1899 page_ordinal,
1899 install_parameter); 1900 install_parameter);
1900 delayed_installs_.Remove(extension->id()); 1901 delayed_installs_.Remove(extension->id());
1901 if (InstallVerifier::NeedsVerification(*extension)) 1902 if (InstallVerifier::NeedsVerification(*extension))
1902 system_->install_verifier()->VerifyExtension(extension->id()); 1903 system_->install_verifier()->VerifyExtension(extension->id());
1903 FinishInstallation(extension); 1904 FinishInstallation(extension, was_ephemeral);
1904 } 1905 }
1905 1906
1906 void ExtensionService::MaybeFinishDelayedInstallation( 1907 void ExtensionService::MaybeFinishDelayedInstallation(
1907 const std::string& extension_id) { 1908 const std::string& extension_id) {
1908 // Check if the extension already got installed. 1909 // Check if the extension already got installed.
1909 if (!delayed_installs_.Contains(extension_id)) 1910 if (!delayed_installs_.Contains(extension_id))
1910 return; 1911 return;
1911 extensions::ExtensionPrefs::DelayReason reason = 1912 extensions::ExtensionPrefs::DelayReason reason =
1912 extension_prefs_->GetDelayedInstallReason(extension_id); 1913 extension_prefs_->GetDelayedInstallReason(extension_id);
1913 1914
(...skipping 24 matching lines...) Expand all
1938 FinishDelayedInstallation(extension_id); 1939 FinishDelayedInstallation(extension_id);
1939 } 1940 }
1940 1941
1941 void ExtensionService::FinishDelayedInstallation( 1942 void ExtensionService::FinishDelayedInstallation(
1942 const std::string& extension_id) { 1943 const std::string& extension_id) {
1943 scoped_refptr<const Extension> extension( 1944 scoped_refptr<const Extension> extension(
1944 GetPendingExtensionUpdate(extension_id)); 1945 GetPendingExtensionUpdate(extension_id));
1945 CHECK(extension.get()); 1946 CHECK(extension.get());
1946 delayed_installs_.Remove(extension_id); 1947 delayed_installs_.Remove(extension_id);
1947 1948
1949 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
1948 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) 1950 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
1949 NOTREACHED(); 1951 NOTREACHED();
1950 1952
1951 FinishInstallation(extension.get()); 1953 FinishInstallation(extension.get(), was_ephemeral);
1952 } 1954 }
1953 1955
1954 void ExtensionService::FinishInstallation(const Extension* extension) { 1956 void ExtensionService::FinishInstallation(
1957 const Extension* extension, bool was_ephemeral) {
1955 const extensions::Extension* existing_extension = 1958 const extensions::Extension* existing_extension =
1956 GetInstalledExtension(extension->id()); 1959 GetInstalledExtension(extension->id());
1957 bool is_update = false; 1960 bool is_update = false;
1958 std::string old_name; 1961 std::string old_name;
1959 if (existing_extension) { 1962 if (existing_extension) {
1960 is_update = true; 1963 is_update = true;
1961 old_name = existing_extension->name(); 1964 old_name = existing_extension->name();
1962 } 1965 }
1963 extensions::InstalledExtensionInfo details(extension, is_update, old_name); 1966 bool from_ephemeral =
1967 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1968 extensions::InstalledExtensionInfo details(
1969 extension, is_update, from_ephemeral, old_name);
1964 content::NotificationService::current()->Notify( 1970 content::NotificationService::current()->Notify(
1965 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, 1971 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
1966 content::Source<Profile>(profile_), 1972 content::Source<Profile>(profile_),
1967 content::Details<const extensions::InstalledExtensionInfo>(&details)); 1973 content::Details<const extensions::InstalledExtensionInfo>(&details));
1968 1974
1969 ExtensionRegistry::Get(profile_) 1975 ExtensionRegistry::Get(profile_)->TriggerOnWillBeInstalled(
1970 ->TriggerOnWillBeInstalled(extension, is_update, old_name); 1976 extension, is_update, from_ephemeral, old_name);
1971 1977
1972 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); 1978 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
1973 1979
1974 // Unpacked extensions default to allowing file access, but if that has been 1980 // Unpacked extensions default to allowing file access, but if that has been
1975 // overridden, don't reset the value. 1981 // overridden, don't reset the value.
1976 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && 1982 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
1977 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { 1983 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1978 extension_prefs_->SetAllowFileAccess(extension->id(), true); 1984 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1979 } 1985 }
1980 1986
(...skipping 18 matching lines...) Expand all
1999 } 2005 }
2000 } 2006 }
2001 2007
2002 // Check extensions that may have been delayed only because this shared module 2008 // Check extensions that may have been delayed only because this shared module
2003 // was not available. 2009 // was not available.
2004 if (SharedModuleInfo::IsSharedModule(extension)) { 2010 if (SharedModuleInfo::IsSharedModule(extension)) {
2005 MaybeFinishDelayedInstallations(); 2011 MaybeFinishDelayedInstallations();
2006 } 2012 }
2007 } 2013 }
2008 2014
2015 void ExtensionService::PromoteEphemeralApp(
2016 const extensions::Extension* extension, bool is_from_sync) {
2017 DCHECK(GetInstalledExtension(extension->id()) &&
2018 extension_prefs_->IsEphemeralApp(extension->id()));
2019
2020 if (!is_from_sync) {
2021 if (extension->RequiresSortOrdinal()) {
2022 // Reset the sort ordinals of the app to ensure it is added to the default
2023 // position, like newly installed apps would.
2024 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
2025 extension_prefs_->app_sorting()->EnsureValidOrdinals(
2026 extension->id(), syncer::StringOrdinal());
2027 }
2028
2029 if (extension_prefs_->IsExtensionDisabled(extension->id()) &&
2030 !extension_prefs_->IsExtensionBlacklisted(extension->id())) {
2031 // If the extension is not blacklisted and was disabled due to permission
2032 // increase or user action only, we can enable it because the user was
2033 // prompted.
2034 extension_prefs_->RemoveDisableReason(
2035 extension->id(),
2036 Extension::DISABLE_PERMISSIONS_INCREASE);
2037 extension_prefs_->RemoveDisableReason(
2038 extension->id(),
2039 Extension::DISABLE_USER_ACTION);
2040 if (!extension_prefs_->GetDisableReasons(extension->id()))
2041 EnableExtension(extension->id());
2042 }
2043 }
2044
2045 // Remove the ephemeral flags from the preferences.
2046 extension_prefs_->OnEphemeralAppPromoted(extension->id());
2047
2048 // Fire install-related events to allow observers to handle the promotion
2049 // of the ephemeral app.
2050 extensions::InstalledExtensionInfo details(
2051 extension,
2052 true /* is update */,
2053 true /* from ephemeral */,
2054 extension->name() /* old name */);
2055 content::NotificationService::current()->Notify(
2056 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
2057 content::Source<Profile>(profile_),
2058 content::Details<const extensions::InstalledExtensionInfo>(&details));
2059
2060 registry_->TriggerOnWillBeInstalled(
2061 extension,
2062 true /* is update */,
2063 true /* from ephemeral */,
2064 extension->name() /* old name */);
2065
2066 if (registry_->enabled_extensions().Contains(extension->id())) {
2067 content::NotificationService::current()->Notify(
2068 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
2069 content::Source<Profile>(profile_),
2070 content::Details<const Extension>(extension));
2071
2072 registry_->TriggerOnLoaded(extension);
2073 }
2074
2075 if (!is_from_sync && extension_sync_service_)
2076 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
2077 }
2078
2009 const Extension* ExtensionService::GetPendingExtensionUpdate( 2079 const Extension* ExtensionService::GetPendingExtensionUpdate(
2010 const std::string& id) const { 2080 const std::string& id) const {
2011 return delayed_installs_.GetByID(id); 2081 return delayed_installs_.GetByID(id);
2012 } 2082 }
2013 2083
2014 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { 2084 void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
2015 // No need to check for duplicates; inserting a duplicate is a no-op. 2085 // No need to check for duplicates; inserting a duplicate is a no-op.
2016 registry_->AddTerminated(make_scoped_refptr(extension)); 2086 registry_->AddTerminated(make_scoped_refptr(extension));
2017 extensions_being_terminated_.erase(extension->id()); 2087 extensions_being_terminated_.erase(extension->id());
2018 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); 2088 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 } 2543 }
2474 2544
2475 void ExtensionService::OnProfileDestructionStarted() { 2545 void ExtensionService::OnProfileDestructionStarted() {
2476 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2546 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2477 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2547 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2478 it != ids_to_unload.end(); 2548 it != ids_to_unload.end();
2479 ++it) { 2549 ++it) {
2480 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2550 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2481 } 2551 }
2482 } 2552 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698