Commit 30e190f8 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Fixed sync regression for ephemeral apps

r272157 introduced a regression where ephemeral apps would be synced
when Chrome restarts, causing them to be installed.

BUG=374018

Review URL: https://codereview.chromium.org/295203002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272855 0039d316-1c4b-4281-b951-d872f2087c98
parent d26b905c
......@@ -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/browser/app_sorting.h"
#include "extensions/common/extension.h"
......@@ -141,13 +143,15 @@ std::vector<AppSyncData> AppSyncBundle::GetPendingData() const {
void AppSyncBundle::GetAppSyncDataListHelper(
const ExtensionSet& extensions,
std::vector<AppSyncData>* 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 app data for this app, then this
// version is out of date. We'll sync back the version we got from
// sync.
if (IsSyncing() && sync_helper::IsSyncableApp(&extension) &&
if (IsSyncing() && util::ShouldSyncApp(&extension, profile) &&
!HasPendingExtensionId(extension.id())) {
sync_data_list->push_back(extension_sync_service_->GetAppSyncData(
extension));
......
......@@ -58,11 +58,6 @@ void OnWebApplicationInfoLoaded(
CreateOrUpdateBookmarkApp(extension_service.get(), synced_info);
}
bool ShouldSyncApp(const Extension* extension, Profile* profile) {
return extensions::sync_helper::IsSyncableApp(extension) &&
!extensions::util::IsEphemeralApp(extension->id(), profile);
}
} // namespace
ExtensionSyncService::ExtensionSyncService(Profile* profile,
......@@ -103,7 +98,7 @@ syncer::SyncChange ExtensionSyncService::PrepareToSyncUninstallExtension(
// "back from the dead" style bugs, because sync will add-back the extension
// that was uninstalled here when MergeDataAndStartSyncing is called.
// See crbug.com/256795.
if (ShouldSyncApp(extension, profile_)) {
if (extensions::util::ShouldSyncApp(extension, profile_)) {
if (app_sync_bundle_.IsSyncing())
return app_sync_bundle_.CreateSyncChangeToDelete(extension);
else if (extensions_ready && !flare_.is_null())
......@@ -134,7 +129,7 @@ void ExtensionSyncService::SyncEnableExtension(
const extensions::Extension& extension) {
// Syncing may not have started yet, so handle pending enables.
if (ShouldSyncApp(&extension, profile_))
if (extensions::util::ShouldSyncApp(&extension, profile_))
pending_app_enables_.OnExtensionEnabled(extension.id());
if (extensions::sync_helper::IsSyncableExtension(&extension))
......@@ -147,7 +142,7 @@ void ExtensionSyncService::SyncDisableExtension(
const extensions::Extension& extension) {
// Syncing may not have started yet, so handle pending enables.
if (ShouldSyncApp(&extension, profile_))
if (extensions::util::ShouldSyncApp(&extension, profile_))
pending_app_enables_.OnExtensionDisabled(extension.id());
if (extensions::sync_helper::IsSyncableExtension(&extension))
......@@ -538,7 +533,7 @@ bool ExtensionSyncService::ProcessExtensionSyncDataHelper(
void ExtensionSyncService::SyncExtensionChangeIfNeeded(
const Extension& extension) {
if (ShouldSyncApp(&extension, profile_)) {
if (extensions::util::ShouldSyncApp(&extension, profile_)) {
if (app_sync_bundle_.IsSyncing())
app_sync_bundle_.SyncChangeIfNeeded(extension);
else if (extension_service_->is_ready() && !flare_.is_null())
......
......@@ -112,6 +112,8 @@ class ExtensionSyncService : public syncer::SyncableService,
// sync_start_util for more.
void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare);
Profile* profile() { return profile_; }
private:
// Return true if the sync type of |extension| matches |type|.
bool IsCorrectSyncType(const extensions::Extension& extension,
......
......@@ -18,6 +18,7 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/manifest.h"
......@@ -153,6 +154,11 @@ bool IsAppLaunchableWithoutEnabling(const std::string& extension_id,
extension_id, ExtensionRegistry::ENABLED) != NULL;
}
bool ShouldSyncApp(const Extension* app, content::BrowserContext* context) {
return sync_helper::IsSyncableApp(app) &&
!util::IsEphemeralApp(app->id(), context);
}
bool IsExtensionIdle(const std::string& extension_id,
content::BrowserContext* context) {
ProcessManager* process_manager =
......
......@@ -69,6 +69,9 @@ bool IsAppLaunchable(const std::string& extension_id,
bool IsAppLaunchableWithoutEnabling(const std::string& extension_id,
content::BrowserContext* context);
// Returns true if |app| should be synced.
bool ShouldSyncApp(const Extension* app, content::BrowserContext* context);
// Returns true if |extension_id| is idle and it is safe to perform actions such
// as updating.
bool IsExtensionIdle(const std::string& extension_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment