Commit e81d6f1b authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

app_list: Remove Drive app in launcher support

- Remove code that shows connected Drive apps in launcher;
- Update AppListSyncableService to remove sync data for those apps;

Bug: 794724
Change-Id: I4e16df1d1e7dc216114174eae21cfac1b0eec189
Reviewed-on: https://chromium-review.googlesource.com/828026Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524468}
parent c4dd1051
include_rules = [
"+components/drive",
]
benwells@chromium.org
calamity@chromium.org
stevenjb@chromium.org
tapted@chromium.org
xiyuan@chromium.org
# Drive API
kinaba@chromium.org
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/drive/drive_app_converter.h"
#include <stddef.h>
#include <algorithm>
#include <set>
#include <utility>
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chrome/browser/image_decoder.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/resource_request.h"
#include "content/public/common/simple_url_loader.h"
#include "content/public/common/url_loader_factory.mojom.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "net/base/load_flags.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "third_party/skia/include/core/SkBitmap.h"
using content::BrowserThread;
// IconFetcher downloads |icon_url| using |converter|'s profile. The icon
// url is passed from a DriveAppInfo and should follow icon url definition
// in Drive API:
// https://developers.google.com/drive/v2/reference/apps#resource
// Each icon url represents a single image associated with a certain size.
class DriveAppConverter::IconFetcher : public ImageDecoder::ImageRequest {
public:
IconFetcher(DriveAppConverter* converter,
const GURL& icon_url,
int expected_size)
: converter_(converter),
icon_url_(icon_url),
expected_size_(expected_size) {}
~IconFetcher() override {}
void Start() {
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("launcher_drive_app_icon_fetch", R"(
semantics {
sender: "Google Drive App"
description:
"Drive allows user to add apps to handle their data such as "
"Lucidchart etc. DriveAppConverter wraps those apps as a "
"bookmark app. This service fetches the icon of a user's "
"connected Drive app."
trigger:
"When Chrome detects that a Drive app is connected to a user's "
"account"
data:
"URL of the required icon to fetch. No user information is sent."
destination: WEBSITE
}
policy {
cookies_allowed: YES
cookies_store: "user"
setting: "Unconditionally enabled on ChromeOS"
policy_exception_justification:
"Not implemented, considered not useful."
})");
auto resource_request = std::make_unique<content::ResourceRequest>();
resource_request->url = icon_url_;
resource_request->load_flags = net::LOAD_DO_NOT_SAVE_COOKIES;
simple_loader_ = content::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
content::mojom::URLLoaderFactory* loader_factory =
content::BrowserContext::GetDefaultStoragePartition(
converter_->profile_)
->GetURLLoaderFactoryForBrowserProcess();
simple_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
loader_factory,
base::BindOnce(&DriveAppConverter::IconFetcher::OnCompleteCallback,
base::Unretained(this)));
}
const GURL& icon_url() const { return icon_url_; }
const SkBitmap& icon() const { return icon_; }
private:
void OnCompleteCallback(std::unique_ptr<std::string> response_body) {
if (!response_body) {
converter_->OnIconFetchComplete(this);
return;
}
// Call start to begin decoding. The ImageDecoder will call OnImageDecoded
// with the data when it is done.
ImageDecoder::Start(this, *response_body);
}
// ImageDecoder::ImageRequest overrides:
void OnImageDecoded(const SkBitmap& decoded_image) override {
if (decoded_image.width() == expected_size_)
icon_ = decoded_image;
converter_->OnIconFetchComplete(this);
}
void OnDecodeImageFailed() override { converter_->OnIconFetchComplete(this); }
DriveAppConverter* converter_;
const GURL icon_url_;
const int expected_size_;
std::unique_ptr<content::SimpleURLLoader> simple_loader_;
SkBitmap icon_;
DISALLOW_COPY_AND_ASSIGN(IconFetcher);
};
DriveAppConverter::DriveAppConverter(Profile* profile,
const drive::DriveAppInfo& drive_app_info,
const FinishedCallback& finished_callback)
: profile_(profile),
drive_app_info_(drive_app_info),
extension_(NULL),
is_new_install_(false),
finished_callback_(finished_callback) {
DCHECK(profile_);
}
DriveAppConverter::~DriveAppConverter() {
PostInstallCleanUp();
}
void DriveAppConverter::Start() {
DCHECK(!IsStarted());
if (drive_app_info_.app_name.empty() ||
!drive_app_info_.create_url.is_valid()) {
base::ResetAndReturn(&finished_callback_).Run(this, false);
return;
}
VLOG(1) << "Start installing drive app: ID " << drive_app_info_.app_id
<< ", product ID " << drive_app_info_.product_id << ", name "
<< drive_app_info_.app_name;
web_app_.title = base::UTF8ToUTF16(drive_app_info_.app_name);
web_app_.app_url = drive_app_info_.create_url;
std::set<int> pending_sizes;
for (size_t i = 0; i < drive_app_info_.app_icons.size(); ++i) {
const int icon_size = drive_app_info_.app_icons[i].first;
if (pending_sizes.find(icon_size) != pending_sizes.end())
continue;
pending_sizes.insert(icon_size);
const GURL& icon_url = drive_app_info_.app_icons[i].second;
fetchers_.push_back(
base::MakeUnique<IconFetcher>(this, icon_url, icon_size));
fetchers_.back()->Start();
}
if (fetchers_.empty())
StartInstall();
}
bool DriveAppConverter::IsStarted() const {
return !fetchers_.empty() || crx_installer_.get();
}
bool DriveAppConverter::IsInstalling(const std::string& app_id) const {
return crx_installer_.get() && crx_installer_->extension() &&
crx_installer_->extension()->id() == app_id;
}
void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) {
const SkBitmap& icon = fetcher->icon();
if (!icon.empty() && icon.width() != 0) {
WebApplicationInfo::IconInfo icon_info;
icon_info.url = fetcher->icon_url();
icon_info.data = icon;
icon_info.width = icon.width();
icon_info.height = icon.height();
web_app_.icons.push_back(icon_info);
}
fetchers_.erase(
std::find_if(fetchers_.begin(), fetchers_.end(),
[fetcher](const std::unique_ptr<IconFetcher>& item) {
return item.get() == fetcher;
}));
if (fetchers_.empty())
StartInstall();
}
void DriveAppConverter::StartInstall() {
DCHECK(!crx_installer_.get());
crx_installer_ = extensions::CrxInstaller::CreateSilent(
extensions::ExtensionSystem::Get(profile_)->extension_service());
// The converted url app should not be syncable. Drive apps go with the user's
// account and url apps will be created when needed. Syncing those apps could
// hit an edge case where the synced url apps become orphans when the user has
// corresponding chrome apps.
crx_installer_->set_do_not_sync(true);
extensions::InstallTracker::Get(profile_)->AddObserver(this);
crx_installer_->InstallWebApp(web_app_);
}
void DriveAppConverter::PostInstallCleanUp() {
if (!crx_installer_.get())
return;
extensions::InstallTracker::Get(profile_)->RemoveObserver(this);
crx_installer_ = NULL;
}
void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id,
bool success) {
if (!crx_installer_->extension() ||
crx_installer_->extension()->id() != extension_id) {
return;
}
extension_ = crx_installer_->extension();
is_new_install_ = success && !crx_installer_->current_version().IsValid();
PostInstallCleanUp();
base::ResetAndReturn(&finished_callback_).Run(this, success);
// |finished_callback_| could delete this.
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/common/web_application_info.h"
#include "components/drive/drive_app_registry.h"
class Profile;
namespace extensions {
class CrxInstaller;
class Extension;
}
// DriveAppConverter creates and installs a local URL app for the given
// DriveAppInfo into the given profile.
class DriveAppConverter : public extensions::InstallObserver {
public:
typedef base::Callback<void(const DriveAppConverter*, bool success)>
FinishedCallback;
DriveAppConverter(Profile* profile,
const drive::DriveAppInfo& drive_app_info,
const FinishedCallback& finished_callback);
~DriveAppConverter() override;
void Start();
bool IsStarted() const;
bool IsInstalling(const std::string& app_id) const;
const drive::DriveAppInfo& drive_app_info() const { return drive_app_info_; }
const extensions::Extension* extension() const { return extension_; }
bool is_new_install() const { return is_new_install_; }
private:
class IconFetcher;
// Callbacks from IconFetcher.
void OnIconFetchComplete(const IconFetcher* fetcher);
void StartInstall();
void PostInstallCleanUp();
// extensions::InstallObserver:
void OnFinishCrxInstall(const std::string& extension_id,
bool success) override;
Profile* profile_;
const drive::DriveAppInfo drive_app_info_;
WebApplicationInfo web_app_;
const extensions::Extension* extension_;
bool is_new_install_;
std::vector<std::unique_ptr<IconFetcher>> fetchers_;
scoped_refptr<extensions::CrxInstaller> crx_installer_;
FinishedCallback finished_callback_;
DISALLOW_COPY_AND_ASSIGN(DriveAppConverter);
};
#endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_CONVERTER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/drive/drive_app_converter.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/version.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
using extensions::AppLaunchInfo;
using extensions::Extension;
using extensions::ExtensionRegistry;
namespace {
const char kAppName[] = "Test drive app";
const char kAppUrl[] = "http://foobar.com/drive_app";
} // namespace
class DriveAppConverterTest : public ExtensionBrowserTest {
public:
DriveAppConverterTest() {}
~DriveAppConverterTest() override {}
// ExtensionBrowserTest:
void SetUpOnMainThread() override {
ExtensionBrowserTest::SetUpOnMainThread();
base::FilePath test_data_dir;
PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
ASSERT_TRUE(embedded_test_server()->Start());
}
void InstallAndWaitFinish(const drive::DriveAppInfo& drive_app) {
runner_ = new content::MessageLoopRunner;
converter_.reset(new DriveAppConverter(
profile(),
drive_app,
base::Bind(&DriveAppConverterTest::ConverterFinished,
base::Unretained(this))));
converter_->Start();
runner_->Run();
}
GURL GetTestUrl(const std::string& path) {
return embedded_test_server()->base_url().Resolve(path);
}
drive::DriveAppInfo GetTestDriveApp() {
// Define four icons. icon1.png is 16x16 and good to use. icon2.png is
// 16x16 but claims to be 32x32 and should be dropped. icon3.png is 66x66
// and not a typical icon size but it should be allowed. The fourth one is
// icon2.png with 16x16 but should be ignored because 16x16 already has
// icon1.png as its resource.
drive::DriveAppInfo::IconList app_icons;
app_icons.push_back(std::make_pair(16, GetTestUrl("extensions/icon1.png")));
app_icons.push_back(std::make_pair(32, GetTestUrl("extensions/icon2.png")));
app_icons.push_back(std::make_pair(66, GetTestUrl("extensions/icon3.png")));
app_icons.push_back(std::make_pair(16, GetTestUrl("extensions/icon2.png")));
drive::DriveAppInfo::IconList document_icons;
return drive::DriveAppInfo("fake_drive_app_id",
"fake_product_id",
app_icons,
document_icons,
kAppName,
GURL(kAppUrl),
true);
}
const DriveAppConverter* converter() const { return converter_.get(); }
private:
void ConverterFinished(const DriveAppConverter* converter, bool success) {
if (runner_.get())
runner_->Quit();
}
std::unique_ptr<DriveAppConverter> converter_;
scoped_refptr<content::MessageLoopRunner> runner_;
DISALLOW_COPY_AND_ASSIGN(DriveAppConverterTest);
};
IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, GoodApp) {
InstallAndWaitFinish(GetTestDriveApp());
const Extension* app = converter()->extension();
ASSERT_TRUE(app != NULL);
EXPECT_EQ(kAppName, app->name());
EXPECT_TRUE(app->is_hosted_app());
EXPECT_TRUE(app->from_bookmark());
EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(app));
EXPECT_EQ(extensions::LAUNCH_CONTAINER_TAB,
AppLaunchInfo::GetLaunchContainer(app));
EXPECT_EQ(0u, app->permissions_data()->active_permissions().apis().size());
const ExtensionIconSet& icons = extensions::IconsInfo::GetIcons(app);
EXPECT_EQ(2u, icons.map().size());
EXPECT_FALSE(icons.Get(16, ExtensionIconSet::MATCH_EXACTLY).empty());
EXPECT_TRUE(icons.Get(32, ExtensionIconSet::MATCH_EXACTLY).empty());
EXPECT_FALSE(icons.Get(66, ExtensionIconSet::MATCH_EXACTLY).empty());
const Extension* installed = extensions::ExtensionSystem::Get(profile())
->extension_service()
->GetInstalledExtension(app->id());
EXPECT_EQ(app, installed);
EXPECT_FALSE(extensions::util::ShouldSync(app, profile()));
}
IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, BadApp) {
drive::DriveAppInfo no_name = GetTestDriveApp();
no_name.app_name.clear();
InstallAndWaitFinish(no_name);
EXPECT_TRUE(converter()->extension() == NULL);
drive::DriveAppInfo no_url = GetTestDriveApp();
no_url.create_url = GURL();
InstallAndWaitFinish(no_url);
EXPECT_TRUE(converter()->extension() == NULL);
}
IN_PROC_BROWSER_TEST_F(DriveAppConverterTest, InstallTwice) {
InstallAndWaitFinish(GetTestDriveApp());
const Extension* first_install = converter()->extension();
ASSERT_TRUE(first_install != NULL);
EXPECT_TRUE(converter()->is_new_install());
const std::string first_install_id = first_install->id();
const base::Version first_install_version(first_install->VersionString());
ASSERT_TRUE(first_install_version.IsValid());
InstallAndWaitFinish(GetTestDriveApp());
const Extension* second_install = converter()->extension();
ASSERT_TRUE(second_install != NULL);
EXPECT_FALSE(converter()->is_new_install());
// Two different app instances.
ASSERT_NE(first_install, second_install);
EXPECT_EQ(first_install_id, second_install->id());
EXPECT_GE(second_install->version()->CompareTo(first_install_version), 0);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/drive/drive_app_mapping.h"
#include <stddef.h>
#include <memory>
#include "base/values.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
namespace {
// Key for a string value that holds the mapped chrome app id.
const char kKeyChromeApp[] = "chrome_app";
// Key for a boolean value of whether the mapped chrome app is auto generated.
// Default is false.
const char kKeyGenerated[] = "generated";
std::unique_ptr<base::DictionaryValue> CreateInfoDict(
const std::string& chrome_app_id,
bool generated) {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
dict->SetKey(kKeyChromeApp, base::Value(chrome_app_id));
// Only writes non-default value.
if (generated)
dict->SetKey(kKeyGenerated, base::Value(true));
return dict;
}
} // namespace
DriveAppMapping::DriveAppMapping(PrefService* prefs) : prefs_(prefs) {
GetUninstalledIdsFromPref();
}
DriveAppMapping::~DriveAppMapping() {
}
// static
void DriveAppMapping::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterDictionaryPref(prefs::kAppLauncherDriveAppMapping);
registry->RegisterListPref(prefs::kAppLauncherUninstalledDriveApps);
}
void DriveAppMapping::Add(const std::string& drive_app_id,
const std::string& chrome_app_id,
bool generated) {
DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping);
update->SetWithoutPathExpansion(drive_app_id,
CreateInfoDict(chrome_app_id, generated));
}
void DriveAppMapping::Remove(const std::string& drive_app_id) {
DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping);
update->RemoveWithoutPathExpansion(drive_app_id, NULL);
}
std::string DriveAppMapping::GetChromeApp(
const std::string& drive_app_id) const {
const base::DictionaryValue* mapping =
prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
const base::DictionaryValue* info_dict;
std::string chrome_app_id;
if (mapping->GetDictionaryWithoutPathExpansion(drive_app_id, &info_dict) &&
info_dict->GetStringWithoutPathExpansion(kKeyChromeApp, &chrome_app_id)) {
return chrome_app_id;
}
return std::string();
}
std::string DriveAppMapping::GetDriveApp(
const std::string& chrome_app_id) const {
const base::DictionaryValue* mapping =
prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd();
it.Advance()) {
const base::DictionaryValue* info_dict;
std::string value_string;
DCHECK(it.value().is_dict());
if (it.value().GetAsDictionary(&info_dict) &&
info_dict->GetStringWithoutPathExpansion(kKeyChromeApp,
&value_string) &&
value_string == chrome_app_id) {
return it.key();
}
}
return std::string();
}
bool DriveAppMapping::IsChromeAppGenerated(
const std::string& chrome_app_id) const {
const base::DictionaryValue* mapping =
prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd();
it.Advance()) {
const base::DictionaryValue* info_dict;
std::string value_string;
bool generated = false;
DCHECK(it.value().is_dict());
if (it.value().GetAsDictionary(&info_dict) &&
info_dict->GetStringWithoutPathExpansion(kKeyChromeApp,
&value_string) &&
value_string == chrome_app_id &&
info_dict->GetBooleanWithoutPathExpansion(kKeyGenerated, &generated)) {
return generated;
}
}
return false;
}
std::set<std::string> DriveAppMapping::GetDriveAppIds() const {
const base::DictionaryValue* mapping =
prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
std::set<std::string> keys;
for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd();
it.Advance()) {
keys.insert(it.key());
}
return keys;
}
void DriveAppMapping::AddUninstalledDriveApp(const std::string& drive_app_id) {
if (IsUninstalledDriveApp(drive_app_id))
return;
uninstalled_app_ids_.insert(drive_app_id);
UpdateUninstalledList();
}
void DriveAppMapping::RemoveUninstalledDriveApp(
const std::string& drive_app_id) {
auto it = uninstalled_app_ids_.find(drive_app_id);
if (it == uninstalled_app_ids_.end())
return;
uninstalled_app_ids_.erase(it);
UpdateUninstalledList();
}
bool DriveAppMapping::IsUninstalledDriveApp(
const std::string& drive_app_id) const {
return uninstalled_app_ids_.find(drive_app_id) != uninstalled_app_ids_.end();
}
void DriveAppMapping::GetUninstalledIdsFromPref() {
uninstalled_app_ids_.clear();
const base::ListValue* list =
prefs_->GetList(prefs::kAppLauncherUninstalledDriveApps);
for (size_t i = 0; i < list->GetSize(); ++i) {
std::string app_id;
if (!list->GetString(i, &app_id))
continue;
uninstalled_app_ids_.insert(app_id);
}
}
void DriveAppMapping::UpdateUninstalledList() {
ListPrefUpdate update(prefs_, prefs::kAppLauncherUninstalledDriveApps);
update->Clear();
for (const auto& app_id : uninstalled_app_ids_)
update->AppendString(app_id);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_MAPPING_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_MAPPING_H_
#include <set>
#include <string>
#include "base/macros.h"
namespace user_prefs {
class PrefRegistrySyncable;
}
class PrefService;
// DriveAppMapping tracks the mapping between Drive apps and corresponding
// Chrome apps. The data is backed by kAppLauncherDriveAppMapping pref.
class DriveAppMapping {
public:
explicit DriveAppMapping(PrefService* prefs);
~DriveAppMapping();
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Adds a mapping from |drive_app_id| to |chrome_app_id|. |generated|
// represents whether the corresponding Chrome app is generated.
void Add(const std::string& drive_app_id,
const std::string& chrome_app_id,
bool generated);
void Remove(const std::string& drive_app_id);
std::string GetChromeApp(const std::string& drive_app_id) const;
std::string GetDriveApp(const std::string& chrome_app_id) const;
bool IsChromeAppGenerated(const std::string& chrome_app_id) const;
std::set<std::string> GetDriveAppIds() const;
void AddUninstalledDriveApp(const std::string& drive_app_id);
void RemoveUninstalledDriveApp(const std::string& drive_app_id);
bool IsUninstalledDriveApp(const std::string& drive_app_id) const;
private:
void GetUninstalledIdsFromPref();
void UpdateUninstalledList();
PrefService* prefs_;
std::set<std::string> uninstalled_app_ids_;
DISALLOW_COPY_AND_ASSIGN(DriveAppMapping);
};
#endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_MAPPING_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/drive/drive_app_mapping.h"
#include <memory>
#include "base/macros.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
class DriveAppMappingTest : public testing::Test {
public:
DriveAppMappingTest() {}
~DriveAppMappingTest() override {}
// testing::Test:
void SetUp() override {
pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable);
DriveAppMapping::RegisterProfilePrefs(pref_service_->registry());
mapping_.reset(new DriveAppMapping(pref_service_.get()));
}
DriveAppMapping* mapping() { return mapping_.get(); }
private:
std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> pref_service_;
std::unique_ptr<DriveAppMapping> mapping_;
DISALLOW_COPY_AND_ASSIGN(DriveAppMappingTest);
};
TEST_F(DriveAppMappingTest, Empty) {
EXPECT_EQ("", mapping()->GetChromeApp(""));
EXPECT_EQ("", mapping()->GetDriveApp(""));
EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app"));
EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app"));
EXPECT_EQ(0u, mapping()->GetDriveAppIds().size());
}
TEST_F(DriveAppMappingTest, Add) {
std::set<std::string> drive_app_ids;
// Add one.
mapping()->Add("drive", "chrome", false);
EXPECT_EQ("chrome", mapping()->GetChromeApp("drive"));
EXPECT_EQ("drive", mapping()->GetDriveApp("chrome"));
EXPECT_FALSE(mapping()->IsChromeAppGenerated("chrome"));
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(1u, drive_app_ids.size());
EXPECT_EQ(1u, drive_app_ids.count("drive"));
// Overwrite previous mapping if added under the same key.
mapping()->Add("drive", "another-chrome-app", true);
EXPECT_EQ("", mapping()->GetDriveApp("chrome"));
EXPECT_FALSE(mapping()->IsChromeAppGenerated("chrome"));
EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive"));
EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app"));
EXPECT_TRUE(mapping()->IsChromeAppGenerated("another-chrome-app"));
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(1u, drive_app_ids.size());
EXPECT_EQ(1u, drive_app_ids.count("drive"));
// Add another one.
mapping()->Add("drive-1", "chrome-1", false);
EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1"));
EXPECT_EQ("drive-1", mapping()->GetDriveApp("chrome-1"));
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(2u, drive_app_ids.size());
EXPECT_EQ(1u, drive_app_ids.count("drive"));
EXPECT_EQ(1u, drive_app_ids.count("drive-1"));
// Previous mapping should not be affected by new mapping.
EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive"));
EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app"));
EXPECT_TRUE(mapping()->IsChromeAppGenerated("another-chrome-app"));
// Non-existent value returns empty string.
EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app"));
EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app"));
}
TEST_F(DriveAppMappingTest, Remove) {
std::set<std::string> drive_app_ids;
// Prepare data.
mapping()->Add("drive-1", "chrome-1", false);
mapping()->Add("drive-2", "chrome-2", false);
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(2u, drive_app_ids.size());
// Remove non-existent.
mapping()->Remove("non-existent-drive-app");
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(2u, drive_app_ids.size());
// Remove one.
EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1"));
mapping()->Remove("drive-1");
EXPECT_EQ("", mapping()->GetChromeApp("drive-1"));
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(1u, drive_app_ids.size());
// Remove it again has no effect.
mapping()->Remove("drive-1");
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(1u, drive_app_ids.size());
// Remove another one.
EXPECT_EQ("chrome-2", mapping()->GetChromeApp("drive-2"));
mapping()->Remove("drive-2");
EXPECT_EQ("", mapping()->GetChromeApp("drive-2"));
drive_app_ids = mapping()->GetDriveAppIds();
EXPECT_EQ(0u, drive_app_ids.size());
}
TEST_F(DriveAppMappingTest, TrackUninstall) {
const std::string drive_app_id = "drive-1";
mapping()->AddUninstalledDriveApp(drive_app_id);
EXPECT_TRUE(mapping()->IsUninstalledDriveApp(drive_app_id));
mapping()->RemoveUninstalledDriveApp(drive_app_id);
EXPECT_FALSE(mapping()->IsUninstalledDriveApp(drive_app_id));
}
This diff is collapsed.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/drive/drive_app_registry_observer.h"
#include "extensions/browser/extension_registry_observer.h"
namespace drive {
struct DriveAppInfo;
}
class BrowserContextKeyedServiceFactory;
class DriveAppConverter;
class DriveAppMapping;
class DriveAppUninstallSyncService;
class DriveServiceBridge;
class Profile;
// DriveAppProvider is the integration point for Drive apps. It ensures each
// Drive app has a corresponding Chrome app in the extension system. If there
// is no matching Chrome app, a local URL app would be created. The class
// processes app changes from both DriveAppRegistry and extension system to
// keep the two in sync.
class DriveAppProvider : public drive::DriveAppRegistryObserver,
public extensions::ExtensionRegistryObserver {
public:
DriveAppProvider(Profile* profile,
DriveAppUninstallSyncService* uninstall_sync_service);
~DriveAppProvider() override;
// Appends PKS factories this class depends on.
static void AppendDependsOnFactories(
std::set<BrowserContextKeyedServiceFactory*>* factories);
void SetDriveServiceBridgeForTest(
std::unique_ptr<DriveServiceBridge> test_bridge);
// Adds/removes uninstalled Drive app id from DriveAppUninstallSyncService.
// If a Drive app id is added as uninstalled Drive app, DriveAppProvider
// would not auto create the local URL app for it until the uninstall record
// is removed.
void AddUninstalledDriveAppFromSync(const std::string& drive_app_id);
void RemoveUninstalledDriveAppFromSync(const std::string& drive_app_id);
private:
friend class DriveAppProviderTest;
typedef std::set<std::string> IdSet;
typedef std::vector<drive::DriveAppInfo> DriveAppInfos;
// Maps |drive_app_id| to |new_app|'s id in mapping. Auto uninstall existing
// mapped app if it is an URL app.
void UpdateMappingAndExtensionSystem(const std::string& drive_app_id,
const extensions::Extension* new_app,
bool is_new_app_generated);
// Deferred processing of relevant extension installed message.
void ProcessDeferredOnExtensionInstalled(const std::string drive_app_id,
const std::string chrome_app_id);
void SchedulePendingConverters();
void OnLocalAppConverted(const DriveAppConverter* converter, bool success);
bool IsMappedUrlAppUpToDate(const drive::DriveAppInfo& drive_app) const;
void AddOrUpdateDriveApp(const drive::DriveAppInfo& drive_app);
void ProcessRemovedDriveApp(const std::string& drive_app_id);
void UpdateDriveApps();
// drive::DriveAppRegistryObserver overrides:
void OnDriveAppRegistryUpdated() override;
// extensions::ExtensionRegistryObserver overrides:
void OnExtensionInstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension,
bool is_update) override;
void OnExtensionUninstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) override;
Profile* profile_;
DriveAppUninstallSyncService* uninstall_sync_service_;
std::unique_ptr<DriveServiceBridge> service_bridge_;
std::unique_ptr<DriveAppMapping> mapping_;
DriveAppInfos drive_apps_;
bool drive_app_registry_updated_;
// Tracks the pending web app convertions.
std::vector<std::unique_ptr<DriveAppConverter>> pending_converters_;
base::WeakPtrFactory<DriveAppProvider> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DriveAppProvider);
};
#endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_UNINSTALL_SYNC_SERVICE_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_UNINSTALL_SYNC_SERVICE_H_
class DriveAppUninstallSyncService {
public:
// Invoked when user uninstalls a default Drive app.
virtual void TrackUninstalledDriveApp(
const std::string& drive_app_id) = 0;
// Invoked when user installs a default Drive app.
virtual void UntrackUninstalledDriveApp(
const std::string& drive_app_id) = 0;
protected:
virtual ~DriveAppUninstallSyncService() {}
};
#endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_UNINSTALL_SYNC_SERVICE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/drive/drive_service_bridge.h"
#include <string>
#include <utility>
#include "base/logging.h"
#include "base/macros.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/drive/drive_notification_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/drive/drive_app_registry.h"
#include "components/drive/drive_notification_manager.h"
#include "components/drive/drive_notification_observer.h"
#include "components/drive/service/drive_api_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace {
// Hosts DriveAPIService and DriveAppRegistry.
// TODO(xiyuan): Optimize to leverage chromeos::DriveIntegrationService.
class DriveServiceBridgeImpl : public DriveServiceBridge,
public drive::DriveServiceObserver,
public drive::DriveNotificationObserver {
public:
explicit DriveServiceBridgeImpl(Profile* profile);
~DriveServiceBridgeImpl() override;
void Initialize();
// DriveServiceBridge:
drive::DriveAppRegistry* GetAppRegistry() override;
// drive::DriveServiceObserver:
void OnReadyToSendRequests() override;
// drive::DriveNotificationObserver:
void OnNotificationReceived() override;
void OnPushNotificationEnabled(bool enabled) override;
private:
Profile* profile_;
std::unique_ptr<drive::DriveServiceInterface> drive_service_;
std::unique_ptr<drive::DriveAppRegistry> drive_app_registry_;
DISALLOW_COPY_AND_ASSIGN(DriveServiceBridgeImpl);
};
DriveServiceBridgeImpl::DriveServiceBridgeImpl(Profile* profile)
: profile_(profile) {
DCHECK(profile_);
}
DriveServiceBridgeImpl::~DriveServiceBridgeImpl() {
drive::DriveNotificationManager* drive_notification_manager =
drive::DriveNotificationManagerFactory::FindForBrowserContext(profile_);
if (drive_notification_manager)
drive_notification_manager->RemoveObserver(this);
drive_service_->RemoveObserver(this);
drive_app_registry_.reset();
drive_service_.reset();
}
void DriveServiceBridgeImpl::Initialize() {
scoped_refptr<base::SequencedTaskRunner> drive_task_runner(
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
drive_service_.reset(new drive::DriveAPIService(
token_service, profile_->GetRequestContext(), drive_task_runner.get(),
GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction),
std::string(), /* custom_user_agent */
NO_TRAFFIC_ANNOTATION_YET));
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
drive_service_->Initialize(signin_manager->GetAuthenticatedAccountId());
drive_service_->AddObserver(this);
drive::DriveNotificationManager* drive_notification_manager =
drive::DriveNotificationManagerFactory::GetForBrowserContext(profile_);
if (drive_notification_manager)
drive_notification_manager->AddObserver(this);
drive_app_registry_.reset(new drive::DriveAppRegistry(drive_service_.get()));
if (drive_service_->CanSendRequest())
drive_app_registry_->Update();
}
drive::DriveAppRegistry* DriveServiceBridgeImpl::GetAppRegistry() {
return drive_app_registry_.get();
}
void DriveServiceBridgeImpl::OnReadyToSendRequests() {
drive_app_registry_->Update();
}
void DriveServiceBridgeImpl::OnNotificationReceived() {
if (drive_service_->CanSendRequest())
drive_app_registry_->Update();
}
void DriveServiceBridgeImpl::OnPushNotificationEnabled(bool enabled) {
if (enabled && drive_service_->CanSendRequest())
drive_app_registry_->Update();
}
} // namespace
// static
std::unique_ptr<DriveServiceBridge> DriveServiceBridge::Create(
Profile* profile) {
std::unique_ptr<DriveServiceBridgeImpl> bridge(
new DriveServiceBridgeImpl(profile));
bridge->Initialize();
return std::move(bridge);
}
// static
void DriveServiceBridge::AppendDependsOnFactories(
std::set<BrowserContextKeyedServiceFactory*>* factories) {
DCHECK(factories);
factories->insert(ProfileOAuth2TokenServiceFactory::GetInstance());
factories->insert(SigninManagerFactory::GetInstance());
factories->insert(drive::DriveNotificationManagerFactory::GetInstance());
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_SERVICE_BRIDGE_H_
#define CHROME_BROWSER_APPS_DRIVE_DRIVE_SERVICE_BRIDGE_H_
#include <memory>
#include <set>
namespace drive {
class DriveAppRegistry;
}
class BrowserContextKeyedServiceFactory;
class Profile;
// An interface to access Drive service for a given profile.
class DriveServiceBridge {
public:
virtual ~DriveServiceBridge() {}
// Factory to create an instance of DriveServiceBridge.
static std::unique_ptr<DriveServiceBridge> Create(Profile* profile);
// Appends PKS factories this class depends on.
static void AppendDependsOnFactories(
std::set<BrowserContextKeyedServiceFactory*>* factories);
// Returns the DriveAppRegistery to use. The ownership is not transferred.
virtual drive::DriveAppRegistry* GetAppRegistry() = 0;
};
#endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_SERVICE_BRIDGE_H_
......@@ -1094,22 +1094,6 @@ static_library("extensions") {
]
}
if (enable_app_list) {
sources += [
# TODO These references to files in //chrome/browser/ should either be
# moved to the browser target or the files moved to this directory.
"../apps/drive/drive_app_converter.cc",
"../apps/drive/drive_app_converter.h",
"../apps/drive/drive_app_mapping.cc",
"../apps/drive/drive_app_mapping.h",
"../apps/drive/drive_app_provider.cc",
"../apps/drive/drive_app_provider.h",
"../apps/drive/drive_app_uninstall_sync_service.h",
"../apps/drive/drive_service_bridge.cc",
"../apps/drive/drive_service_bridge.h",
]
}
if (enable_print_preview && !is_chromeos) {
sources += [
"api/cloud_print_private/cloud_print_private_api.cc",
......
......@@ -117,7 +117,6 @@
#include "rlz/features/features.h"
#if BUILDFLAG(ENABLE_APP_LIST)
#include "chrome/browser/apps/drive/drive_app_mapping.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#endif
......@@ -574,7 +573,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
DeviceIDFetcher::RegisterProfilePrefs(registry);
DevToolsWindow::RegisterProfilePrefs(registry);
#if BUILDFLAG(ENABLE_APP_LIST)
DriveAppMapping::RegisterProfilePrefs(registry);
app_list::AppListSyncableService::RegisterProfilePrefs(registry);
#endif
extensions::CommandService::RegisterProfilePrefs(registry);
......
......@@ -17,7 +17,6 @@
#include "base/strings/string_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/apps/drive/drive_app_provider.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/genius_app/app_id.h"
......@@ -45,7 +44,6 @@
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/constants.h"
#include "extensions/common/one_shot_event.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/base/l10n/l10n_util.h"
using syncer::SyncChange;
......@@ -54,18 +52,11 @@ namespace app_list {
namespace {
const char kNameKey[] = "name";
const char kParentIdKey[] = "parent_id";
const char kPositionKey[] = "position";
const char kPinPositionKey[] = "pin_position";
const char kTypeKey[] = "type";
// Prefix for a sync id of a Drive app. Drive app ids are in a different
// format and have to be used because a Drive app could have only an URL
// without a matching Chrome app. To differentiate the Drive app id from
// Chrome app ids, this prefix will be added to create the sync item id
// for a Drive app item.
const char kDriveAppSyncIdPrefix[] = "drive-app-";
constexpr char kNameKey[] = "name";
constexpr char kParentIdKey[] = "parent_id";
constexpr char kPositionKey[] = "position";
constexpr char kPinPositionKey[] = "pin_position";
constexpr char kTypeKey[] = "type";
void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics,
AppListSyncableService::SyncItem* item) {
......@@ -158,21 +149,19 @@ bool GetAppListItemType(AppListItem* item,
return true;
}
// TODO(http://crbug.com/794724): Remove after M65 goes stable.
bool IsDriveAppSyncId(const std::string& sync_id) {
// Prefix for a sync id of a Drive app. Drive app ids are in a different
// format and have to be used because a Drive app could have only an URL
// without a matching Chrome app. To differentiate the Drive app id from
// Chrome app ids, this prefix will be added to create the sync item id
// for a Drive app item.
constexpr char kDriveAppSyncIdPrefix[] = "drive-app-";
return base::StartsWith(sync_id, kDriveAppSyncIdPrefix,
base::CompareCase::SENSITIVE);
}
std::string GetDriveAppSyncId(const std::string& drive_app_id) {
return kDriveAppSyncIdPrefix + drive_app_id;
}
std::string GetDriveAppIdFromSyncId(const std::string& sync_id) {
if (!IsDriveAppSyncId(sync_id))
return std::string();
return sync_id.substr(strlen(kDriveAppSyncIdPrefix));
}
void RemoveSyncItemFromLocalStorage(Profile* profile,
const std::string& item_id) {
DictionaryPrefUpdate(profile->GetPrefs(), prefs::kAppListLocalState)->
......@@ -400,11 +389,6 @@ void AppListSyncableService::BuildModel() {
if (arc_apps_builder_.get())
arc_apps_builder_->Initialize(this, profile_, model_updater_.get());
if (app_list::switches::IsDriveAppsInAppListEnabled() &&
!::switches::ExtensionsDisabled()) {
drive_app_provider_.reset(new DriveAppProvider(profile_, this));
}
HandleUpdateFinished();
}
......@@ -427,43 +411,6 @@ size_t AppListSyncableService::GetNumSyncItemsForTest() {
return sync_items_.size();
}
void AppListSyncableService::ResetDriveAppProviderForTest() {
drive_app_provider_.reset();
}
void AppListSyncableService::Shutdown() {
// DriveAppProvider touches other KeyedServices in its dtor and needs be
// released in shutdown stage.
drive_app_provider_.reset();
}
void AppListSyncableService::TrackUninstalledDriveApp(
const std::string& drive_app_id) {
const std::string sync_id = GetDriveAppSyncId(drive_app_id);
SyncItem* sync_item = FindSyncItem(sync_id);
if (sync_item) {
DCHECK_EQ(sync_item->item_type,
sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP);
return;
}
sync_item = CreateSyncItem(
sync_id, sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP);
SendSyncChange(sync_item, SyncChange::ACTION_ADD);
}
void AppListSyncableService::UntrackUninstalledDriveApp(
const std::string& drive_app_id) {
const std::string sync_id = GetDriveAppSyncId(drive_app_id);
SyncItem* sync_item = FindSyncItem(sync_id);
if (!sync_item)
return;
DCHECK_EQ(sync_item->item_type,
sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP);
DeleteSyncItem(drive_app_id);
}
const AppListSyncableService::SyncItem*
AppListSyncableService::GetSyncItem(const std::string& id) const {
auto iter = sync_items_.find(id);
......@@ -502,6 +449,8 @@ void AppListSyncableService::HandleUpdateFinished() {
// Resolve them now.
ResolveFolderPositions();
RemoveDriveAppItems();
// Resume or start observing app list model changes.
model_observer_.reset(new ModelObserver(this));
......@@ -982,12 +931,7 @@ void AppListSyncableService::ProcessNewSyncItem(SyncItem* sync_item) {
}
case sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP: {
VLOG(1) << this << ": Uninstall: " << sync_item->ToString();
if (IsDriveAppSyncId(sync_item->item_id)) {
if (drive_app_provider_) {
drive_app_provider_->AddUninstalledDriveAppFromSync(
GetDriveAppIdFromSyncId(sync_item->item_id));
}
} else {
if (!IsDriveAppSyncId(sync_item->item_id)) {
UninstallExtension(extension_system_->extension_service(),
sync_item->item_id);
}
......@@ -1100,11 +1044,6 @@ void AppListSyncableService::DeleteSyncItemSpecifics(
// children have been deleted.
if (item_type == sync_pb::AppListSpecifics::TYPE_APP) {
model_updater_->RemoveItem(item_id);
} else if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
if (IsDriveAppSyncId(item_id) && drive_app_provider_) {
drive_app_provider_->RemoveUninstalledDriveAppFromSync(
GetDriveAppIdFromSyncId(item_id));
}
}
}
......@@ -1177,4 +1116,15 @@ void AppListSyncableService::MaybeImportLegacyPlayStorePosition(
DVLOG(2) << "Play Store app list item was updated from the legacy entry";
}
void AppListSyncableService::RemoveDriveAppItems() {
std::set<std::string> drive_app_item_ids;
for (const auto& sync_pair : sync_items_) {
if (IsDriveAppSyncId(sync_pair.first))
drive_app_item_ids.insert(sync_pair.first);
}
for (const auto& item_id : drive_app_item_ids)
DeleteSyncItem(item_id);
}
} // namespace app_list
......@@ -15,7 +15,6 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "build/build_config.h"
#include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h"
#include "chrome/browser/sync/glue/sync_start_util.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sync/model/string_ordinal.h"
......@@ -26,7 +25,6 @@
#include "components/sync/protocol/app_list_specifics.pb.h"
class ArcAppModelBuilder;
class DriveAppProvider;
class ExtensionAppModelBuilder;
class Profile;
......@@ -54,8 +52,7 @@ class ChromeAppListModelUpdater;
// Keyed Service that owns, stores, and syncs an AppListModel for a profile.
class AppListSyncableService : public syncer::SyncableService,
public KeyedService,
public DriveAppUninstallSyncService {
public KeyedService {
public:
struct SyncItem {
SyncItem(const std::string& id,
......@@ -145,7 +142,6 @@ class AppListSyncableService : public syncer::SyncableService,
const std::string& GetOemFolderNameForTest() const {
return oem_folder_name_;
}
void ResetDriveAppProviderForTest();
const SyncItemMap& sync_items() const { return sync_items_; }
......@@ -164,13 +160,6 @@ class AppListSyncableService : public syncer::SyncableService,
private:
class ModelObserver;
// KeyedService
void Shutdown() override;
// DriveAppUninstallSyncService
void TrackUninstalledDriveApp(const std::string& drive_app_id) override;
void UntrackUninstalledDriveApp(const std::string& drive_app_id) override;
// Builds the model once ExtensionService is ready.
void BuildModel();
......@@ -272,6 +261,10 @@ class AppListSyncableService : public syncer::SyncableService,
// releases http://crbug.com/722675.
void MaybeImportLegacyPlayStorePosition(syncer::SyncChangeList* change_list);
// Remove sync data of Drive apps.
// TODO(http://crbug.com/794724): Remove after M65 goes stable.
void RemoveDriveAppItems();
Profile* profile_;
extensions::ExtensionSystem* extension_system_;
std::unique_ptr<ChromeAppListModelUpdater> model_updater_;
......@@ -289,9 +282,6 @@ class AppListSyncableService : public syncer::SyncableService,
// List of observers.
base::ObserverList<Observer> observer_list_;
// Provides integration with Drive apps.
std::unique_ptr<DriveAppProvider> drive_app_provider_;
base::WeakPtrFactory<AppListSyncableService> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AppListSyncableService);
......
......@@ -8,7 +8,6 @@
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "chrome/browser/apps/drive/drive_app_provider.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
......@@ -67,7 +66,6 @@ AppListSyncableServiceFactory::AppListSyncableServiceFactory()
dependent_factories.insert(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
dependent_factories.insert(ArcAppListPrefsFactory::GetInstance());
DriveAppProvider::AppendDependsOnFactories(&dependent_factories);
for (FactorySet::iterator it = dependent_factories.begin();
it != dependent_factories.end();
++it) {
......
......@@ -413,3 +413,21 @@ TEST_F(AppListSyncableServiceTest, InitialMergeAndUpdate_BadData) {
ASSERT_TRUE(GetSyncItem(kItemId));
}
TEST_F(AppListSyncableServiceTest, InitialMerge_NoDriveAppData) {
// Note that Drive app item id must start with "drive-app-" prefix as defined
// in kDriveAppSyncIdPrefix in AppListSyncableService.
constexpr char kDriveAppItemId[] = "drive-app-fake-drive-app";
syncer::SyncDataList sync_list;
sync_list.push_back(CreateAppRemoteData(
kDriveAppItemId, "Fake Drive App", kParentId(), "ordinal", "pinordinal"));
app_list_syncable_service()->MergeDataAndStartSyncing(
syncer::APP_LIST, sync_list,
base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
base::MakeUnique<syncer::SyncErrorFactoryMock>());
content::RunAllTasksUntilIdle();
ASSERT_FALSE(GetSyncItem(kDriveAppItemId));
}
......@@ -1883,8 +1883,6 @@ test("browser_tests") {
}
if (enable_app_list) {
sources += [
"../browser/apps/drive/drive_app_converter_browsertest.cc",
"../browser/apps/drive/drive_app_provider_browsertest.cc",
"../browser/ui/app_list/app_list_controller_browsertest.cc",
"../browser/ui/app_list/app_list_service_impl_browsertest.cc",
"../browser/ui/app_list/search/webstore/webstore_provider_browsertest.cc",
......@@ -4155,7 +4153,6 @@ test("unit_tests") {
}
if (enable_app_list) {
sources += [
"../browser/apps/drive/drive_app_mapping_unittest.cc",
"../browser/ui/app_list/app_context_menu_unittest.cc",
"../browser/ui/app_list/app_list_service_unittest.cc",
"../browser/ui/app_list/app_list_syncable_service_unittest.cc",
......
......@@ -42,10 +42,6 @@ bool ShouldNotDismissOnBlur() {
kDisableAppListDismissOnBlur);
}
bool IsDriveAppsInAppListEnabled() {
return true;
}
bool IsDriveSearchInChromeLauncherEnabled() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kEnableDriveSearchInChromeLauncher))
......
......@@ -28,8 +28,6 @@ bool APP_LIST_EXPORT IsVoiceSearchEnabled();
// Determines whether the app list should not be dismissed on focus loss.
bool APP_LIST_EXPORT ShouldNotDismissOnBlur();
bool APP_LIST_EXPORT IsDriveAppsInAppListEnabled();
bool APP_LIST_EXPORT IsDriveSearchInChromeLauncherEnabled();
} // namespace switches
......
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