diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-21 19:40:08 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-21 19:40:08 +0000 |
commit | 7fa19f8c525235f3318359b4e6f647e1dfd18f46 (patch) | |
tree | 83b8148a77823c65c8f74aba0a079bc4b1e94bd1 /chrome | |
parent | 0ff0ff32b0b9f301200cb4e595fef541118a2987 (diff) | |
download | chromium_src-7fa19f8c525235f3318359b4e6f647e1dfd18f46.zip chromium_src-7fa19f8c525235f3318359b4e6f647e1dfd18f46.tar.gz chromium_src-7fa19f8c525235f3318359b4e6f647e1dfd18f46.tar.bz2 |
Coalesced various extension type enums into Extension::Type.
Renamed Extension::HistogramType to Extension::Type and used it
everywhere.
Moved extension sync security checks into sync land and simplified them.
BUG=55823
TEST=Existing unit tests / sync integration tests
Review URL: http://codereview.chromium.org/5946001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 136 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 40 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service_unittest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater.cc | 37 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater.h | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater_unittest.cc | 32 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_change_processor.cc | 12 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_sync.cc | 35 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_sync_traits.cc | 64 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_sync_traits.h | 27 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_util.cc | 48 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_util.h | 31 | ||||
-rw-r--r-- | chrome/browser/sync/glue/extension_util_unittest.cc | 79 | ||||
-rw-r--r-- | chrome/browser/sync/glue/theme_util.cc | 12 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 6 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 16 |
16 files changed, 252 insertions, 386 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index afb7e04..d364648 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -49,8 +49,6 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/sync/glue/extension_sync_traits.h" -#include "chrome/browser/sync/glue/extension_util.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" @@ -146,14 +144,14 @@ void GetExplicitOriginsInExtent(const Extension* extension, PendingExtensionInfo::PendingExtensionInfo( const GURL& update_url, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + ShouldInstallExtensionPredicate should_install_extension, bool is_from_sync, bool install_silently, bool enable_on_install, bool enable_incognito_on_install, Extension::Location location) : update_url(update_url), - expected_crx_type(expected_crx_type), + should_install_extension(should_install_extension), is_from_sync(is_from_sync), install_silently(install_silently), enable_on_install(enable_on_install), @@ -162,7 +160,7 @@ PendingExtensionInfo::PendingExtensionInfo( PendingExtensionInfo::PendingExtensionInfo() : update_url(), - expected_crx_type(PendingExtensionInfo::UNKNOWN), + should_install_extension(NULL), is_from_sync(true), install_silently(false), enable_on_install(false), @@ -718,7 +716,7 @@ void ExtensionService::UpdateExtension(const std::string& id, void ExtensionService::AddPendingExtensionFromSync( const std::string& id, const GURL& update_url, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + ShouldInstallExtensionPredicate should_install_extension, bool install_silently, bool enable_on_install, bool enable_incognito_on_install) { if (GetExtensionByIdInternal(id, true, true)) { @@ -727,18 +725,23 @@ void ExtensionService::AddPendingExtensionFromSync( return; } - AddPendingExtensionInternal(id, update_url, expected_crx_type, true, + AddPendingExtensionInternal(id, update_url, should_install_extension, true, install_silently, enable_on_install, enable_incognito_on_install, Extension::INTERNAL); } +namespace { + +bool AlwaysInstall(const Extension& extension) { + return true; +} + +} // namespace + void ExtensionService::AddPendingExtensionFromExternalUpdateUrl( const std::string& id, const GURL& update_url, Extension::Location location) { - // Add the extension to this list of extensions to update. - const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = - PendingExtensionInfo::UNKNOWN; const bool kIsFromSync = false; const bool kInstallSilently = true; const bool kEnableOnInstall = true; @@ -752,17 +755,25 @@ void ExtensionService::AddPendingExtensionFromExternalUpdateUrl( return; } - AddPendingExtensionInternal(id, update_url, kExpectedCrxType, kIsFromSync, - kInstallSilently, kEnableOnInstall, - kEnableIncognitoOnInstall, + AddPendingExtensionInternal(id, update_url, &AlwaysInstall, + kIsFromSync, kInstallSilently, + kEnableOnInstall, kEnableIncognitoOnInstall, location); } +namespace { + +bool IsApp(const Extension& extension) { + return extension.is_app(); +} + +} // namespace + +// TODO(akalin): Change DefaultAppList to DefaultExtensionList and +// remove the IsApp() check. + void ExtensionService::AddPendingExtensionFromDefaultAppList( const std::string& id) { - // Add the extension to this list of extensions to update. - const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = - PendingExtensionInfo::APP; const bool kIsFromSync = false; const bool kInstallSilently = true; const bool kEnableOnInstall = true; @@ -773,15 +784,15 @@ void ExtensionService::AddPendingExtensionFromDefaultAppList( if (GetExtensionByIdInternal(id, true, true)) return; - AddPendingExtensionInternal(id, GURL(), kExpectedCrxType, kIsFromSync, - kInstallSilently, kEnableOnInstall, - kEnableIncognitoOnInstall, + AddPendingExtensionInternal(id, GURL(), &IsApp, + kIsFromSync, kInstallSilently, + kEnableOnInstall, kEnableIncognitoOnInstall, Extension::INTERNAL); } void ExtensionService::AddPendingExtensionInternal( const std::string& id, const GURL& update_url, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + ShouldInstallExtensionPredicate should_install_extension, bool is_from_sync, bool install_silently, bool enable_on_install, bool enable_incognito_on_install, Extension::Location install_source) { @@ -806,8 +817,8 @@ void ExtensionService::AddPendingExtensionInternal( } pending_extensions_[id] = - PendingExtensionInfo(update_url, expected_crx_type, is_from_sync, - install_silently, enable_on_install, + PendingExtensionInfo(update_url, should_install_extension, + is_from_sync, install_silently, enable_on_install, enable_incognito_on_install, install_source); } @@ -871,7 +882,7 @@ void ExtensionService::UninstallExtension(const std::string& extension_id, UninstalledExtensionInfo uninstalled_extension_info(*extension); UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", - extension->GetHistogramType(), 100); + extension->GetType(), 100); // Also copy the extension identifier since the reference might have been // obtained via Extension::id(). @@ -1100,7 +1111,7 @@ void ExtensionService::LoadAllExtensions() { ExtensionList::iterator ex; for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) { Extension::Location location = (*ex)->location(); - Extension::HistogramType type = (*ex)->GetHistogramType(); + Extension::Type type = (*ex)->GetType(); if ((*ex)->is_app()) { UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", location, 100); @@ -1729,25 +1740,17 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) { pending_extensions_.find(extension->id()); if (it != pending_extensions_.end()) { PendingExtensionInfo pending_extension_info = it->second; - PendingExtensionInfo::ExpectedCrxType expected_crx_type = - pending_extension_info.expected_crx_type; - bool is_from_sync = pending_extension_info.is_from_sync; pending_extensions_.erase(it); it = pending_extensions_.end(); - // Set initial state from pending extension data. - PendingExtensionInfo::ExpectedCrxType actual_crx_type = - PendingExtensionInfo::EXTENSION; - if (extension->is_app()) - actual_crx_type = PendingExtensionInfo::APP; - else if (extension->is_theme()) - actual_crx_type = PendingExtensionInfo::THEME; - - if (expected_crx_type != PendingExtensionInfo::UNKNOWN && - expected_crx_type != actual_crx_type) { + if (!pending_extension_info.should_install_extension(*extension)) { LOG(WARNING) - << "Not installing pending extension " << extension->id() - << " with is_theme = " << extension->is_theme(); + << "should_install_extension (" + << pending_extension_info.should_install_extension + << ") returned false for " << extension->id() + << " of type " << extension->GetType() + << " and update URL " << extension->update_url().spec() + << "; not installing"; // Delete the extension directory since we're not going to // load it. BrowserThread::PostTask( @@ -1756,55 +1759,6 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) { return; } - // If |extension| is not syncable, and was installed via sync, disallow - // the instanation. - // - // Themes are always allowed. Because they contain no active code, they - // are less of a risk than extensions. - // - // If |is_from_sync| is false, then the install was not initiated by sync, - // and this check should pass. Extensions that were installed from an - // update URL in external_extensions.json are an example. They are not - // syncable, because the user did not make an explicit choice to install - // them. However, they were installed through the update mechanism, so - // control must pass into this function. - // - // TODO(akalin): When we do apps sync, we have to work with its - // traits, too. - const browser_sync::ExtensionSyncTraits extension_sync_traits = - browser_sync::GetExtensionSyncTraits(); - const browser_sync::ExtensionSyncTraits app_sync_traits = - browser_sync::GetAppSyncTraits(); - // If an extension is a theme, we bypass the valid/syncable check - // as themes are harmless. - if (!extension->is_theme() && is_from_sync && - !browser_sync::IsExtensionValidAndSyncable( - *extension, extension_sync_traits.allowed_extension_types) && - !browser_sync::IsExtensionValidAndSyncable( - *extension, app_sync_traits.allowed_extension_types)) { - // We're an extension installed via sync that is unsyncable, - // i.e. we may have been syncable previously. We block these - // installs. We'll have to update the clause above if we decide - // to sync other extension-like things, like apps or user - // scripts. - // - // Note that this creates a small window where a user who tries - // to download/install an extension that is simultaneously - // installed via sync (and blocked) will find his download - // blocked. - // - // TODO(akalin): Remove this check once we've put in UI to - // approve synced extensions. - LOG(WARNING) - << "Not installing invalid or unsyncable extension " - << extension->id(); - // Delete the extension directory since we're not going to - // load it. - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableFunction(&DeleteFileHelper, extension->path(), true)); - return; - } if (extension->is_theme()) { DCHECK(pending_extension_info.enable_on_install); initial_state = Extension::ENABLED; @@ -1829,7 +1783,7 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) { } UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", - extension->GetHistogramType(), 100); + extension->GetType(), 100); ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); extension_prefs_->OnExtensionInstalled( extension, initial_state, initial_enable_incognito); @@ -1976,15 +1930,13 @@ void ExtensionService::OnExternalExtensionFileFound( } GURL update_url = GURL(); - PendingExtensionInfo::ExpectedCrxType expected_crx_type = - PendingExtensionInfo::UNKNOWN; bool is_from_sync = false; bool install_silently = true; bool enable_on_install = true; bool enable_incognito_on_install = false; pending_extensions_[id] = PendingExtensionInfo( update_url, - expected_crx_type, + &AlwaysInstall, is_from_sync, install_silently, enable_on_install, diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index defa10a..2ae45ef 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -41,33 +41,29 @@ class GURL; class Profile; class Version; +typedef bool (*ShouldInstallExtensionPredicate)(const Extension&); + // A pending extension is an extension that hasn't been installed yet // and is intended to be installed in the next auto-update cycle. The // update URL of a pending extension may be blank, in which case a // default one is assumed. struct PendingExtensionInfo { - // TODO(skerner): Consider merging ExpectedCrxType with - // browser_sync::ExtensionType. - enum ExpectedCrxType { - UNKNOWN, // Sometimes we don't know the type of a pending item. An - // update URL from external_extensions.json is one such case. - APP, - THEME, - EXTENSION - }; - - PendingExtensionInfo(const GURL& update_url, - ExpectedCrxType expected_crx_type, - bool is_from_sync, - bool install_silently, - bool enable_on_install, - bool enable_incognito_on_install, - Extension::Location install_source); + PendingExtensionInfo( + const GURL& update_url, + ShouldInstallExtensionPredicate should_install_extension, + bool is_from_sync, + bool install_silently, + bool enable_on_install, + bool enable_incognito_on_install, + Extension::Location install_source); PendingExtensionInfo(); GURL update_url; - ExpectedCrxType expected_crx_type; + // When the extension is about to be installed, this function is + // called. If this function returns true, the install proceeds. If + // this function returns false, the install is aborted. + ShouldInstallExtensionPredicate should_install_extension; bool is_from_sync; // This update check was initiated from sync. bool install_silently; bool enable_on_install; @@ -242,7 +238,7 @@ class ExtensionService // pre-enabled permissions. void AddPendingExtensionFromSync( const std::string& id, const GURL& update_url, - const PendingExtensionInfo::ExpectedCrxType expected_crx_type, + ShouldInstallExtensionPredicate should_install_extension, bool install_silently, bool enable_on_install, bool enable_incognito_on_install); @@ -471,11 +467,11 @@ class ExtensionService bool include_enabled, bool include_disabled); - // Like AddPendingExtension() but assumes an extension with the same - // id is not already installed. + // Like AddPendingExtension*() functions above, but assumes an + // extension with the same id is not already installed. void AddPendingExtensionInternal( const std::string& id, const GURL& update_url, - PendingExtensionInfo::ExpectedCrxType crx_type, + ShouldInstallExtensionPredicate should_install_extension, bool is_from_sync, bool install_silently, bool enable_on_install, bool enable_incognito_on_install, Extension::Location install_source); diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index b9de0f8..5d47e88 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/extension_service_unittest.h" #include <algorithm> +#include <set> #include <vector> #include "base/basictypes.h" @@ -1970,36 +1971,38 @@ TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { EXPECT_EQ("1.0", loaded_[0]->VersionString()); } +namespace { + +bool IsExtension(const Extension& extension) { + return extension.GetType() == Extension::TYPE_EXTENSION; +} + +} // namespace + // Test adding a pending extension. -TEST_F(ExtensionServiceTest, AddPendingExtension) { +TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { InitializeEmptyExtensionService(); const std::string kFakeId("fake-id"); const GURL kFakeUpdateURL("http:://fake.update/url"); - const PendingExtensionInfo::ExpectedCrxType kFakeExpectedCrxType = - PendingExtensionInfo::EXTENSION; const bool kFakeInstallSilently(true); const Extension::State kFakeInitialState(Extension::ENABLED); const bool kFakeInitialIncognitoEnabled(false); service_->AddPendingExtensionFromSync( - kFakeId, kFakeUpdateURL, kFakeExpectedCrxType, kFakeInstallSilently, - kFakeInitialState, kFakeInitialIncognitoEnabled); + kFakeId, kFakeUpdateURL, &IsExtension, + kFakeInstallSilently, kFakeInitialState, kFakeInitialIncognitoEnabled); PendingExtensionMap::const_iterator it = service_->pending_extensions().find(kFakeId); ASSERT_TRUE(it != service_->pending_extensions().end()); EXPECT_EQ(kFakeUpdateURL, it->second.update_url); - EXPECT_EQ(kFakeExpectedCrxType, it->second.expected_crx_type); + EXPECT_EQ(&IsExtension, it->second.should_install_extension); EXPECT_EQ(kFakeInstallSilently, it->second.install_silently); } namespace { const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; const char kGoodUpdateURL[] = "http://good.update/url"; -const PendingExtensionInfo::ExpectedCrxType kCrxTypeTheme = - PendingExtensionInfo::THEME; -const PendingExtensionInfo::ExpectedCrxType kCrxTypeExtension = - PendingExtensionInfo::EXTENSION; const bool kGoodIsFromSync = true; const bool kGoodInstallSilently = true; const Extension::State kGoodInitialState = Extension::DISABLED; @@ -2010,7 +2013,7 @@ const bool kGoodInitialIncognitoEnabled = true; TEST_F(ExtensionServiceTest, UpdatePendingExtension) { InitializeEmptyExtensionService(); service_->AddPendingExtensionFromSync( - kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension, + kGoodId, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently, kGoodInitialState, kGoodInitialIncognitoEnabled); EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId)); @@ -2034,11 +2037,19 @@ TEST_F(ExtensionServiceTest, UpdatePendingExtension) { service_->IsIncognitoEnabled(extension)); } +namespace { + +bool IsTheme(const Extension& extension) { + return extension.is_theme(); +} + +} // namespace + // Test updating a pending theme. TEST_F(ExtensionServiceTest, UpdatePendingTheme) { InitializeEmptyExtensionService(); service_->AddPendingExtensionFromSync( - theme_crx, GURL(), PendingExtensionInfo::THEME, + theme_crx, GURL(), &IsTheme, false, Extension::ENABLED, false); EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx)); @@ -2092,7 +2103,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { // Add a crx to be installed from the update mechanism. service_->AddPendingExtensionFromSync( - kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension, + kGoodId, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently, kGoodInitialState, kGoodInitialIncognitoEnabled); @@ -2113,7 +2124,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { // Add a crx to be installed from the update mechanism. service_->AddPendingExtensionFromSync( - kGoodId, GURL(kGoodUpdateURL), kCrxTypeExtension, + kGoodId, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently, kGoodInitialState, kGoodInitialIncognitoEnabled); @@ -2128,8 +2139,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { InitializeEmptyExtensionService(); service_->AddPendingExtensionFromSync( - theme_crx, GURL(), - PendingExtensionInfo::EXTENSION, + theme_crx, GURL(), &IsExtension, true, Extension::ENABLED, false); EXPECT_TRUE(ContainsKey(service_->pending_extensions(), theme_crx)); @@ -2150,13 +2160,13 @@ TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { // we can mock out ExtensionInstallUI and inject our version into // UpdateExtension(). -// Test updating a pending extension with wrong is_theme. -TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongIsTheme) { +// Test updating a pending extension which fails the should-install test. +TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { InitializeEmptyExtensionService(); // Add pending extension with a flipped is_theme. service_->AddPendingExtensionFromSync( - kGoodId, GURL(kGoodUpdateURL), - kCrxTypeTheme, kGoodInstallSilently, kGoodInitialState, + kGoodId, GURL(kGoodUpdateURL), &IsTheme, + kGoodInstallSilently, kGoodInitialState, kGoodInitialIncognitoEnabled); EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId)); @@ -2206,8 +2216,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { // Use AddPendingExtensionInternal() as AddPendingExtension() would // balk. service_->AddPendingExtensionInternal( - good->id(), good->update_url(), - PendingExtensionInfo::EXTENSION, + good->id(), good->update_url(), &IsExtension, kGoodIsFromSync, kGoodInstallSilently, kGoodInitialState, kGoodInitialIncognitoEnabled, Extension::INTERNAL); UpdateExtension(good->id(), path, INSTALLED); diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc index d143052..63374ac 100644 --- a/chrome/browser/extensions/extension_updater.cc +++ b/chrome/browser/extensions/extension_updater.cc @@ -190,8 +190,7 @@ void ManifestFetchesBuilder::AddExtension(const Extension& extension) { AddExtensionData(extension.location(), extension.id(), *extension.version(), - (extension.is_theme() ? PendingExtensionInfo::THEME - : PendingExtensionInfo::EXTENSION), + extension.GetType(), extension.update_url(), update_url_data); } @@ -204,17 +203,20 @@ void ManifestFetchesBuilder::AddPendingExtension( scoped_ptr<Version> version( Version::GetVersionFromString("0.0.0.0")); - AddExtensionData(info.install_source, id, *version, - info.expected_crx_type, info.update_url, ""); + AddExtensionData( + info.install_source, id, *version, + Extension::TYPE_UNKNOWN, info.update_url, ""); } void ManifestFetchesBuilder::ReportStats() const { - UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtensions", - url_stats_.google_url_count + - url_stats_.other_url_count - - url_stats_.theme_count); + UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", + url_stats_.extension_count); UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", url_stats_.theme_count); + UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckApp", + url_stats_.app_count); + UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckPending", + url_stats_.pending_count); UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl", url_stats_.google_url_count); UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", @@ -239,7 +241,7 @@ void ManifestFetchesBuilder::AddExtensionData( Extension::Location location, const std::string& id, const Version& version, - PendingExtensionInfo::ExpectedCrxType crx_type, + Extension::Type extension_type, GURL update_url, const std::string& update_url_data) { @@ -272,8 +274,21 @@ void ManifestFetchesBuilder::AddExtensionData( url_stats_.other_url_count++; } - if (crx_type == PendingExtensionInfo::THEME) { - url_stats_.theme_count++; + switch (extension_type) { + case Extension::TYPE_THEME: + ++url_stats_.theme_count; + break; + case Extension::TYPE_EXTENSION: + case Extension::TYPE_USER_SCRIPT: + ++url_stats_.extension_count; + break; + case Extension::TYPE_HOSTED_APP: + case Extension::TYPE_PACKAGED_APP: + ++url_stats_.app_count; + case Extension::TYPE_UNKNOWN: + default: + ++url_stats_.pending_count; + break; } DCHECK(!update_url.is_empty()); diff --git a/chrome/browser/extensions/extension_updater.h b/chrome/browser/extensions/extension_updater.h index 8c1997c..d9e6a3e 100644 --- a/chrome/browser/extensions/extension_updater.h +++ b/chrome/browser/extensions/extension_updater.h @@ -104,15 +104,19 @@ class ManifestFetchesBuilder { : no_url_count(0), google_url_count(0), other_url_count(0), - theme_count(0) {} + extension_count(0), + theme_count(0), + app_count(0), + pending_count(0) {} - int no_url_count, google_url_count, other_url_count, theme_count; + int no_url_count, google_url_count, other_url_count; + int extension_count, theme_count, app_count, pending_count; }; void AddExtensionData(Extension::Location location, const std::string& id, const Version& version, - PendingExtensionInfo::ExpectedCrxType crx_type, + Extension::Type extension_type, GURL update_url, const std::string& update_url_data); ExtensionUpdateService* service_; diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc index 23b22d3..d501de6 100644 --- a/chrome/browser/extensions/extension_updater_unittest.cc +++ b/chrome/browser/extensions/extension_updater_unittest.cc @@ -124,22 +124,34 @@ std::string GenerateId(std::string input) { return result; } +bool ShouldInstallExtensionsOnly(const Extension& extension) { + return extension.GetType() == Extension::TYPE_EXTENSION; +} + +bool ShouldInstallThemesOnly(const Extension& extension) { + return extension.is_theme(); +} + +bool ShouldAlwaysInstall(const Extension& extension) { + return true; +} + // Creates test pending extensions and inserts them into list. The // name and version are all based on their index. void CreateTestPendingExtensions(int count, const GURL& update_url, PendingExtensionMap* pending_extensions) { - PendingExtensionInfo::ExpectedCrxType crx_type; for (int i = 1; i <= count; i++) { - crx_type = ((i % 2) ? PendingExtensionInfo::EXTENSION - : PendingExtensionInfo::THEME); + ShouldInstallExtensionPredicate should_install_extension = + (i % 2 == 0) ? &ShouldInstallThemesOnly : + &ShouldInstallExtensionsOnly; const bool kIsFromSync = true; const bool kInstallSilently = true; const Extension::State kInitialState = Extension::ENABLED; const bool kInitialIncognitoEnabled = false; std::string id = GenerateId(base::StringPrintf("extension%i", i)); (*pending_extensions)[id] = - PendingExtensionInfo(update_url, crx_type, kIsFromSync, - kInstallSilently, kInitialState, + PendingExtensionInfo(update_url, should_install_extension, + kIsFromSync, kInstallSilently, kInitialState, kInitialIncognitoEnabled, Extension::INTERNAL); } } @@ -636,15 +648,13 @@ class ExtensionUpdaterTest : public testing::Test { updater->FetchUpdatedExtension(id, test_url, hash, version->GetString()); if (pending) { - const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = - PendingExtensionInfo::EXTENSION; const bool kIsFromSync = true; const bool kInstallSilently = true; const Extension::State kInitialState = Extension::ENABLED; const bool kInitialIncognitoEnabled = false; PendingExtensionMap pending_extensions; pending_extensions[id] = - PendingExtensionInfo(test_url, kExpectedCrxType, kIsFromSync, + PendingExtensionInfo(test_url, &ShouldAlwaysInstall, kIsFromSync, kInstallSilently, kInitialState, kInitialIncognitoEnabled, Extension::INTERNAL); service.set_pending_extensions(pending_extensions); @@ -985,14 +995,14 @@ TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { // Extensions with invalid update URLs should be rejected. builder.AddPendingExtension( GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), - PendingExtensionInfo::EXTENSION, + &ShouldInstallExtensionsOnly, false, false, true, false, Extension::INTERNAL)); EXPECT_TRUE(builder.GetFetches().empty()); // Extensions with empty IDs should be rejected. builder.AddPendingExtension( - "", PendingExtensionInfo(GURL(), PendingExtensionInfo::EXTENSION, + "", PendingExtensionInfo(GURL(), &ShouldInstallExtensionsOnly, false, false, true, false, Extension::INTERNAL)); EXPECT_TRUE(builder.GetFetches().empty()); @@ -1004,7 +1014,7 @@ TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { // filled in. builder.AddPendingExtension( GenerateId("foo"), PendingExtensionInfo(GURL(), - PendingExtensionInfo::EXTENSION, + &ShouldInstallExtensionsOnly, false, false, true, false, Extension::INTERNAL)); std::vector<ManifestFetchData*> fetches = builder.GetFetches(); diff --git a/chrome/browser/sync/glue/extension_change_processor.cc b/chrome/browser/sync/glue/extension_change_processor.cc index 597db3f..fc28a62 100644 --- a/chrome/browser/sync/glue/extension_change_processor.cc +++ b/chrome/browser/sync/glue/extension_change_processor.cc @@ -61,13 +61,11 @@ void ExtensionChangeProcessor::Observe(NotificationType type, const UninstalledExtensionInfo* uninstalled_extension_info = Details<UninstalledExtensionInfo>(details).ptr(); CHECK(uninstalled_extension_info); - ExtensionType extension_type = - GetExtensionTypeFromUninstalledExtensionInfo( - *uninstalled_extension_info); - if (ContainsKey(traits_.allowed_extension_types, extension_type)) { + if (traits_.should_handle_extension_uninstall( + *uninstalled_extension_info)) { const std::string& id = uninstalled_extension_info->extension_id; VLOG(1) << "Removing server data for uninstalled extension " << id - << " of type " << extension_type; + << " of type " << uninstalled_extension_info->extension_type; RemoveServerData(traits_, id, profile_->GetProfileSyncService()); } } else { @@ -75,9 +73,7 @@ void ExtensionChangeProcessor::Observe(NotificationType type, CHECK(extension); VLOG(1) << "Updating server data for extension " << extension->id() << " (notification type = " << type.value << ")"; - // Ignore non-syncable extensions. - if (!IsExtensionValidAndSyncable( - *extension, traits_.allowed_extension_types)) { + if (!traits_.is_valid_and_syncable(*extension)) { return; } std::string error; diff --git a/chrome/browser/sync/glue/extension_sync.cc b/chrome/browser/sync/glue/extension_sync.cc index c14b593..83068df 100644 --- a/chrome/browser/sync/glue/extension_sync.cc +++ b/chrome/browser/sync/glue/extension_sync.cc @@ -13,6 +13,7 @@ #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/extension_data.h" #include "chrome/browser/sync/glue/extension_sync_traits.h" +#include "chrome/browser/sync/glue/extension_util.h" #include "chrome/browser/sync/profile_sync_service.h" namespace browser_sync { @@ -79,7 +80,7 @@ ExtensionData* SetOrCreateExtensionData( // extensions in |unsynced_extensions|. void ReadClientDataFromExtensionList( const ExtensionList& extensions, - const ExtensionTypeSet& allowed_extension_types, + IsValidAndSyncablePredicate is_valid_and_syncable, ExtensionService* extensions_service, std::set<std::string>* unsynced_extensions, ExtensionDataMap* extension_data_map) { @@ -87,7 +88,7 @@ void ReadClientDataFromExtensionList( it != extensions.end(); ++it) { CHECK(*it); const Extension& extension = **it; - if (IsExtensionValidAndSyncable(extension, allowed_extension_types)) { + if (is_valid_and_syncable(extension)) { sync_pb::ExtensionSpecifics client_specifics; GetExtensionSpecifics(extension, extensions_service->extension_prefs(), &client_specifics); @@ -109,21 +110,21 @@ void ReadClientDataFromExtensionList( // Simply calls ReadClientDataFromExtensionList() on the list of // enabled and disabled extensions from |extensions_service|. void SlurpClientData( - const ExtensionTypeSet& allowed_extension_types, + IsValidAndSyncablePredicate is_valid_and_syncable, ExtensionService* extensions_service, std::set<std::string>* unsynced_extensions, ExtensionDataMap* extension_data_map) { const ExtensionList* extensions = extensions_service->extensions(); CHECK(extensions); ReadClientDataFromExtensionList( - *extensions, allowed_extension_types, extensions_service, + *extensions, is_valid_and_syncable, extensions_service, unsynced_extensions, extension_data_map); const ExtensionList* disabled_extensions = extensions_service->disabled_extensions(); CHECK(disabled_extensions); ReadClientDataFromExtensionList( - *disabled_extensions, allowed_extension_types, extensions_service, + *disabled_extensions, is_valid_and_syncable, extensions_service, unsynced_extensions, extension_data_map); } @@ -198,7 +199,7 @@ bool SlurpExtensionData(const ExtensionSyncTraits& traits, // Read client-side data first so server data takes precedence, and // also so we have an idea of which extensions are unsyncable. SlurpClientData( - traits.allowed_extension_types, extensions_service, + traits.is_valid_and_syncable, extensions_service, &unsynced_extensions, extension_data_map); if (!SlurpServerData( @@ -258,8 +259,7 @@ bool UpdateServer( // function is called. Otherwise, the extension needs updating to a // new version. void TryUpdateClient( - const ExtensionTypeSet& allowed_extension_types, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + IsValidAndSyncablePredicate is_valid_and_syncable, ExtensionService* extensions_service, ExtensionData* extension_data) { DCHECK(!extension_data->NeedsUpdate(ExtensionData::SERVER)); @@ -270,7 +270,7 @@ void TryUpdateClient( const std::string& id = specifics.id(); const Extension* extension = extensions_service->GetExtensionById(id, true); if (extension) { - if (!IsExtensionValidAndSyncable(*extension, allowed_extension_types)) { + if (!is_valid_and_syncable(*extension)) { LOG(DFATAL) << "TryUpdateClient() called for non-syncable extension " << extension->id(); return; @@ -295,7 +295,7 @@ void TryUpdateClient( // permissions. extensions_service->AddPendingExtensionFromSync( id, update_url, - expected_crx_type, + is_valid_and_syncable, true, // install_silently specifics.enabled(), specifics.incognito_enabled()); @@ -350,8 +350,7 @@ bool FlushExtensionData(const ExtensionSyncTraits& traits, } DCHECK(!extension_data.NeedsUpdate(ExtensionData::SERVER)); if (extension_data.NeedsUpdate(ExtensionData::CLIENT)) { - TryUpdateClient(traits.allowed_extension_types, - traits.expected_crx_type, + TryUpdateClient(traits.is_valid_and_syncable, extensions_service, &extension_data); if (extension_data.NeedsUpdate(ExtensionData::CLIENT)) { should_nudge_extension_updater = true; @@ -372,8 +371,7 @@ bool UpdateServerData(const ExtensionSyncTraits& traits, ProfileSyncService* sync_service, std::string* error) { const std::string& id = extension.id(); - if (!IsExtensionValidAndSyncable(extension, - traits.allowed_extension_types)) { + if (!traits.is_valid_and_syncable(extension)) { *error = std::string("UpdateServerData() called for invalid or " "unsyncable extension ") + id; @@ -449,8 +447,7 @@ void UpdateClient(const ExtensionSyncTraits& traits, const Extension* extension = extensions_service->GetExtensionById(server_data.id(), true); if (extension) { - if (!IsExtensionValidAndSyncable( - *extension, traits.allowed_extension_types)) { + if (!traits.is_valid_and_syncable(*extension)) { LOG(WARNING) << "Ignoring server data for invalid or " << "non-syncable extension " << extension->id(); return; @@ -465,8 +462,7 @@ void UpdateClient(const ExtensionSyncTraits& traits, } DCHECK(!extension_data.NeedsUpdate(ExtensionData::SERVER)); if (extension_data.NeedsUpdate(ExtensionData::CLIENT)) { - TryUpdateClient(traits.allowed_extension_types, - traits.expected_crx_type, + TryUpdateClient(traits.is_valid_and_syncable, extensions_service, &extension_data); if (extension_data.NeedsUpdate(ExtensionData::CLIENT)) { NudgeExtensionUpdater(extensions_service); @@ -480,8 +476,7 @@ void RemoveFromClient(const ExtensionSyncTraits& traits, ExtensionService* extensions_service) { const Extension* extension = extensions_service->GetExtensionById(id, true); if (extension) { - if (IsExtensionValidAndSyncable(*extension, - traits.allowed_extension_types)) { + if (traits.is_valid_and_syncable(*extension)) { extensions_service->UninstallExtension(id, false); } else { LOG(WARNING) << "Ignoring server data for invalid or " diff --git a/chrome/browser/sync/glue/extension_sync_traits.cc b/chrome/browser/sync/glue/extension_sync_traits.cc index 74e291e..f45dabb 100644 --- a/chrome/browser/sync/glue/extension_sync_traits.cc +++ b/chrome/browser/sync/glue/extension_sync_traits.cc @@ -7,23 +7,26 @@ #include "base/string_piece.h" #include "base/utf_string_conversions.h" #include "chrome/browser/sync/engine/syncapi.h" +#include "chrome/browser/sync/glue/extension_util.h" #include "chrome/browser/sync/protocol/app_specifics.pb.h" #include "chrome/browser/sync/protocol/extension_specifics.pb.h" +#include "chrome/common/extensions/extension.h" namespace browser_sync { ExtensionSyncTraits::ExtensionSyncTraits( syncable::ModelType model_type, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + IsValidAndSyncablePredicate is_valid_and_syncable, + ShouldHandleExtensionUninstallPredicate + should_handle_extension_uninstall, const char* root_node_tag, - const ExtensionTypeSet& allowed_extension_types, ExtensionSpecificsGetter extension_specifics_getter, ExtensionSpecificsSetter extension_specifics_setter, ExtensionSpecificsEntityGetter extension_specifics_entity_getter) : model_type(model_type), - expected_crx_type(expected_crx_type), + is_valid_and_syncable(is_valid_and_syncable), + should_handle_extension_uninstall(should_handle_extension_uninstall), root_node_tag(root_node_tag), - allowed_extension_types(allowed_extension_types), extension_specifics_getter(extension_specifics_getter), extension_specifics_setter(extension_specifics_setter), extension_specifics_entity_getter(extension_specifics_entity_getter) {} @@ -54,16 +57,37 @@ bool GetExtensionSpecificsFromEntity( return true; } +bool IsSyncableExtension(Extension::Type type, const GURL& update_url) { + switch (type) { + case Extension::TYPE_EXTENSION: + return true; + case Extension::TYPE_USER_SCRIPT: + // We only want to sync user scripts with update URLs. + return !update_url.is_empty(); + default: + return false; + } +} + +bool IsValidAndSyncableExtension(const Extension& extension) { + return + IsExtensionValid(extension) && + IsSyncableExtension(extension.GetType(), extension.update_url()); +} + +bool IsExtensionUninstall( + const UninstalledExtensionInfo& uninstalled_extension_info) { + return IsSyncableExtension(uninstalled_extension_info.extension_type, + uninstalled_extension_info.update_url); +} + } // namespace ExtensionSyncTraits GetExtensionSyncTraits() { - ExtensionTypeSet allowed_extension_types; - allowed_extension_types.insert(EXTENSION); - allowed_extension_types.insert(UPDATEABLE_USER_SCRIPT); return ExtensionSyncTraits(syncable::EXTENSIONS, - PendingExtensionInfo::EXTENSION, + &IsValidAndSyncableExtension, + &IsExtensionUninstall, "google_chrome_extensions", - allowed_extension_types, &GetExtensionSpecifics, &SetExtensionSpecifics, &GetExtensionSpecificsFromEntity); @@ -96,15 +120,29 @@ bool GetExtensionSpecificsFromEntityOfApp( return true; } +bool IsSyncableApp(Extension::Type type) { + return + (type == Extension::TYPE_HOSTED_APP) || + (type == Extension::TYPE_PACKAGED_APP); +} + +bool IsValidAndSyncableApp( + const Extension& extension) { + return IsExtensionValid(extension) && IsSyncableApp(extension.GetType()); +} + +bool IsAppUninstall( + const UninstalledExtensionInfo& uninstalled_extension_info) { + return IsSyncableApp(uninstalled_extension_info.extension_type); +} + } // namespace ExtensionSyncTraits GetAppSyncTraits() { - ExtensionTypeSet allowed_extension_types; - allowed_extension_types.insert(APP); return ExtensionSyncTraits(syncable::APPS, - PendingExtensionInfo::APP, + &IsValidAndSyncableApp, + &IsAppUninstall, "google_chrome_apps", - allowed_extension_types, &GetExtensionSpecificsOfApp, &SetExtensionSpecificsOfApp, &GetExtensionSpecificsFromEntityOfApp); diff --git a/chrome/browser/sync/glue/extension_sync_traits.h b/chrome/browser/sync/glue/extension_sync_traits.h index 66bd5d6..cafc790 100644 --- a/chrome/browser/sync/glue/extension_sync_traits.h +++ b/chrome/browser/sync/glue/extension_sync_traits.h @@ -6,9 +6,10 @@ #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_TRAITS_H_ #pragma once -#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/sync/syncable/model_type.h" -#include "chrome/browser/sync/glue/extension_util.h" + +class Extension; +struct UninstalledExtensionInfo; namespace sync_api { class BaseNode; @@ -16,11 +17,17 @@ class WriteNode; } // namespace sync_api namespace sync_pb { +class EntitySpecifics; class ExtensionSpecifics; } // namespace sync_pb namespace browser_sync { +typedef bool (*IsValidAndSyncablePredicate)(const Extension&); + +typedef bool (*ShouldHandleExtensionUninstallPredicate)( + const UninstalledExtensionInfo&); + // ExtensionSpecificsGetter : BaseNode -> ExtensionSpecifics typedef const sync_pb::ExtensionSpecifics& (*ExtensionSpecificsGetter)( const sync_api::BaseNode&); @@ -41,9 +48,10 @@ typedef bool (*ExtensionSpecificsEntityGetter)( struct ExtensionSyncTraits { ExtensionSyncTraits( syncable::ModelType model_type, - PendingExtensionInfo::ExpectedCrxType expected_crx_type, + IsValidAndSyncablePredicate is_valid_and_syncable, + ShouldHandleExtensionUninstallPredicate + should_handle_extension_uninstall, const char* root_node_tag, - const ExtensionTypeSet& allowed_extension_types, ExtensionSpecificsGetter extension_specifics_getter, ExtensionSpecificsSetter extension_specifics_setter, ExtensionSpecificsEntityGetter extension_specifics_entity_getter); @@ -51,13 +59,14 @@ struct ExtensionSyncTraits { // The sync type for the data type. const syncable::ModelType model_type; - // The ExpectedCrxType to use for the data type. - PendingExtensionInfo::ExpectedCrxType expected_crx_type; + // A checker to make sure that the downloaded extension is valid and + // syncable. + const IsValidAndSyncablePredicate is_valid_and_syncable; + // A checker to know which extension uninstall events to handle. + const ShouldHandleExtensionUninstallPredicate + should_handle_extension_uninstall; // The tag with which the top-level data type node is marked. const char* const root_node_tag; - // The set of allowed ExtensionTypes (not just a single one since - // some data types handle more than one). - const ExtensionTypeSet allowed_extension_types; // The function that retrieves a ExtensionSpecifics reference (which // may be embedded in another specifics object) from a sync node. const ExtensionSpecificsGetter extension_specifics_getter; diff --git a/chrome/browser/sync/glue/extension_util.cc b/chrome/browser/sync/glue/extension_util.cc index 1ea144a..4713c92 100644 --- a/chrome/browser/sync/glue/extension_util.cc +++ b/chrome/browser/sync/glue/extension_util.cc @@ -19,47 +19,6 @@ namespace browser_sync { -ExtensionType GetExtensionType(const Extension& extension) { - if (extension.is_theme()) { - return THEME; - } - - if (extension.is_app()) { - return APP; - } - - if (extension.converted_from_user_script()) { - if (extension.update_url().is_empty()) { - return LOCAL_USER_SCRIPT; - } - return UPDATEABLE_USER_SCRIPT; - } - - // Otherwise, we just have a regular extension. - return EXTENSION; -} - -// Keep this in sync with the above function. -// TODO(akalin): Or just hurry up and remove this! -ExtensionType GetExtensionTypeFromUninstalledExtensionInfo( - const UninstalledExtensionInfo& uninstalled_extension_info) { - if (uninstalled_extension_info.is_theme) { - return THEME; - } - - if (uninstalled_extension_info.is_app) { - return APP; - } - - if (uninstalled_extension_info.converted_from_user_script) { - if (uninstalled_extension_info.update_url.is_empty()) { - return LOCAL_USER_SCRIPT; - } - return UPDATEABLE_USER_SCRIPT; - } - return EXTENSION; -} - bool IsExtensionValid(const Extension& extension) { // TODO(akalin): Figure out if we need to allow some other types. if (extension.location() != Extension::INTERNAL) { @@ -88,13 +47,6 @@ bool IsExtensionValid(const Extension& extension) { return true; } -bool IsExtensionValidAndSyncable(const Extension& extension, - const ExtensionTypeSet& allowed_types) { - return - IsExtensionValid(extension) && - ContainsKey(allowed_types, GetExtensionType(extension)); -} - std::string ExtensionSpecificsToString( const sync_pb::ExtensionSpecifics& specifics) { std::stringstream ss; diff --git a/chrome/browser/sync/glue/extension_util.h b/chrome/browser/sync/glue/extension_util.h index e87d98c..e908650 100644 --- a/chrome/browser/sync/glue/extension_util.h +++ b/chrome/browser/sync/glue/extension_util.h @@ -9,12 +9,10 @@ // This file contains some low-level utility functions used by // extensions sync. -#include <set> #include <string> class Extension; class ExtensionPrefs; -class ExtensionTypeSet; class ExtensionService; struct UninstalledExtensionInfo; @@ -24,38 +22,9 @@ class ExtensionSpecifics; namespace browser_sync { -enum ExtensionType { - THEME, - EXTENSION, - // A converted user script that does not have an update URL. - LOCAL_USER_SCRIPT, - // A converted user script that has an update URL. (We don't have a - // similar distinction for "regular" extensions as an empty update - // URL is interpreted to mean the default update URL [i.e., the - // extensions gallery].) - UPDATEABLE_USER_SCRIPT, - APP, -}; - -typedef std::set<ExtensionType> ExtensionTypeSet; - -// Returns the type of the given extension. -// -// TODO(akalin): Might be useful to move this into extension.cc. -ExtensionType GetExtensionType(const Extension& extension); - -// TODO(akalin): Remove this once we unify ExtensionType and simply -// have an ExtensionType member in UninstalledExtensionInfo. -ExtensionType GetExtensionTypeFromUninstalledExtensionInfo( - const UninstalledExtensionInfo& uninstalled_extension_info); - // Returns whether or not the given extension is one we want to sync. bool IsExtensionValid(const Extension& extension); -// Returns whether or not the given extension is one we want to sync. -bool IsExtensionValidAndSyncable(const Extension& extension, - const ExtensionTypeSet& allowed_types); - // Stringifies the given ExtensionSpecifics. std::string ExtensionSpecificsToString( const sync_pb::ExtensionSpecifics& specifics); diff --git a/chrome/browser/sync/glue/extension_util_unittest.cc b/chrome/browser/sync/glue/extension_util_unittest.cc index 1a375ff..946ca5a 100644 --- a/chrome/browser/sync/glue/extension_util_unittest.cc +++ b/chrome/browser/sync/glue/extension_util_unittest.cc @@ -83,45 +83,6 @@ scoped_refptr<Extension> MakeExtension( return extension; } -TEST_F(ExtensionUtilTest, GetExtensionType) { - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), GURL(), false, - Extension::INTERNAL, 0, file_path)); - EXPECT_EQ(EXTENSION, GetExtensionType(*extension)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(true, GURL(), GURL(), false, - Extension::INTERNAL, 0, file_path)); - EXPECT_EQ(THEME, GetExtensionType(*extension)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), GURL(), true, - Extension::INTERNAL, 0, file_path)); - EXPECT_EQ(LOCAL_USER_SCRIPT, GetExtensionType(*extension)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL("http://www.google.com"), GURL(), true, - Extension::INTERNAL, 0, file_path)); - EXPECT_EQ(UPDATEABLE_USER_SCRIPT, GetExtensionType(*extension)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), - GURL("http://www.google.com"), false, - Extension::INTERNAL, 0, file_path)); - EXPECT_EQ(APP, GetExtensionType(*extension)); - } -} - TEST_F(ExtensionUtilTest, IsExtensionValid) { { FilePath file_path(kExtensionFilePath); @@ -190,46 +151,6 @@ TEST_F(ExtensionUtilTest, IsExtensionValid) { } } -TEST_F(ExtensionUtilTest, IsExtensionValidAndSyncable) { - ExtensionTypeSet allowed_extension_types; - allowed_extension_types.insert(EXTENSION); - allowed_extension_types.insert(APP); - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), GURL(), false, - Extension::INTERNAL, 0, file_path)); - EXPECT_TRUE(IsExtensionValidAndSyncable( - *extension, allowed_extension_types)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), - GURL("http://www.google.com"), false, - Extension::INTERNAL, 0, file_path)); - EXPECT_TRUE(IsExtensionValidAndSyncable( - *extension, allowed_extension_types)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), GURL(), true, - Extension::INTERNAL, 0, file_path)); - EXPECT_FALSE(IsExtensionValidAndSyncable( - *extension, allowed_extension_types)); - } - { - FilePath file_path(kExtensionFilePath); - scoped_refptr<Extension> extension( - MakeExtension(false, GURL(), GURL(), false, - Extension::EXTERNAL_PREF, 0, file_path)); - EXPECT_FALSE(IsExtensionValidAndSyncable( - *extension, allowed_extension_types)); - } -} - - TEST_F(ExtensionUtilTest, IsExtensionSpecificsUnset) { { sync_pb::ExtensionSpecifics specifics; diff --git a/chrome/browser/sync/glue/theme_util.cc b/chrome/browser/sync/glue/theme_util.cc index a0a5da2..c2d70ca 100644 --- a/chrome/browser/sync/glue/theme_util.cc +++ b/chrome/browser/sync/glue/theme_util.cc @@ -75,6 +75,14 @@ bool AreThemeSpecificsEqualHelper( } } +namespace { + +bool IsTheme(const Extension& extension) { + return extension.is_theme(); +} + +} // namespace + void SetCurrentThemeFromThemeSpecifics( const sync_pb::ThemeSpecifics& theme_specifics, Profile* profile) { @@ -125,8 +133,6 @@ void SetCurrentThemeFromThemeSpecifics( // No extension with this id exists -- we must install it; we do // so by adding it as a pending extension and then triggering an // auto-update cycle. - const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = - PendingExtensionInfo::THEME; // Themes don't need to install silently as they just pop up an // informational dialog after installation instead of a // confirmation dialog. @@ -134,7 +140,7 @@ void SetCurrentThemeFromThemeSpecifics( const bool kEnableOnInstall = true; const bool kEnableIncognitoOnInstall = false; extensions_service->AddPendingExtensionFromSync( - id, update_url, kExpectedCrxType, + id, update_url, &IsTheme, kInstallSilently, kEnableOnInstall, kEnableIncognitoOnInstall); ExtensionUpdater* extension_updater = extensions_service->updater(); // Auto-updates should now be on always (see the construction of diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 56e0683..f365ac6 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -469,7 +469,7 @@ std::string Extension::GenerateIdForPath(const FilePath& path) { return id; } -Extension::HistogramType Extension::GetHistogramType() const { +Extension::Type Extension::GetType() const { if (is_theme()) return TYPE_THEME; if (converted_from_user_script()) @@ -2255,9 +2255,7 @@ UninstalledExtensionInfo::UninstalledExtensionInfo( const Extension& extension) : extension_id(extension.id()), extension_api_permissions(extension.api_permissions()), - is_theme(extension.is_theme()), - is_app(extension.is_app()), - converted_from_user_script(extension.converted_from_user_script()), + extension_type(extension.GetType()), update_url(extension.update_url()) {} UninstalledExtensionInfo::~UninstalledExtensionInfo() {} diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 8fa35d5..4d680ef 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -83,9 +83,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> { EXTENSION_ICON_BITTY = 16, }; - // Type used for UMA_HISTOGRAM_ENUMERATION about extensions. - // Do not change the order of entries or remove entries in this list. - enum HistogramType { + // Do not change the order of entries or remove entries in this list + // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. + enum Type { TYPE_UNKNOWN = 0, TYPE_EXTENSION, TYPE_THEME, @@ -227,8 +227,8 @@ class Extension : public base::RefCountedThreadSafe<Extension> { IsExternalLocation(location); } - // See HistogramType definition above. - HistogramType GetHistogramType() const; + // See Type definition above. + Type GetType() const; // Returns an absolute url to a resource inside of an extension. The // |extension_url| argument should be the url() from an Extension object. The @@ -730,11 +730,7 @@ struct UninstalledExtensionInfo { std::string extension_id; std::set<std::string> extension_api_permissions; - // TODO(akalin): Once we have a unified ExtensionType, replace the - // below member variables with a member of that type. - bool is_theme; - bool is_app; - bool converted_from_user_script; + Extension::Type extension_type; GURL update_url; }; |