diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-14 20:28:05 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-14 20:28:05 +0000 |
commit | 658eae5c45ea3e7f99741d84962434ecc782a038 (patch) | |
tree | 21fea6d0ea56bd04b4348b0e327bec6bacde4af7 /chrome/browser | |
parent | 986dd0ea53fe19d2ff9ffe7a41b71c3d8bfbd926 (diff) | |
download | chromium_src-658eae5c45ea3e7f99741d84962434ecc782a038.zip chromium_src-658eae5c45ea3e7f99741d84962434ecc782a038.tar.gz chromium_src-658eae5c45ea3e7f99741d84962434ecc782a038.tar.bz2 |
Add a do_not_sync pref to ExtensionPrefs.
Split from https://codereview.chromium.org/308003005/ for extensions
system changes that allows to install a none syncable Extension.
- Add a do_not_sync pref to ExtensionPrefs;
- Add a kInstallFlagDoNotSync that CrxInstaller uses to initialize the pref;
- Update util::ShouldSyncApp and add ShouldSyncExtension to use the pref to skip sync in ExtensionSyncService;
BUG=358791
Review URL: https://codereview.chromium.org/323843003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277269 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/crx_installer.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/crx_installer_browsertest.cc | 31 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_sync_bundle.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_sync_service.cc | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_util.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_util.h | 4 |
7 files changed, 57 insertions, 16 deletions
diff --git a/chrome/browser/extensions/crx_installer.h b/chrome/browser/extensions/crx_installer.h index 93659c5..fe34b2f 100644 --- a/chrome/browser/extensions/crx_installer.h +++ b/chrome/browser/extensions/crx_installer.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ #include <string> +#include <vector> #include "base/compiler_specific.h" #include "base/files/file_path.h" @@ -196,6 +197,13 @@ class CrxInstaller install_flags_ &= ~kInstallFlagIsEphemeral; } + void set_install_flag(int flag, bool val) { + if (val) + install_flags_ |= flag; + else + install_flags_ &= ~flag; + } + bool did_handle_successfully() const { return did_handle_successfully_; } Profile* profile() { return installer_.profile(); } diff --git a/chrome/browser/extensions/crx_installer_browsertest.cc b/chrome/browser/extensions/crx_installer_browsertest.cc index 375b57e..7c583a3 100644 --- a/chrome/browser/extensions/crx_installer_browsertest.cc +++ b/chrome/browser/extensions/crx_installer_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -50,8 +51,7 @@ class MockInstallPrompt; // MockInstallPrompt. We create the MockInstallPrompt but need to pass // ownership of it to CrxInstaller, so it isn't safe to hang this data on // MockInstallPrompt itself becuase we can't guarantee it's lifetime. -class MockPromptProxy : - public base::RefCountedThreadSafe<MockPromptProxy> { +class MockPromptProxy : public base::RefCountedThreadSafe<MockPromptProxy> { public: explicit MockPromptProxy(content::WebContents* web_contents); @@ -116,10 +116,8 @@ class MockInstallPrompt : public ExtensionInstallPrompt { scoped_refptr<MockPromptProxy> proxy_; }; - -MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) : - web_contents_(web_contents), - confirmation_requested_(false) { +MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) + : web_contents_(web_contents), confirmation_requested_(false) { } MockPromptProxy::~MockPromptProxy() {} @@ -366,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); crx_path = crx_path.AppendASCII("theme_hidpi.crx"); - ASSERT_TRUE(InstallExtension(crx_path,1)); + ASSERT_TRUE(InstallExtension(crx_path, 1)); const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); ExtensionService* service = extensions::ExtensionSystem::Get( @@ -428,7 +426,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ASSERT_EQ("1.0", extension->version()->GetString()); // Make the extension idle again by closing the popup. This should not trigger - //the delayed install. + // the delayed install. content::RenderProcessHostWatcher terminated_observer( extension_host->render_process_host(), content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); @@ -535,4 +533,21 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallToSharedLocation) { } #endif +IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) { + ExtensionService* service = extensions::ExtensionSystem::Get( + browser()->profile())->extension_service(); + scoped_refptr<CrxInstaller> crx_installer( + CrxInstaller::CreateSilent(service)); + crx_installer->set_install_flag(kInstallFlagDoNotSync, true); + crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); + EXPECT_TRUE(WaitForCrxInstallerDone()); + ASSERT_TRUE(crx_installer->extension()); + + const ExtensionPrefs* extension_prefs = + ExtensionPrefs::Get(browser()->profile()); + EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id())); + EXPECT_FALSE(extensions::util::ShouldSyncApp(crx_installer->extension(), + browser()->profile())); +} + } // namespace extensions diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index f3fbae3..d9a5370 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -582,8 +582,11 @@ bool ExtensionService::UpdateExtension(const std::string& id, if (extension && extension->was_installed_by_oem()) creation_flags |= Extension::WAS_INSTALLED_BY_OEM; - if (extension) + if (extension) { installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id)); + installer->set_install_flag(extensions::kInstallFlagDoNotSync, + extension_prefs_->DoNotSync(id)); + } installer->set_creation_flags(creation_flags); diff --git a/chrome/browser/extensions/extension_sync_bundle.cc b/chrome/browser/extensions/extension_sync_bundle.cc index facac22..2333ffa 100644 --- a/chrome/browser/extensions/extension_sync_bundle.cc +++ b/chrome/browser/extensions/extension_sync_bundle.cc @@ -6,6 +6,8 @@ #include "base/location.h" #include "chrome/browser/extensions/extension_sync_service.h" +#include "chrome/browser/extensions/extension_util.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/sync_helper.h" #include "extensions/common/extension.h" #include "extensions/common/extension_set.h" @@ -142,13 +144,15 @@ std::vector<ExtensionSyncData> ExtensionSyncBundle::GetPendingData() const { void ExtensionSyncBundle::GetExtensionSyncDataListHelper( const ExtensionSet& extensions, std::vector<ExtensionSyncData>* sync_data_list) const { + Profile* profile = extension_sync_service_->profile(); + for (ExtensionSet::const_iterator it = extensions.begin(); it != extensions.end(); ++it) { const Extension& extension = *it->get(); // If we have pending extension data for this extension, then this // version is out of date. We'll sync back the version we got from // sync. - if (IsSyncing() && sync_helper::IsSyncableExtension(&extension) && + if (IsSyncing() && util::ShouldSyncExtension(&extension, profile) && !HasPendingExtensionId(extension.id())) { sync_data_list->push_back( extension_sync_service_->GetExtensionSyncData(extension)); diff --git a/chrome/browser/extensions/extension_sync_service.cc b/chrome/browser/extensions/extension_sync_service.cc index f978667..b125e72 100644 --- a/chrome/browser/extensions/extension_sync_service.cc +++ b/chrome/browser/extensions/extension_sync_service.cc @@ -132,7 +132,7 @@ void ExtensionSyncService::SyncEnableExtension( if (extensions::util::ShouldSyncApp(&extension, profile_)) pending_app_enables_.OnExtensionEnabled(extension.id()); - if (extensions::sync_helper::IsSyncableExtension(&extension)) + if (extensions::util::ShouldSyncExtension(&extension, profile_)) pending_extension_enables_.OnExtensionEnabled(extension.id()); SyncExtensionChangeIfNeeded(extension); @@ -145,7 +145,7 @@ void ExtensionSyncService::SyncDisableExtension( if (extensions::util::ShouldSyncApp(&extension, profile_)) pending_app_enables_.OnExtensionDisabled(extension.id()); - if (extensions::sync_helper::IsSyncableExtension(&extension)) + if (extensions::util::ShouldSyncExtension(&extension, profile_)) pending_extension_enables_.OnExtensionDisabled(extension.id()); SyncExtensionChangeIfNeeded(extension); @@ -474,9 +474,9 @@ bool ExtensionSyncService::ProcessExtensionSyncDataHelper( // what the disable reason is, so set it to that directly. Note that when // CheckPermissionsIncrease runs, it might still add permissions increase // as a disable reason for the extension. - if (extension_sync_data.enabled()) + if (extension_sync_data.enabled()) { extension_service_->EnableExtension(id); - else if (!IsPendingEnable(id)) { + } else if (!IsPendingEnable(id)) { if (extension_sync_data.remote_install()) { extension_service_->DisableExtension(id, Extension::DISABLE_REMOTE_INSTALL); @@ -546,7 +546,7 @@ void ExtensionSyncService::SyncExtensionChangeIfNeeded( app_sync_bundle_.SyncChangeIfNeeded(extension); else if (extension_service_->is_ready() && !flare_.is_null()) flare_.Run(syncer::APPS); - } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { + } else if (extensions::util::ShouldSyncExtension(&extension, profile_)) { if (extension_sync_bundle_.IsSyncing()) extension_sync_bundle_.SyncChangeIfNeeded(extension); else if (extension_service_->is_ready() && !flare_.is_null()) diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc index dd28913..45dc740 100644 --- a/chrome/browser/extensions/extension_util.cc +++ b/chrome/browser/extensions/extension_util.cc @@ -180,9 +180,16 @@ bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, extension_id, ExtensionRegistry::ENABLED) != NULL; } +bool ShouldSyncExtension(const Extension* extension, + content::BrowserContext* context) { + return sync_helper::IsSyncableExtension(extension) && + !ExtensionPrefs::Get(context)->DoNotSync(extension->id()); +} + bool ShouldSyncApp(const Extension* app, content::BrowserContext* context) { return sync_helper::IsSyncableApp(app) && - !util::IsEphemeralApp(app->id(), context); + !util::IsEphemeralApp(app->id(), context) && + !ExtensionPrefs::Get(context)->DoNotSync(app->id()); } bool IsExtensionIdle(const std::string& extension_id, diff --git a/chrome/browser/extensions/extension_util.h b/chrome/browser/extensions/extension_util.h index 5cf2892..452206e 100644 --- a/chrome/browser/extensions/extension_util.h +++ b/chrome/browser/extensions/extension_util.h @@ -85,6 +85,10 @@ bool IsAppLaunchable(const std::string& extension_id, bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, content::BrowserContext* context); +// Returns true if |extension| should be synced. +bool ShouldSyncExtension(const Extension* extension, + content::BrowserContext* context); + // Returns true if |app| should be synced. bool ShouldSyncApp(const Extension* app, content::BrowserContext* context); |