summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn1
-rw-r--r--chrome/BUILD.gn1
-rw-r--r--chrome/browser/BUILD.gn2
-rw-r--r--chrome/browser/chrome_browser_main_android.cc5
-rw-r--r--chrome/browser/enhanced_bookmarks/OWNERS2
-rw-r--r--chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.cc71
-rw-r--r--chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h46
-rw-r--r--chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc56
-rw-r--r--chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h44
-rw-r--r--chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc14
-rw-r--r--chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h13
-rw-r--r--chrome/browser/prefs/browser_prefs.cc2
-rw-r--r--chrome/chrome_android.gypi3
-rw-r--r--chrome/chrome_browser.gypi6
-rw-r--r--chrome/common/extensions/api/bookmark_manager_private.json18
-rw-r--r--components/BUILD.gn1
-rw-r--r--components/components_strings.grd1
-rw-r--r--components/components_tests.gyp9
-rw-r--r--components/enhanced_bookmarks.gypi91
-rw-r--r--components/enhanced_bookmarks/BUILD.gn94
-rw-r--r--components/enhanced_bookmarks/DEPS15
-rw-r--r--components/enhanced_bookmarks/bookmark_server_cluster_service.cc393
-rw-r--r--components/enhanced_bookmarks/bookmark_server_cluster_service.h142
-rw-r--r--components/enhanced_bookmarks/bookmark_server_service.cc161
-rw-r--r--components/enhanced_bookmarks/bookmark_server_service.h126
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_model.cc537
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_model.h222
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_model_observer.h51
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc718
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_switches_ios.cc12
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h14
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_utils.cc66
-rw-r--r--components/enhanced_bookmarks/enhanced_bookmark_utils.h32
-rw-r--r--components/enhanced_bookmarks/image_record.cc26
-rw-r--r--components/enhanced_bookmarks/image_record.h39
-rw-r--r--components/enhanced_bookmarks/image_store.cc24
-rw-r--r--components/enhanced_bookmarks/image_store.h72
-rw-r--r--components/enhanced_bookmarks/image_store_ios_unittest.mm161
-rw-r--r--components/enhanced_bookmarks/image_store_unittest.cc341
-rw-r--r--components/enhanced_bookmarks/image_store_util.cc39
-rw-r--r--components/enhanced_bookmarks/image_store_util.h31
-rw-r--r--components/enhanced_bookmarks/image_store_util_ios.mm56
-rw-r--r--components/enhanced_bookmarks/item_position.cc179
-rw-r--r--components/enhanced_bookmarks/item_position.h59
-rw-r--r--components/enhanced_bookmarks/item_position_unittest.cc81
-rw-r--r--components/enhanced_bookmarks/metadata_accessor.cc258
-rw-r--r--components/enhanced_bookmarks/metadata_accessor.h91
-rw-r--r--components/enhanced_bookmarks/persistent_image_store.cc343
-rw-r--r--components/enhanced_bookmarks/persistent_image_store.h50
-rw-r--r--components/enhanced_bookmarks/pref_names.cc13
-rw-r--r--components/enhanced_bookmarks/pref_names.h19
-rw-r--r--components/enhanced_bookmarks/proto/BUILD.gn13
-rw-r--r--components/enhanced_bookmarks/proto/cluster.proto34
-rw-r--r--components/enhanced_bookmarks/proto/metadata.proto60
-rw-r--r--components/enhanced_bookmarks/proto/search.proto30
-rw-r--r--components/enhanced_bookmarks/test_image_store.cc89
-rw-r--r--components/enhanced_bookmarks/test_image_store.h42
-rw-r--r--components/enhanced_bookmarks_strings.grdp9
-rw-r--r--extensions/browser/extension_function_histogram_value.h2
-rw-r--r--ios/chrome/BUILD.gn1
-rw-r--r--ios/chrome/browser/BUILD.gn2
-rw-r--r--ios/chrome/browser/DEPS1
-rw-r--r--ios/chrome/browser/about_flags.mm19
-rw-r--r--ios/chrome/browser/experimental_flags.mm20
-rw-r--r--ios/chrome/ios_chrome.gyp2
-rw-r--r--ios/chrome/ios_chrome_tests.gyp1
-rw-r--r--tools/metrics/histograms/histograms.xml2
67 files changed, 5 insertions, 5173 deletions
diff --git a/BUILD.gn b/BUILD.gn
index c1bc7cb..d1c5875 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -662,7 +662,6 @@ group("gn_only") {
"//chrome/installer/util:strings",
"//chrome/tools/convert_dict",
"//components/constrained_window:unit_tests",
- "//components/enhanced_bookmarks:test_support",
"//components/metrics:serialization",
"//components/password_manager/content/renderer:browser_tests",
"//components/rappor:unit_tests",
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn
index d3e7daf..96bb583 100644
--- a/chrome/BUILD.gn
+++ b/chrome/BUILD.gn
@@ -980,7 +980,6 @@ if (is_android) {
"//chrome/plugin",
"//chrome/renderer",
"//chrome/utility",
- "//components/enhanced_bookmarks",
"//content/public/app:both",
]
}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index bf5d62a..bb99933 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -119,7 +119,6 @@ source_set("browser") {
"//components/data_use_measurement/core",
"//components/device_event_log",
"//components/domain_reliability",
- "//components/enhanced_bookmarks",
"//components/favicon/core",
"//components/favicon_base",
"//components/flags_ui",
@@ -774,7 +773,6 @@ source_set("browser") {
":delta_file_proto",
":jni_headers",
"//components/data_usage/android",
- "//components/enhanced_bookmarks",
"//components/precache/content",
"//components/precache/core",
"//components/resources:components_resources",
diff --git a/chrome/browser/chrome_browser_main_android.cc b/chrome/browser/chrome_browser_main_android.cc
index 4fd6d9d..a481b6a 100644
--- a/chrome/browser/chrome_browser_main_android.cc
+++ b/chrome/browser/chrome_browser_main_android.cc
@@ -17,7 +17,6 @@
#include "chrome/common/chrome_paths.h"
#include "components/crash/content/app/breakpad_linux.h"
#include "components/crash/content/browser/crash_dump_manager_android.h"
-#include "components/enhanced_bookmarks/persistent_image_store.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/android/compositor.h"
#include "content/public/browser/browser_thread.h"
@@ -86,8 +85,8 @@ void ChromeBrowserMainPartsAndroid::PostProfileInit() {
// Previously we stored information related to salient images for bookmarks
// in a local file. We replaced the salient images with favicons. As part
// of the clean up, the local file needs to be deleted. See crbug.com/499415.
- base::FilePath bookmark_image_file_path = profile()->GetPath().Append(
- PersistentImageStore::kBookmarkImageStoreDb);
+ base::FilePath bookmark_image_file_path =
+ profile()->GetPath().Append("BookmarkImageAndUrlStore.db");
content::BrowserThread::PostDelayedTask(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(&DeleteFileTask, bookmark_image_file_path),
diff --git a/chrome/browser/enhanced_bookmarks/OWNERS b/chrome/browser/enhanced_bookmarks/OWNERS
deleted file mode 100644
index 066d364..0000000
--- a/chrome/browser/enhanced_bookmarks/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-kkimlabs@chromium.org
-noyau@chromium.org
diff --git a/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.cc b/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.cc
deleted file mode 100644
index 0cb53aa..0000000
--- a/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.cc
+++ /dev/null
@@ -1,71 +0,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/enhanced_bookmarks/bookmark_server_cluster_service_factory.h"
-
-#include "base/memory/singleton.h"
-#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h"
-#include "chrome/browser/profiles/incognito_helpers.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 "chrome/browser/sync/profile_sync_service_factory.h"
-#include "components/browser_sync/browser/profile_sync_service.h"
-#include "components/enhanced_bookmarks/bookmark_server_cluster_service.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-#include "components/signin/core/browser/signin_manager.h"
-
-namespace enhanced_bookmarks {
-
-BookmarkServerClusterServiceFactory::BookmarkServerClusterServiceFactory()
- : BrowserContextKeyedServiceFactory(
- "BookmarkServerClusterService",
- BrowserContextDependencyManager::GetInstance()) {
- DependsOn(ProfileSyncServiceFactory::GetInstance());
- DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
- DependsOn(SigninManagerFactory::GetInstance());
- DependsOn(BookmarkModelFactory::GetInstance());
-}
-
-BookmarkServerClusterServiceFactory::~BookmarkServerClusterServiceFactory() {
-}
-
-// static
-BookmarkServerClusterServiceFactory*
-BookmarkServerClusterServiceFactory::GetInstance() {
- return base::Singleton<BookmarkServerClusterServiceFactory>::get();
-}
-
-// static
-BookmarkServerClusterService*
-BookmarkServerClusterServiceFactory::GetForBrowserContext(
- content::BrowserContext* context) {
- DCHECK(!context->IsOffTheRecord());
- return static_cast<BookmarkServerClusterService*>(
- GetInstance()->GetServiceForBrowserContext(context, true));
-}
-
-KeyedService* BookmarkServerClusterServiceFactory::BuildServiceInstanceFor(
- content::BrowserContext* browser_context) const {
- DCHECK(!browser_context->IsOffTheRecord());
- Profile* profile = Profile::FromBrowserContext(browser_context);
-
- return new BookmarkServerClusterService(
- g_browser_process->GetApplicationLocale(),
- browser_context->GetRequestContext(),
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
- SigninManagerFactory::GetForProfile(profile),
- EnhancedBookmarkModelFactory::GetForBrowserContext(profile),
- ProfileSyncServiceFactory::GetForProfile(profile), profile->GetPrefs());
-}
-
-content::BrowserContext*
-BookmarkServerClusterServiceFactory::GetBrowserContextToUse(
- content::BrowserContext* context) const {
- return chrome::GetBrowserContextRedirectedInIncognito(context);
-}
-
-} // namespace enhanced_bookmarks
diff --git a/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h b/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h
deleted file mode 100644
index e4abc4c..0000000
--- a/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h
+++ /dev/null
@@ -1,46 +0,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.
-
-#ifndef CHROME_BROWSER_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_FACTORY_H_
-#define CHROME_BROWSER_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_FACTORY_H_
-
-#include "base/macros.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace enhanced_bookmarks {
-
-class BookmarkServerClusterService;
-
-// A factory to create one unique BookmarkServerClusterService.
-class BookmarkServerClusterServiceFactory
- : public BrowserContextKeyedServiceFactory {
- public:
- static BookmarkServerClusterServiceFactory* GetInstance();
- static BookmarkServerClusterService* GetForBrowserContext(
- content::BrowserContext* context);
-
- private:
- friend struct base::DefaultSingletonTraits<
- BookmarkServerClusterServiceFactory>;
-
- BookmarkServerClusterServiceFactory();
- ~BookmarkServerClusterServiceFactory() override;
-
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* context) const override;
-
- content::BrowserContext* GetBrowserContextToUse(
- content::BrowserContext* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterServiceFactory);
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // CHROME_BROWSER_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_FACTORY_H_
diff --git a/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc b/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc
deleted file mode 100644
index e546d82..0000000
--- a/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc
+++ /dev/null
@@ -1,56 +0,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/enhanced_bookmarks/enhanced_bookmark_model_factory.h"
-
-#include "base/memory/singleton.h"
-#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/profiles/incognito_helpers.h"
-#include "chrome/browser/profiles/profile.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-#include "components/version_info/version_info.h"
-
-namespace {
-const char kVersionPrefix[] = "chrome.";
-}
-
-namespace enhanced_bookmarks {
-
-EnhancedBookmarkModelFactory::EnhancedBookmarkModelFactory()
- : BrowserContextKeyedServiceFactory(
- "EnhancedBookmarkModel",
- BrowserContextDependencyManager::GetInstance()) {
- DependsOn(BookmarkModelFactory::GetInstance());
-}
-
-// static
-EnhancedBookmarkModelFactory* EnhancedBookmarkModelFactory::GetInstance() {
- return base::Singleton<EnhancedBookmarkModelFactory>::get();
-}
-
-// static
-EnhancedBookmarkModel* EnhancedBookmarkModelFactory::GetForBrowserContext(
- content::BrowserContext* context) {
- DCHECK(!context->IsOffTheRecord());
- return static_cast<EnhancedBookmarkModel*>(
- GetInstance()->GetServiceForBrowserContext(context, true));
-}
-
-KeyedService* EnhancedBookmarkModelFactory::BuildServiceInstanceFor(
- content::BrowserContext* browser_context) const {
- DCHECK(!browser_context->IsOffTheRecord());
- Profile* profile = Profile::FromBrowserContext(browser_context);
-
- return new EnhancedBookmarkModel(
- BookmarkModelFactory::GetForProfile(profile),
- kVersionPrefix + version_info::GetVersionNumber());
-}
-
-content::BrowserContext* EnhancedBookmarkModelFactory::GetBrowserContextToUse(
- content::BrowserContext* context) const {
- return chrome::GetBrowserContextRedirectedInIncognito(context);
-}
-
-} // namespace enhanced_bookmarks
diff --git a/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h b/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h
deleted file mode 100644
index c128287..0000000
--- a/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h
+++ /dev/null
@@ -1,44 +0,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.
-
-#ifndef CHROME_BROWSER_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_FACTORY_H_
-#define CHROME_BROWSER_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_FACTORY_H_
-
-#include "base/macros.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace enhanced_bookmarks {
-
-class EnhancedBookmarkModel;
-
-// A factory to create one unique EnhancedBookmarkModel.
-class EnhancedBookmarkModelFactory : public BrowserContextKeyedServiceFactory {
- public:
- static EnhancedBookmarkModelFactory* GetInstance();
- static EnhancedBookmarkModel* GetForBrowserContext(
- content::BrowserContext* context);
-
- private:
- friend struct base::DefaultSingletonTraits<EnhancedBookmarkModelFactory>;
-
- EnhancedBookmarkModelFactory();
- ~EnhancedBookmarkModelFactory() override {}
-
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* context) const override;
-
- content::BrowserContext* GetBrowserContextToUse(
- content::BrowserContext* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelFactory);
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // CHROME_BROWSER_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_FACTORY_H_
diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
index c5e06c1..88e21f8 100644
--- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
+++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/bookmark_stats.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h"
#include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h"
#include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h"
#include "chrome/browser/extensions/extension_web_ui.h"
@@ -33,7 +32,6 @@
#include "components/bookmarks/browser/scoped_group_bookmark_actions.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
#include "components/undo/bookmark_undo_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/render_view_host.h"
@@ -67,7 +65,6 @@ namespace Paste = api::bookmark_manager_private::Paste;
namespace RedoInfo = api::bookmark_manager_private::GetRedoInfo;
namespace RemoveTrees = api::bookmark_manager_private::RemoveTrees;
namespace SetMetaInfo = api::bookmark_manager_private::SetMetaInfo;
-namespace SetVersion = api::bookmark_manager_private::SetVersion;
namespace SortChildren = api::bookmark_manager_private::SortChildren;
namespace StartDrag = api::bookmark_manager_private::StartDrag;
namespace UndoInfo = api::bookmark_manager_private::GetUndoInfo;
@@ -857,15 +854,4 @@ bool BookmarkManagerPrivateGetRedoInfoFunction::RunOnReady() {
return true;
}
-bool BookmarkManagerPrivateSetVersionFunction::RunOnReady() {
- scoped_ptr<SetVersion::Params> params = SetVersion::Params::Create(*args_);
-
- enhanced_bookmarks::EnhancedBookmarkModel* model =
- enhanced_bookmarks::EnhancedBookmarkModelFactory::GetForBrowserContext(
- browser_context());
- model->SetVersionSuffix(params->version);
-
- return true;
-}
-
} // namespace extensions
diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h
index 5d5ec36..3943a23 100644
--- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h
+++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h
@@ -403,19 +403,6 @@ class BookmarkManagerPrivateGetRedoInfoFunction
bool RunOnReady() override;
};
-class BookmarkManagerPrivateSetVersionFunction
- : public extensions::BookmarksFunction {
- public:
- DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.setVersion",
- BOOKMARKMANAGERPRIVATE_SETVERSION);
-
- protected:
- ~BookmarkManagerPrivateSetVersionFunction() override {}
-
- // ExtensionFunction:
- bool RunOnReady() override;
-};
-
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_BOOKMARK_MANAGER_PRIVATE_BOOKMARK_MANAGER_PRIVATE_API_H_
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 5437797..7e97b67 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -72,7 +72,6 @@
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/dom_distiller/core/distilled_page_prefs.h"
-#include "components/enhanced_bookmarks/bookmark_server_cluster_service.h"
#include "components/flags_ui/pref_service_flags_storage.h"
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/network_time/network_time_tracker.h"
@@ -416,7 +415,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
chrome_prefs::RegisterProfilePrefs(registry);
dom_distiller::DistilledPagePrefs::RegisterProfilePrefs(registry);
DownloadPrefs::RegisterProfilePrefs(registry);
- enhanced_bookmarks::BookmarkServerClusterService::RegisterPrefs(registry);
HostContentSettingsMap::RegisterProfilePrefs(registry);
IncognitoModePrefs::RegisterProfilePrefs(registry);
InstantUI::RegisterProfilePrefs(registry);
diff --git a/chrome/chrome_android.gypi b/chrome/chrome_android.gypi
index 1f1d797f..873487e 100644
--- a/chrome/chrome_android.gypi
+++ b/chrome/chrome_android.gypi
@@ -18,9 +18,6 @@
'chrome.gyp:plugin',
'chrome.gyp:renderer',
'chrome.gyp:utility',
- # TODO(kkimlabs): Move this to chrome.gyp:browser when the dependent
- # is upstreamed.
- '../components/components.gyp:enhanced_bookmarks',
'../content/content.gyp:content',
'../content/content.gyp:content_app_both',
],
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 18eaf1a..f986e4c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1459,10 +1459,6 @@
'browser/bookmarks/managed_bookmark_service_factory.h',
'browser/bookmarks/startup_task_runner_service_factory.cc',
'browser/bookmarks/startup_task_runner_service_factory.h',
- 'browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.cc',
- 'browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h',
- 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc',
- 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h',
],
'chrome_browser_offline_pages_sources': [
'browser/android/offline_pages/offline_page_bridge.cc',
@@ -3153,7 +3149,6 @@
'../components/components.gyp:data_usage_core',
'../components/components.gyp:data_use_measurement_core',
'../components/components.gyp:domain_reliability',
- '../components/components.gyp:enhanced_bookmarks',
'../components/components.gyp:favicon_base',
'../components/components.gyp:favicon_core',
'../components/components.gyp:gcm_driver',
@@ -3752,7 +3747,6 @@
'dependencies': [
'../components/components.gyp:data_reduction_proxy_content',
'../components/components.gyp:data_usage_android',
- '../components/components.gyp:enhanced_bookmarks',
'../components/components.gyp:offline_pages',
'../components/components.gyp:precache_content',
'../components/components.gyp:precache_core',
diff --git a/chrome/common/extensions/api/bookmark_manager_private.json b/chrome/common/extensions/api/bookmark_manager_private.json
index 36015d8..ecd66ef 100644
--- a/chrome/common/extensions/api/bookmark_manager_private.json
+++ b/chrome/common/extensions/api/bookmark_manager_private.json
@@ -404,24 +404,6 @@
]
}
]
- },
- {
- "name": "setVersion",
- "type": "function",
- "description": "Sets the version to use when updating enhanced bookmarks.",
- "parameters": [
- {
- "type": "string",
- "name": "version",
- "description": "The version to set."
- },
- {
- "type": "function",
- "name": "callback",
- "optional": true,
- "parameters": []
- }
- ]
}
],
"events": [
diff --git a/components/BUILD.gn b/components/BUILD.gn
index e8766e7..ad3fab2 100644
--- a/components/BUILD.gn
+++ b/components/BUILD.gn
@@ -230,7 +230,6 @@ test("components_unittests") {
"//components/autofill/core/browser:unit_tests",
"//components/autofill/core/common:unit_tests",
"//components/browser_sync/browser:unit_tests",
- "//components/enhanced_bookmarks:unit_tests",
"//components/favicon/core:unit_tests",
"//components/favicon_base:unit_tests",
"//components/gcm_driver:unit_tests",
diff --git a/components/components_strings.grd b/components/components_strings.grd
index 0a1e1fa..d00786b 100644
--- a/components/components_strings.grd
+++ b/components/components_strings.grd
@@ -191,7 +191,6 @@
<part file="data_reduction_proxy_strings.grdp" />
<part file="dialog_strings.grdp" />
<part file="dom_distiller_strings.grdp" />
- <part file="enhanced_bookmarks_strings.grdp" />
<part file="error_page_strings.grdp" />
<part file="flags_ui_strings.grdp" />
<part file="history_ui_strings.grdp" />
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index de0fda5..1523a53 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -236,12 +236,6 @@
'data_use_measurement_unittest_sources': [
'data_use_measurement/content/data_use_measurement_unittest.cc',
],
- 'enhanced_bookmarks_unittest_sources': [
- 'enhanced_bookmarks/enhanced_bookmark_model_unittest.cc',
- 'enhanced_bookmarks/image_store_ios_unittest.mm',
- 'enhanced_bookmarks/image_store_unittest.cc',
- 'enhanced_bookmarks/item_position_unittest.cc',
- ],
'error_page_unittest_sources': [
'error_page/renderer/net_error_helper_core_unittest.cc',
],
@@ -919,7 +913,6 @@
'<@(device_event_log_unittest_sources)',
'<@(dom_distiller_unittest_sources)',
'<@(domain_reliability_unittest_sources)',
- '<@(enhanced_bookmarks_unittest_sources)',
'<@(favicon_base_unittest_sources)',
'<@(favicon_unittest_sources)',
'<@(flags_ui_unittest_sources)',
@@ -1031,8 +1024,6 @@
'components.gyp:dom_distiller_protos',
'components.gyp:dom_distiller_test_support',
'components.gyp:domain_reliability',
- 'components.gyp:enhanced_bookmarks',
- 'components.gyp:enhanced_bookmarks_test_support',
'components.gyp:favicon_base',
'components.gyp:favicon_core',
'components.gyp:flags_ui',
diff --git a/components/enhanced_bookmarks.gypi b/components/enhanced_bookmarks.gypi
index c95db40..3ebdc60 100644
--- a/components/enhanced_bookmarks.gypi
+++ b/components/enhanced_bookmarks.gypi
@@ -3,97 +3,6 @@
# found in the LICENSE file.
{
- 'targets': [
- {
- # GN: //components/enhanced_bookmarks:enhanced_bookmarks
- 'target_name': 'enhanced_bookmarks',
- 'type': 'static_library',
- 'include_dirs': [
- '..',
- ],
- 'dependencies': [
- '../base/base.gyp:base',
- '../google_apis/google_apis.gyp:google_apis',
- '../net/net.gyp:net',
- '../skia/skia.gyp:skia',
- '../sql/sql.gyp:sql',
- '../ui/gfx/gfx.gyp:gfx',
- '../url/url.gyp:url_lib',
- 'bookmarks_browser',
- 'enhanced_bookmarks_proto',
- 'keyed_service_core',
- 'signin_core_browser',
- 'sync_driver',
- 'variations',
- ],
- 'sources': [
- 'enhanced_bookmarks/bookmark_server_cluster_service.cc',
- 'enhanced_bookmarks/bookmark_server_cluster_service.h',
- 'enhanced_bookmarks/bookmark_server_service.cc',
- 'enhanced_bookmarks/bookmark_server_service.h',
- 'enhanced_bookmarks/enhanced_bookmark_model.cc',
- 'enhanced_bookmarks/enhanced_bookmark_model.h',
- 'enhanced_bookmarks/enhanced_bookmark_model_observer.h',
- 'enhanced_bookmarks/enhanced_bookmark_switches_ios.cc',
- 'enhanced_bookmarks/enhanced_bookmark_switches_ios.h',
- 'enhanced_bookmarks/enhanced_bookmark_utils.cc',
- 'enhanced_bookmarks/enhanced_bookmark_utils.h',
- 'enhanced_bookmarks/image_record.cc',
- 'enhanced_bookmarks/image_record.h',
- 'enhanced_bookmarks/image_store.cc',
- 'enhanced_bookmarks/image_store.h',
- 'enhanced_bookmarks/image_store_util.cc',
- 'enhanced_bookmarks/image_store_util.h',
- 'enhanced_bookmarks/image_store_util_ios.mm',
- 'enhanced_bookmarks/item_position.cc',
- 'enhanced_bookmarks/item_position.h',
- 'enhanced_bookmarks/metadata_accessor.cc',
- 'enhanced_bookmarks/metadata_accessor.h',
- 'enhanced_bookmarks/persistent_image_store.cc',
- 'enhanced_bookmarks/persistent_image_store.h',
- 'enhanced_bookmarks/pref_names.cc',
- 'enhanced_bookmarks/pref_names.h',
- ],
- 'conditions': [
- ['OS=="ios"', {
- 'sources!': [
- 'enhanced_bookmarks/image_store_util.cc',
- ],
- }],
- ],
- },
- {
- # GN: //components/enhanced_bookmarks:enhanced_bookmarks_test_support
- 'target_name': 'enhanced_bookmarks_test_support',
- 'type': 'static_library',
- 'include_dirs': [
- '..',
- ],
- 'dependencies': [
- '../skia/skia.gyp:skia',
- '../testing/gtest.gyp:gtest',
- 'enhanced_bookmarks',
- ],
- 'sources': [
- 'enhanced_bookmarks/test_image_store.cc',
- 'enhanced_bookmarks/test_image_store.h',
- ],
- },
- {
- 'target_name': 'enhanced_bookmarks_proto',
- 'type': 'static_library',
- 'sources': [
- 'enhanced_bookmarks/proto/cluster.proto',
- 'enhanced_bookmarks/proto/metadata.proto',
- 'enhanced_bookmarks/proto/search.proto',
- ],
- 'variables': {
- 'proto_in_dir': './enhanced_bookmarks/proto',
- 'proto_out_dir': 'components/enhanced_bookmarks/proto',
- },
- 'includes': [ '../build/protoc.gypi' ],
- },
- ],
'conditions' : [
['OS=="android"', {
'targets': [
diff --git a/components/enhanced_bookmarks/BUILD.gn b/components/enhanced_bookmarks/BUILD.gn
index 491d0d7..32329bd 100644
--- a/components/enhanced_bookmarks/BUILD.gn
+++ b/components/enhanced_bookmarks/BUILD.gn
@@ -7,63 +7,6 @@ if (is_android) {
import("//build/config/android/rules.gni")
}
-# GYP: //components/enhanced_bookmarks.gypi:enhanced_bookmarks
-source_set("enhanced_bookmarks") {
- sources = [
- "bookmark_server_cluster_service.cc",
- "bookmark_server_cluster_service.h",
- "bookmark_server_service.cc",
- "bookmark_server_service.h",
- "enhanced_bookmark_model.cc",
- "enhanced_bookmark_model.h",
- "enhanced_bookmark_model_observer.h",
- "enhanced_bookmark_switches_ios.cc",
- "enhanced_bookmark_switches_ios.h",
- "enhanced_bookmark_utils.cc",
- "enhanced_bookmark_utils.h",
- "image_record.cc",
- "image_record.h",
- "image_store.cc",
- "image_store.h",
- "image_store_util.cc",
- "image_store_util.h",
- "image_store_util_ios.mm",
- "item_position.cc",
- "item_position.h",
- "metadata_accessor.cc",
- "metadata_accessor.h",
- "persistent_image_store.cc",
- "persistent_image_store.h",
- "pref_names.cc",
- "pref_names.h",
- ]
-
- deps = [
- "//base",
- "//base:prefs",
- "//components/bookmarks/browser",
- "//components/enhanced_bookmarks/proto",
- "//components/keyed_service/core",
- "//components/offline_pages",
- "//components/pref_registry",
- "//components/signin/core/browser",
- "//components/sync_driver",
- "//components/variations",
- "//google_apis",
- "//net",
- "//skia",
- "//sql",
- "//ui/base",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//url",
- ]
-
- if (is_ios) {
- sources -= [ "image_store_util.cc" ]
- }
-}
-
if (is_android) {
# GYP: //components/enhanced_bookmarks.gypi:enhanced_bookmarks_java_enums_srcjar
java_cpp_enum("enhanced_bookmarks_java_enums_srcjar") {
@@ -72,40 +15,3 @@ if (is_android) {
]
}
}
-
-# GYP: //components/enhanced_bookmarks.gypi:enhanced_bookmarks_test_support
-source_set("test_support") {
- testonly = true
- sources = [
- "test_image_store.cc",
- "test_image_store.h",
- ]
-
- public_deps = [
- ":enhanced_bookmarks",
- "//base",
- "//skia",
- "//testing/gtest",
- "//ui/gfx/geometry",
- "//url",
- ]
-}
-
-source_set("unit_tests") {
- testonly = true
- sources = [
- "enhanced_bookmark_model_unittest.cc",
- "image_store_ios_unittest.mm",
- "image_store_unittest.cc",
- "item_position_unittest.cc",
- ]
- deps = [
- ":test_support",
- "//base",
- "//components/bookmarks/browser",
- "//components/bookmarks/test",
- "//components/enhanced_bookmarks/proto",
- "//sql",
- "//ui/gfx",
- ]
-}
diff --git a/components/enhanced_bookmarks/DEPS b/components/enhanced_bookmarks/DEPS
deleted file mode 100644
index 7b597b7..0000000
--- a/components/enhanced_bookmarks/DEPS
+++ /dev/null
@@ -1,15 +0,0 @@
-include_rules = [
- "+components/bookmarks",
- "+components/keyed_service",
- "+components/offline_pages",
- "+components/pref_registry",
- "+components/signin",
- "+components/sync_driver",
- "+components/variations",
- "+google_apis/gaia",
- "+jni",
- "+net",
- "+sql",
- "+third_party/skia",
- "+ui",
-]
diff --git a/components/enhanced_bookmarks/bookmark_server_cluster_service.cc b/components/enhanced_bookmarks/bookmark_server_cluster_service.cc
deleted file mode 100644
index cf34176..0000000
--- a/components/enhanced_bookmarks/bookmark_server_cluster_service.cc
+++ /dev/null
@@ -1,393 +0,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 "components/enhanced_bookmarks/bookmark_server_cluster_service.h"
-
-#include <stddef.h>
-
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/prefs/pref_service.h"
-#include "base/values.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_utils.h"
-#include "components/enhanced_bookmarks/pref_names.h"
-#include "components/enhanced_bookmarks/proto/cluster.pb.h"
-#include "components/pref_registry/pref_registry_syncable.h"
-#include "components/signin/core/browser/signin_manager.h"
-#include "components/sync_driver/sync_service.h"
-#include "net/base/url_util.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_request_context_getter.h"
-
-using bookmarks::BookmarkNode;
-
-namespace {
-const char kClusterUrl[] = "https://www.google.com/stars/cluster";
-const int kPrefServiceVersion = 1;
-const char kPrefServiceVersionKey[] = "version";
-const char kPrefServiceDataKey[] = "data";
-const char kAuthIdKey[] = "auth_id";
-} // namespace
-
-namespace enhanced_bookmarks {
-
-BookmarkServerClusterService::BookmarkServerClusterService(
- const std::string& application_language_code,
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
- ProfileOAuth2TokenService* token_service,
- SigninManagerBase* signin_manager,
- enhanced_bookmarks::EnhancedBookmarkModel* enhanced_bookmark_model,
- sync_driver::SyncService* sync_service,
- PrefService* pref_service)
- : BookmarkServerService(request_context_getter,
- token_service,
- signin_manager,
- enhanced_bookmark_model),
- application_language_code_(application_language_code),
- sync_service_(sync_service),
- pref_service_(pref_service),
- sync_refresh_skipped_(false),
- refreshes_needed_(0) {
- LoadModel();
-
- if (model_->loaded())
- TriggerTokenRequest(false);
-
- GetSigninManager()->AddObserver(this);
- if (sync_service_)
- sync_service_->AddObserver(this);
-}
-
-BookmarkServerClusterService::~BookmarkServerClusterService() {
-}
-
-void BookmarkServerClusterService::Shutdown() {
- if (sync_service_)
- sync_service_->RemoveObserver(this);
- GetSigninManager()->RemoveObserver(this);
-}
-
-const std::vector<const BookmarkNode*>
-BookmarkServerClusterService::BookmarksForClusterNamed(
- const std::string& cluster_name) const {
- std::vector<const BookmarkNode*> results;
-
- ClusterMap::const_iterator cluster_it = cluster_data_.find(cluster_name);
- if (cluster_it == cluster_data_.end())
- return results;
-
- for (auto& star_id : cluster_it->second) {
- const BookmarkNode* bookmark = BookmarkForRemoteId(star_id);
- if (bookmark)
- results.push_back(bookmark);
- }
- return results;
-}
-
-const std::vector<std::string>
-BookmarkServerClusterService::ClustersForBookmark(
- const BookmarkNode* bookmark) const {
- const std::string& star_id = RemoteIDForBookmark(bookmark);
-
- // TODO(noyau): if this turns out to be a perf bottleneck this may be improved
- // by storing a reverse map from id to cluster.
- std::vector<std::string> clusters;
- for (auto& pair : cluster_data_) {
- const std::vector<std::string>& stars_ids = pair.second;
- if (std::find(stars_ids.begin(), stars_ids.end(), star_id) !=
- stars_ids.end())
- clusters.push_back(pair.first);
- }
- return clusters;
-}
-
-const std::vector<std::string> BookmarkServerClusterService::GetClusters()
- const {
- std::vector<std::string> cluster_names;
-
- for (auto& pair : cluster_data_) {
- for (auto& star_id : pair.second) {
- const BookmarkNode* bookmark = BookmarkForRemoteId(star_id);
- if (bookmark) {
- // Only add clusters that have children.
- cluster_names.push_back(pair.first);
- break;
- }
- }
- }
-
- return cluster_names;
-}
-
-void BookmarkServerClusterService::AddObserver(
- enhanced_bookmarks::BookmarkServerServiceObserver* observer) {
- BookmarkServerService::AddObserver(observer);
- if (sync_refresh_skipped_) {
- TriggerTokenRequest(false);
- sync_refresh_skipped_ = true;
- }
-}
-
-// static
-void BookmarkServerClusterService::RegisterPrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterDictionaryPref(prefs::kBookmarkClusters);
-}
-
-scoped_ptr<net::URLFetcher> BookmarkServerClusterService::CreateFetcher() {
- // Add the necessary arguments to the URI.
- GURL url(kClusterUrl);
- url = net::AppendQueryParameter(url, "output", "proto");
-
- // Append language.
- if (!application_language_code_.empty())
- url = net::AppendQueryParameter(url, "hl", application_language_code_);
-
- url = net::AppendQueryParameter(url, "v", model_->GetVersionString());
-
- // Build the URLFetcher to perform the request.
- scoped_ptr<net::URLFetcher> url_fetcher =
- net::URLFetcher::Create(url, net::URLFetcher::POST, this);
-
- // Binary encode a basic request proto.
- image_collections::ClusterRequest request_proto;
- request_proto.set_cluster_all(true);
-
- std::string proto_output;
- bool result = request_proto.SerializePartialToString(&proto_output);
- DCHECK(result);
-
- url_fetcher->SetUploadData("application/octet-stream", proto_output);
- return url_fetcher;
-}
-
-bool BookmarkServerClusterService::ProcessResponse(const std::string& response,
- bool* should_notify) {
- DCHECK(*should_notify);
- image_collections::ClusterResponse response_proto;
- bool result = response_proto.ParseFromString(response);
- if (!result)
- return false; // Not formatted properly.
-
- ClusterMap new_cluster_data;
- for (const auto& cluster : response_proto.clusters()) {
- const std::string& title = cluster.title();
- if (title.empty())
- continue;
- std::vector<std::string> stars_ids;
- for (auto& doc : cluster.docs()) {
- if (!doc.empty())
- stars_ids.push_back(doc);
- }
- if (stars_ids.size())
- new_cluster_data[title] = stars_ids;
- }
-
- if (new_cluster_data.size() == cluster_data_.size() &&
- std::equal(new_cluster_data.begin(),
- new_cluster_data.end(),
- cluster_data_.begin())) {
- *should_notify = false;
- } else {
- SwapModel(&new_cluster_data);
- }
- return true;
-}
-
-void BookmarkServerClusterService::CleanAfterFailure() {
- if (cluster_data_.empty())
- return;
-
- ClusterMap empty;
- SwapModel(&empty);
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkModelLoaded() {
- TriggerTokenRequest(false);
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkAdded(
- const BookmarkNode* node) {
- InvalidateCache();
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkRemoved(
- const BookmarkNode* node) {
- // It is possible to remove the entries from the map here, but as those are
- // filtered in ClustersForBookmark() this is not strictly necessary.
- InvalidateCache();
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkNodeChanged(
- const BookmarkNode* node) {
- InvalidateCache();
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkAllUserNodesRemoved() {
- if (!cluster_data_.empty()) {
- ClusterMap empty;
- SwapModel(&empty);
- }
-}
-
-void BookmarkServerClusterService::EnhancedBookmarkRemoteIdChanged(
- const BookmarkNode* node,
- const std::string& old_remote_id,
- const std::string& remote_id) {
- std::vector<std::string> clusters;
- for (auto& pair : cluster_data_) {
- std::vector<std::string>& stars_ids = pair.second;
- std::replace(stars_ids.begin(), stars_ids.end(), old_remote_id, remote_id);
- }
-}
-
-void BookmarkServerClusterService::GoogleSignedOut(
- const std::string& account_id,
- const std::string& username) {
- if (!cluster_data_.empty()) {
- ClusterMap empty;
- SwapModel(&empty);
- }
-}
-
-void BookmarkServerClusterService::SwapModel(ClusterMap* cluster_map) {
- cluster_data_.swap(*cluster_map);
- const std::string& auth_id = GetSigninManager()->GetAuthenticatedAccountId();
- scoped_ptr<base::DictionaryValue> dictionary(
- Serialize(cluster_data_, auth_id));
- pref_service_->Set(prefs::kBookmarkClusters, *dictionary);
-}
-
-void BookmarkServerClusterService::LoadModel() {
- const base::DictionaryValue* dictionary =
- pref_service_->GetDictionary(prefs::kBookmarkClusters);
- const std::string& auth_id = GetSigninManager()->GetAuthenticatedAccountId();
-
- ClusterMap loaded_data;
- bool result = BookmarkServerClusterService::Deserialize(
- *dictionary, auth_id, &loaded_data);
- if (result)
- cluster_data_.swap(loaded_data);
-}
-
-void BookmarkServerClusterService::OnStateChanged() {
- // Do nothing.
-}
-
-void BookmarkServerClusterService::OnSyncCycleCompleted() {
- // The stars cluster API relies on the information in chrome-sync. Sending a
- // cluster request immediately after a bookmark is changed from the bookmark
- // observer notification will yield the wrong results. The request must be
- // delayed until the sync cycle has completed.
- // Note that we will be skipping calling this cluster API if there is no
- // observer attached, because calling that is meaningless without UI to show.
- // We also will avoid requesting for clusters if the bookmark data hasn't
- // changed.
- if (refreshes_needed_ > 0) {
- DCHECK(model_->loaded());
- if (observers_.might_have_observers()) {
- TriggerTokenRequest(false);
- sync_refresh_skipped_ = false;
- } else {
- sync_refresh_skipped_ = true;
- }
- --refreshes_needed_;
- }
-}
-
-void BookmarkServerClusterService::InvalidateCache() {
- // Bookmark changes can happen locally or via sync. It is difficult to
- // determine if a given SyncCycle contains all the local modifications.
- //
- // Consider the following sequence:
- // 1. SyncCycleBeginning (bookmark version:1)
- // 2. Bookmarks mutate locally (bookmark version:2)
- // 3. SyncCycleCompleted (bookmark version:1)
- //
- // In this case, the bookmarks modified locally won't be sent to the server
- // until the next SyncCycleCompleted. Since we can't accurately determine
- // if a bookmark change has been sent on a SyncCycleCompleted, we're always
- // assuming that we need to wait for 2 sync cycles.
- refreshes_needed_ = 2;
-}
-
-//
-// Serialization.
-//
-// static
-scoped_ptr<base::DictionaryValue> BookmarkServerClusterService::Serialize(
- const ClusterMap& cluster_map,
- const std::string& auth_id) {
- // Create a list of all clusters. For each cluster, make another list. The
- // first element in the list is the key (cluster name). All subsequent
- // elements are stars ids.
- scoped_ptr<base::ListValue> all_clusters(new base::ListValue);
- for (auto& pair : cluster_map) {
- scoped_ptr<base::ListValue> cluster(new base::ListValue);
- cluster->AppendString(pair.first);
- cluster->AppendStrings(pair.second);
- all_clusters->Append(cluster.release());
- }
-
- // The dictionary that will be serialized has two fields: a version field and
- // a data field.
- scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue);
- data->SetInteger(kPrefServiceVersionKey, kPrefServiceVersion);
- data->Set(kPrefServiceDataKey, all_clusters.release());
- data->SetString(kAuthIdKey, auth_id);
-
- return data;
-}
-
-// static
-bool BookmarkServerClusterService::Deserialize(
- const base::DictionaryValue& value,
- const std::string& auth_id,
- ClusterMap* out_map) {
- ClusterMap output;
-
- // Check version.
- int version;
- if (!value.GetInteger(kPrefServiceVersionKey, &version))
- return false;
- if (version != kPrefServiceVersion)
- return false;
-
- // Check auth id.
- std::string id;
- if (!value.GetString(kAuthIdKey, &id))
- return false;
- if (id != auth_id)
- return false;
-
- const base::ListValue* all_clusters = NULL;
- if (!value.GetList(kPrefServiceDataKey, &all_clusters))
- return false;
-
- for (size_t index = 0; index < all_clusters->GetSize(); ++index) {
- const base::ListValue* cluster = NULL;
- if (!all_clusters->GetList(index, &cluster))
- return false;
- if (cluster->GetSize() < 1)
- return false;
- std::string key;
- if (!cluster->GetString(0, &key))
- return false;
- std::vector<std::string> stars_ids;
- for (size_t index = 1; index < cluster->GetSize(); ++index) {
- std::string stars_id;
- if (!cluster->GetString(index, &stars_id))
- return false;
- stars_ids.push_back(stars_id);
- }
- output.insert(std::make_pair(key, stars_ids));
- }
- out_map->swap(output);
- return true;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/bookmark_server_cluster_service.h b/components/enhanced_bookmarks/bookmark_server_cluster_service.h
deleted file mode 100644
index 49192c2..0000000
--- a/components/enhanced_bookmarks/bookmark_server_cluster_service.h
+++ /dev/null
@@ -1,142 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
-
-#include <string>
-#include <vector>
-
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "components/enhanced_bookmarks/bookmark_server_service.h"
-#include "components/signin/core/browser/signin_manager_base.h"
-#include "components/sync_driver/sync_service_observer.h"
-#include "net/url_request/url_fetcher.h"
-
-class PrefService;
-
-namespace sync_driver {
-class SyncService;
-}
-
-namespace enhanced_bookmarks {
-
-// Manages requests to the bookmark server to retrieve the current clustering
-// state for the bookmarks. A cluster is simply a named set of bookmarks related
-// to each others. Invalidates its data when a sync operation finishes.
-class BookmarkServerClusterService : public KeyedService,
- public BookmarkServerService,
- public SigninManagerBase::Observer,
- public sync_driver::SyncServiceObserver {
- public:
- // Maps a cluster name to the stars.id of the bookmarks.
- typedef std::map<std::string, std::vector<std::string>> ClusterMap;
- // |application_language_code| should be a ISO 639-1 compliant string. Aka
- // 'en' or 'en-US'. Note that this code should only specify the language, not
- // the locale, so 'en_US' (english language with US locale) and 'en-GB_US'
- // (British english person in the US) are not language code.
- BookmarkServerClusterService(
- const std::string& application_language_code,
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
- ProfileOAuth2TokenService* token_service,
- SigninManagerBase* signin_manager,
- EnhancedBookmarkModel* enhanced_bookmark_model,
- sync_driver::SyncService* sync_service,
- PrefService* pref_service);
- ~BookmarkServerClusterService() override;
-
- // KeyedService methods.
- void Shutdown() override;
-
- // Retrieves all the bookmarks associated with a cluster. The returned
- // BookmarkNodes are owned by the bookmark model, and one must listen to the
- // model observer notification to clear them.
- const std::vector<const bookmarks::BookmarkNode*> BookmarksForClusterNamed(
- const std::string& cluster_name) const;
-
- // Returns the clusters in which the passed bookmark is in, if any.
- const std::vector<std::string> ClustersForBookmark(
- const bookmarks::BookmarkNode* bookmark) const;
-
- // Dynamically generates a vector of all clusters names.
- const std::vector<std::string> GetClusters() const;
-
- // BookmarkServerService methods.
- void AddObserver(BookmarkServerServiceObserver* observer) override;
-
- // Registers server cluster service prefs.
- static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);
-
- protected:
- // BookmarkServerService methods.
- scoped_ptr<net::URLFetcher> CreateFetcher() override;
- bool ProcessResponse(const std::string& response,
- bool* should_notify) override;
- void CleanAfterFailure() override;
-
- // EnhancedBookmarkModelObserver methods.
- void EnhancedBookmarkModelLoaded() override;
- void EnhancedBookmarkAdded(const bookmarks::BookmarkNode* node) override;
- void EnhancedBookmarkRemoved(const bookmarks::BookmarkNode* node) override;
- void EnhancedBookmarkNodeChanged(
- const bookmarks::BookmarkNode* node) override;
- void EnhancedBookmarkAllUserNodesRemoved() override;
- void EnhancedBookmarkRemoteIdChanged(const bookmarks::BookmarkNode* node,
- const std::string& old_remote_id,
- const std::string& remote_id) override;
-
- private:
- // Overriden from SigninManagerBase::Observer.
- void GoogleSignedOut(const std::string& account_id,
- const std::string& username) override;
-
- // Updates |cluster_data_| with the |cluster_map| and saves the result to
- // profile prefs. All changes to |cluster_data_| should go through this method
- // to ensure profile prefs is always up to date.
- // TODO(noyau): This is probably a misuse of profile prefs. While the expected
- // amount of data is small (<1kb), it can theoretically reach megabytes in
- // size.
- void SwapModel(ClusterMap* cluster_map);
- // Updates |cluster_data_| from profile prefs.
- void LoadModel();
-
- // sync_driver::SyncServiceObserver methods.
- void OnStateChanged() override;
- void OnSyncCycleCompleted() override;
-
- // This sets an internal flag to fetch new clusters.
- void InvalidateCache();
-
- // Serialize the |cluster_map| into the returned dictionary value.. The
- // |auth_id| uniquely identify the signed in user, to avoid deserializing data
- // for a different one.
- static scoped_ptr<base::DictionaryValue> Serialize(
- const ClusterMap& cluster_map,
- const std::string& auth_id);
- // Returns true on success.
- // The result is swapped into |out_map|.
- // |auth_id| must match the serialized auth_id for this method to succeed.
- static bool Deserialize(const base::DictionaryValue& value,
- const std::string& auth_id,
- ClusterMap* out_map);
-
- // The ISO 639-1 code of the language used by the application.
- const std::string application_language_code_;
- // This class observes the sync service for changes.
- sync_driver::SyncService* sync_service_;
- // The preferences services associated with the relevant profile.
- PrefService* pref_service_;
- // The cluster data, a map from cluster name to a vector of stars.id.
- ClusterMap cluster_data_;
- bool sync_refresh_skipped_;
- // This holds the number of cluster refreshes needed.
- int refreshes_needed_;
-
- DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterService);
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
diff --git a/components/enhanced_bookmarks/bookmark_server_service.cc b/components/enhanced_bookmarks/bookmark_server_service.cc
deleted file mode 100644
index 283daee..0000000
--- a/components/enhanced_bookmarks/bookmark_server_service.cc
+++ /dev/null
@@ -1,161 +0,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 "components/enhanced_bookmarks/bookmark_server_service.h"
-
-#include <utility>
-
-#include "base/auto_reset.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
-#include "components/signin/core/browser/profile_oauth2_token_service.h"
-#include "components/signin/core/browser/signin_manager_base.h"
-#include "google_apis/gaia/gaia_constants.h"
-#include "net/base/load_flags.h"
-#include "net/url_request/url_request_context_getter.h"
-#include "ui/base/models/tree_node_iterator.h"
-
-using bookmarks::BookmarkNode;
-
-namespace enhanced_bookmarks {
-
-BookmarkServerService::BookmarkServerService(
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
- ProfileOAuth2TokenService* token_service,
- SigninManagerBase* signin_manager,
- EnhancedBookmarkModel* enhanced_bookmark_model)
- : OAuth2TokenService::Consumer("bookmark_server_service"),
- model_(enhanced_bookmark_model),
- token_service_(token_service),
- signin_manager_(signin_manager),
- request_context_getter_(request_context_getter) {
- DCHECK(request_context_getter.get());
- DCHECK(token_service);
- DCHECK(signin_manager);
- DCHECK(enhanced_bookmark_model);
- model_->AddObserver(this);
-}
-
-BookmarkServerService::~BookmarkServerService() {
- model_->RemoveObserver(this);
-}
-
-void BookmarkServerService::AddObserver(
- BookmarkServerServiceObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void BookmarkServerService::RemoveObserver(
- BookmarkServerServiceObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-const BookmarkNode* BookmarkServerService::BookmarkForRemoteId(
- const std::string& remote_id) const {
- return model_->BookmarkForRemoteId(remote_id);
-}
-
-const std::string BookmarkServerService::RemoteIDForBookmark(
- const BookmarkNode* bookmark) const {
- return model_->GetRemoteId(bookmark);
-}
-
-void BookmarkServerService::Cancel() {
- url_fetcher_.reset();
- token_request_.reset();
-}
-
-void BookmarkServerService::Notify() {
- FOR_EACH_OBSERVER(BookmarkServerServiceObserver, observers_, OnChange(this));
-}
-
-void BookmarkServerService::TriggerTokenRequest(bool cancel_previous) {
- if (cancel_previous)
- url_fetcher_.reset();
-
- if (token_request_ || url_fetcher_)
- return; // Fetcher is already running.
-
- if (!signin_manager_->IsAuthenticated()) {
- // User is not signed in.
- CleanAfterFailure();
- Notify();
- return;
- }
- // Find a token.
- OAuth2TokenService::ScopeSet scopes;
- scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
- token_request_ = token_service_->StartRequest(
- signin_manager_->GetAuthenticatedAccountId(), scopes, this);
-}
-
-//
-// OAuth2AccessTokenConsumer methods.
-//
-void BookmarkServerService::OnGetTokenSuccess(
- const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) {
- url_fetcher_ = CreateFetcher();
-
- // Free the token request.
- token_request_.reset();
-
- if (!url_fetcher_) {
- CleanAfterFailure();
- Notify();
- return;
- }
- url_fetcher_->SetRequestContext(request_context_getter_.get());
-
- // Add the token.
- std::string headers;
- headers = "Authorization: Bearer ";
- headers += access_token;
- headers += "\r\n";
- url_fetcher_->SetExtraRequestHeaders(headers);
-
- // Do not pollute the cookie store with cruft, or mix the users cookie in this
- // request.
- url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
- net::LOAD_DO_NOT_SAVE_COOKIES);
-
- url_fetcher_->Start();
-}
-
-void BookmarkServerService::OnGetTokenFailure(
- const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) {
- // Free the request.
- token_request_.reset();
- CleanAfterFailure();
- Notify();
-}
-
-//
-// net::URLFetcherDelegate methods.
-//
-void BookmarkServerService::OnURLFetchComplete(const net::URLFetcher* source) {
- scoped_ptr<net::URLFetcher> url_fetcher(std::move(url_fetcher_));
- std::string response;
- bool should_notify = true;
-
- if (url_fetcher->GetResponseCode() != 200 ||
- !url_fetcher->GetResponseAsString(&response) ||
- !ProcessResponse(response, &should_notify)) {
- CleanAfterFailure();
- }
- if (should_notify)
- Notify();
-}
-
-void BookmarkServerService::EnhancedBookmarkModelShuttingDown() {
- NOTREACHED();
-}
-
-SigninManagerBase* BookmarkServerService::GetSigninManager() {
- DCHECK(signin_manager_);
- return signin_manager_;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/bookmark_server_service.h b/components/enhanced_bookmarks/bookmark_server_service.h
deleted file mode 100644
index aee0277..0000000
--- a/components/enhanced_bookmarks/bookmark_server_service.h
+++ /dev/null
@@ -1,126 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
-
-#include <string>
-#include <vector>
-
-#include "base/macros.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h"
-#include "google_apis/gaia/google_service_auth_error.h"
-#include "google_apis/gaia/oauth2_token_service.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_fetcher_delegate.h"
-#include "net/url_request/url_request_context_getter.h"
-
-class ProfileOAuth2TokenService;
-class SigninManagerBase;
-
-namespace bookmarks {
-class BookmarkNode;
-}
-
-namespace enhanced_bookmarks {
-
-class BookmarkServerService;
-class EnhancedBookmarkModel;
-
-class BookmarkServerServiceObserver {
- public:
- virtual void OnChange(BookmarkServerService* service) = 0;
-
- protected:
- virtual ~BookmarkServerServiceObserver() {}
-};
-
-// This abstract class manages the connection to the bookmark servers and
-// stores the maps necessary to translate the response from stars.id to
-// BookmarkNodes. Subclasses just have to provide the right query and the
-// parsing of the response.
-class BookmarkServerService : protected net::URLFetcherDelegate,
- private OAuth2TokenService::Consumer,
- public EnhancedBookmarkModelObserver {
- public:
- BookmarkServerService(
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
- ProfileOAuth2TokenService* token_service,
- SigninManagerBase* signin_manager,
- EnhancedBookmarkModel* enhanced_bookmark_model);
- ~BookmarkServerService() override;
-
- virtual void AddObserver(BookmarkServerServiceObserver* observer);
- void RemoveObserver(BookmarkServerServiceObserver* observer);
-
- protected:
- // Retrieves a bookmark by using its remote id. Returns null if nothing
- // matches.
- virtual const bookmarks::BookmarkNode* BookmarkForRemoteId(
- const std::string& remote_id) const;
- const std::string RemoteIDForBookmark(
- const bookmarks::BookmarkNode* bookmark) const;
-
- // Cancels the ongoing request, if any.
- void Cancel();
-
- // Notifies the observers that something changed.
- void Notify();
-
- // Triggers a fetch.
- void TriggerTokenRequest(bool cancel_previous);
-
- // Build the query to send to the server. Returns a newly created url_fetcher.
- virtual scoped_ptr<net::URLFetcher> CreateFetcher() = 0;
-
- // Processes the response to the query. Returns true on successful parsing,
- // false on failure. The implementation can assume that |should_notify| is set
- // to true by default, if changed to false there will be no OnChange
- // notification send.
- virtual bool ProcessResponse(const std::string& response,
- bool* should_notify) = 0;
-
- // If the token can't be retrieved or the query fails this method is called.
- virtual void CleanAfterFailure() = 0;
-
- // EnhancedBookmarkModelObserver:
- void EnhancedBookmarkModelShuttingDown() override;
-
- SigninManagerBase* GetSigninManager();
-
- // Cached pointer to the bookmarks model.
- EnhancedBookmarkModel* model_; // weak
-
- protected:
- // The observers.
- base::ObserverList<BookmarkServerServiceObserver> observers_;
-
- private:
- // net::URLFetcherDelegate methods. Called when the query is finished.
- void OnURLFetchComplete(const net::URLFetcher* source) override;
-
- // OAuth2TokenService::Consumer methods.
- void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) override;
- void OnGetTokenFailure(const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) override;
-
- // The Auth service is used to get a token for auth with the server.
- ProfileOAuth2TokenService* token_service_; // Weak
- // The request to the token service.
- scoped_ptr<OAuth2TokenService::Request> token_request_;
- // To get the currently signed in user.
- SigninManagerBase* signin_manager_; // Weak
- // To have access to the right context getter for the profile.
- scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
- // The fetcher used to query the server.
- scoped_ptr<net::URLFetcher> url_fetcher_;
-
- DISALLOW_COPY_AND_ASSIGN(BookmarkServerService);
-};
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
-
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.cc b/components/enhanced_bookmarks/enhanced_bookmark_model.cc
deleted file mode 100644
index d9088a3..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_model.cc
+++ /dev/null
@@ -1,537 +0,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 "components/enhanced_bookmarks/enhanced_bookmark_model.h"
-
-#include <iomanip>
-#include <sstream>
-
-#include "base/base64.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/rand_util.h"
-#include "base/single_thread_task_runner.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/thread_task_runner_handle.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/bookmarks/browser/bookmark_node.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h"
-#include "components/enhanced_bookmarks/proto/metadata.pb.h"
-#include "ui/base/models/tree_node_iterator.h"
-#include "url/gurl.h"
-
-using bookmarks::BookmarkModel;
-using bookmarks::BookmarkNode;
-
-namespace {
-const char* kBookmarkBarId = "f_bookmarks_bar";
-
-const char* kIdKey = "stars.id";
-const char* kImageDataKey = "stars.imageData";
-const char* kNoteKey = "stars.note";
-const char* kOldIdKey = "stars.oldId";
-const char* kPageDataKey = "stars.pageData";
-const char* kVersionKey = "stars.version";
-
-const char* kBookmarkPrefix = "ebc_";
-
-// Helper method for working with bookmark metainfo.
-std::string DataForMetaInfoField(const BookmarkNode* node,
- const std::string& field) {
- std::string value;
- if (!node->GetMetaInfo(field, &value))
- return std::string();
-
- std::string decoded;
- if (!base::Base64Decode(value, &decoded))
- return std::string();
-
- return decoded;
-}
-
-// Helper method for working with ImageData_ImageInfo.
-bool PopulateImageData(const image::collections::ImageData_ImageInfo& info,
- GURL* out_url,
- int* width,
- int* height) {
- if (!info.has_url() || !info.has_width() || !info.has_height())
- return false;
-
- GURL url(info.url());
- if (!url.is_valid())
- return false;
-
- *out_url = url;
- *width = info.width();
- *height = info.height();
- return true;
-}
-
-// Generate a random remote id, with a prefix that depends on whether the node
-// is a folder or a bookmark.
-std::string GenerateRemoteId() {
- std::stringstream random_id;
- random_id << kBookmarkPrefix;
-
- // Generate 32 digit hex string random suffix.
- random_id << std::hex << std::setfill('0') << std::setw(16);
- random_id << base::RandUint64() << base::RandUint64();
- return random_id.str();
-}
-} // namespace
-
-namespace enhanced_bookmarks {
-
-EnhancedBookmarkModel::EnhancedBookmarkModel(BookmarkModel* bookmark_model,
- const std::string& version)
- : bookmark_model_(bookmark_model),
- loaded_(false),
- version_(version),
- weak_ptr_factory_(this) {
- bookmark_model_->AddObserver(this);
- bookmark_model_->AddNonClonedKey(kIdKey);
- if (bookmark_model_->loaded()) {
- InitializeIdMap();
- loaded_ = true;
- }
-}
-
-EnhancedBookmarkModel::~EnhancedBookmarkModel() {
- Shutdown();
-}
-
-void EnhancedBookmarkModel::Shutdown() {
- if (bookmark_model_) {
- FOR_EACH_OBSERVER(EnhancedBookmarkModelObserver,
- observers_,
- EnhancedBookmarkModelShuttingDown());
- weak_ptr_factory_.InvalidateWeakPtrs();
- bookmark_model_->RemoveObserver(this);
- bookmark_model_ = NULL;
- }
-}
-
-void EnhancedBookmarkModel::AddObserver(
- EnhancedBookmarkModelObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void EnhancedBookmarkModel::RemoveObserver(
- EnhancedBookmarkModelObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-// Moves |node| to |new_parent| and inserts it at the given |index|.
-void EnhancedBookmarkModel::Move(const BookmarkNode* node,
- const BookmarkNode* new_parent,
- int index) {
- bookmark_model_->Move(node, new_parent, index);
-}
-
-// Adds a new folder node at the specified position.
-const BookmarkNode* EnhancedBookmarkModel::AddFolder(
- const BookmarkNode* parent,
- int index,
- const base::string16& title) {
- BookmarkNode::MetaInfoMap meta_info;
- meta_info[kVersionKey] = GetVersionString();
- return bookmark_model_->AddFolderWithMetaInfo(parent, index, title,
- &meta_info);
-}
-
-// Adds a url at the specified position.
-const BookmarkNode* EnhancedBookmarkModel::AddURL(
- const BookmarkNode* parent,
- int index,
- const base::string16& title,
- const GURL& url,
- const base::Time& creation_time) {
- BookmarkNode::MetaInfoMap meta_info;
- meta_info[kIdKey] = GenerateRemoteId();
- meta_info[kVersionKey] = GetVersionString();
- return bookmark_model_->AddURLWithCreationTimeAndMetaInfo(
- parent, index, title, url, creation_time, &meta_info);
-}
-
-std::string EnhancedBookmarkModel::GetRemoteId(const BookmarkNode* node) {
- if (node == bookmark_model_->bookmark_bar_node())
- return kBookmarkBarId;
-
- std::string id;
- if (!node->GetMetaInfo(kIdKey, &id))
- return std::string();
- return id;
-}
-
-const BookmarkNode* EnhancedBookmarkModel::BookmarkForRemoteId(
- const std::string& remote_id) {
- IdToNodeMap::iterator it = id_map_.find(remote_id);
- if (it != id_map_.end())
- return it->second;
- return NULL;
-}
-
-void EnhancedBookmarkModel::SetDescription(const BookmarkNode* node,
- const std::string& description) {
- SetMetaInfo(node, kNoteKey, description);
-}
-
-std::string EnhancedBookmarkModel::GetDescription(const BookmarkNode* node) {
- // First, look for a custom note set by the user.
- std::string description;
- if (node->GetMetaInfo(kNoteKey, &description) && !description.empty())
- return description;
-
- // If none are present, return the snippet.
- return GetSnippet(node);
-}
-
-bool EnhancedBookmarkModel::SetOriginalImage(const BookmarkNode* node,
- const GURL& url,
- int width,
- int height) {
- DCHECK(node->is_url());
- DCHECK(url.is_valid());
-
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- image::collections::ImageData data;
-
- // Try to populate the imageData with the existing data.
- if (!decoded.empty()) {
- // If the parsing fails, something is wrong. Immediately fail.
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
- }
-
- scoped_ptr<image::collections::ImageData_ImageInfo> info(
- new image::collections::ImageData_ImageInfo);
- info->set_url(url.spec());
- info->set_width(width);
- info->set_height(height);
- data.set_allocated_original_info(info.release());
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- if (!result)
- return false;
-
- std::string encoded;
- base::Base64Encode(output, &encoded);
- SetMetaInfo(node, kImageDataKey, encoded);
- return true;
-}
-
-void EnhancedBookmarkModel::RemoveImageData(const BookmarkNode* node) {
- DCHECK(node->is_url());
- image::collections::ImageData data;
- data.set_user_removed_image(true);
-
- std::string encoded_data;
- base::Base64Encode(data.SerializeAsString(), &encoded_data);
- SetMetaInfo(node, kImageDataKey, encoded_data);
-}
-
-bool EnhancedBookmarkModel::GetOriginalImage(const BookmarkNode* node,
- GURL* url,
- int* width,
- int* height) {
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- if (decoded.empty())
- return false;
-
- image::collections::ImageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
-
- if (!data.has_original_info())
- return false;
-
- return PopulateImageData(data.original_info(), url, width, height);
-}
-
-bool EnhancedBookmarkModel::GetThumbnailImage(const BookmarkNode* node,
- GURL* url,
- int* width,
- int* height) {
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- if (decoded.empty())
- return false;
-
- image::collections::ImageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
-
- if (!data.has_thumbnail_info())
- return false;
-
- return PopulateImageData(data.thumbnail_info(), url, width, height);
-}
-
-std::string EnhancedBookmarkModel::GetSnippet(const BookmarkNode* node) {
- std::string decoded(DataForMetaInfoField(node, kPageDataKey));
- if (decoded.empty())
- return decoded;
-
- image::collections::PageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return std::string();
-
- return data.snippet();
-}
-
-void EnhancedBookmarkModel::SetVersionSuffix(
- const std::string& version_suffix) {
- version_suffix_ = version_suffix;
-}
-
-void EnhancedBookmarkModel::BookmarkModelChanged() {
-}
-
-void EnhancedBookmarkModel::BookmarkModelLoaded(BookmarkModel* model,
- bool ids_reassigned) {
- InitializeIdMap();
- loaded_ = true;
- FOR_EACH_OBSERVER(
- EnhancedBookmarkModelObserver, observers_, EnhancedBookmarkModelLoaded());
-}
-
-void EnhancedBookmarkModel::BookmarkNodeAdded(BookmarkModel* model,
- const BookmarkNode* parent,
- int index) {
- const BookmarkNode* node = parent->GetChild(index);
- std::string remote_id;
- if (node->GetMetaInfo(kIdKey, &remote_id)) {
- AddToIdMap(node);
- ScheduleResetDuplicateRemoteIds();
- }
- FOR_EACH_OBSERVER(
- EnhancedBookmarkModelObserver, observers_, EnhancedBookmarkAdded(node));
-}
-
-void EnhancedBookmarkModel::BookmarkNodeRemoved(
- BookmarkModel* model,
- const BookmarkNode* parent,
- int old_index,
- const BookmarkNode* node,
- const std::set<GURL>& removed_urls) {
- RemoveNodeFromMaps(node);
- FOR_EACH_OBSERVER(
- EnhancedBookmarkModelObserver, observers_, EnhancedBookmarkRemoved(node));
-}
-
-void EnhancedBookmarkModel::BookmarkNodeChanged(BookmarkModel* model,
- const BookmarkNode* node) {
- FOR_EACH_OBSERVER(
- EnhancedBookmarkModelObserver, observers_,
- EnhancedBookmarkNodeChanged(node));
-}
-
-void EnhancedBookmarkModel::OnWillChangeBookmarkMetaInfo(
- BookmarkModel* model,
- const BookmarkNode* node) {
- prev_remote_id_ = GetRemoteId(node);
-}
-
-void EnhancedBookmarkModel::BookmarkMetaInfoChanged(BookmarkModel* model,
- const BookmarkNode* node) {
- std::string remote_id = GetRemoteId(node);
- if (remote_id != prev_remote_id_) {
- id_map_.erase(prev_remote_id_);
- if (!remote_id.empty()) {
- AddToIdMap(node);
- ScheduleResetDuplicateRemoteIds();
- }
- FOR_EACH_OBSERVER(
- EnhancedBookmarkModelObserver,
- observers_,
- EnhancedBookmarkRemoteIdChanged(node, prev_remote_id_, remote_id));
- }
-}
-
-void EnhancedBookmarkModel::BookmarkAllUserNodesRemoved(
- BookmarkModel* model,
- const std::set<GURL>& removed_urls) {
- id_map_.clear();
- // Re-initialize so non-user nodes with remote ids are present in the map.
- InitializeIdMap();
- FOR_EACH_OBSERVER(EnhancedBookmarkModelObserver,
- observers_,
- EnhancedBookmarkAllUserNodesRemoved());
-}
-
-void EnhancedBookmarkModel::InitializeIdMap() {
- ui::TreeNodeIterator<const BookmarkNode> iterator(
- bookmark_model_->root_node());
- while (iterator.has_next()) {
- AddToIdMap(iterator.Next());
- }
- ScheduleResetDuplicateRemoteIds();
-}
-
-void EnhancedBookmarkModel::AddToIdMap(const BookmarkNode* node) {
- std::string remote_id = GetRemoteId(node);
- if (remote_id.empty())
- return;
-
- // Try to insert the node.
- std::pair<IdToNodeMap::iterator, bool> result =
- id_map_.insert(make_pair(remote_id, node));
- if (!result.second) {
- // Some node already had the same remote id, so add both nodes to the
- // to-be-reset set.
- nodes_to_reset_[result.first->second] = remote_id;
- nodes_to_reset_[node] = remote_id;
- }
-}
-
-void EnhancedBookmarkModel::RemoveNodeFromMaps(const BookmarkNode* node) {
- for (int i = 0; i < node->child_count(); i++) {
- RemoveNodeFromMaps(node->GetChild(i));
- }
- std::string remote_id = GetRemoteId(node);
- id_map_.erase(remote_id);
- nodes_to_reset_.erase(node);
-}
-
-void EnhancedBookmarkModel::ScheduleResetDuplicateRemoteIds() {
- if (!nodes_to_reset_.empty()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&EnhancedBookmarkModel::ResetDuplicateRemoteIds,
- weak_ptr_factory_.GetWeakPtr()));
- }
-}
-
-void EnhancedBookmarkModel::ResetDuplicateRemoteIds() {
- for (NodeToIdMap::iterator it = nodes_to_reset_.begin();
- it != nodes_to_reset_.end();
- ++it) {
- BookmarkNode::MetaInfoMap meta_info;
- meta_info[kIdKey] = "";
- meta_info[kOldIdKey] = it->second;
- SetMultipleMetaInfo(it->first, meta_info);
- }
- nodes_to_reset_.clear();
-}
-
-void EnhancedBookmarkModel::SetMetaInfo(const BookmarkNode* node,
- const std::string& field,
- const std::string& value) {
- DCHECK(!bookmark_model_->is_permanent_node(node));
-
- BookmarkNode::MetaInfoMap meta_info;
- const BookmarkNode::MetaInfoMap* old_meta_info = node->GetMetaInfoMap();
- if (old_meta_info)
- meta_info.insert(old_meta_info->begin(), old_meta_info->end());
-
- // Don't update anything if the value to set is already there.
- BookmarkNode::MetaInfoMap::iterator it = meta_info.find(field);
- if (it != meta_info.end() && it->second == value)
- return;
-
- meta_info[field] = value;
- meta_info[kVersionKey] = GetVersionString();
- bookmark_model_->SetNodeMetaInfoMap(node, meta_info);
-}
-
-std::string EnhancedBookmarkModel::GetVersionString() {
- if (version_suffix_.empty())
- return version_;
- return version_ + '/' + version_suffix_;
-}
-
-void EnhancedBookmarkModel::SetMultipleMetaInfo(
- const BookmarkNode* node,
- BookmarkNode::MetaInfoMap meta_info) {
- DCHECK(!bookmark_model_->is_permanent_node(node));
-
- // Don't update anything if every value is already set correctly.
- if (node->GetMetaInfoMap()) {
- bool changed = false;
- const BookmarkNode::MetaInfoMap* old_meta_info = node->GetMetaInfoMap();
- for (BookmarkNode::MetaInfoMap::iterator it = meta_info.begin();
- it != meta_info.end();
- ++it) {
- BookmarkNode::MetaInfoMap::const_iterator old_field =
- old_meta_info->find(it->first);
- if (old_field == old_meta_info->end() ||
- old_field->second != it->second) {
- changed = true;
- break;
- }
- }
- if (!changed)
- return;
-
- // Fill in the values that aren't changing
- meta_info.insert(old_meta_info->begin(), old_meta_info->end());
- }
-
- meta_info[kVersionKey] = GetVersionString();
- bookmark_model_->SetNodeMetaInfoMap(node, meta_info);
-}
-
-bool EnhancedBookmarkModel::SetAllImages(const BookmarkNode* node,
- const GURL& image_url,
- int image_width,
- int image_height,
- const GURL& thumbnail_url,
- int thumbnail_width,
- int thumbnail_height) {
- DCHECK(node->is_url());
- DCHECK(image_url.is_valid() || image_url.is_empty());
- DCHECK(thumbnail_url.is_valid() || thumbnail_url.is_empty());
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- image::collections::ImageData data;
-
- // Try to populate the imageData with the existing data.
- if (!decoded.empty()) {
- // If the parsing fails, something is wrong. Immediately fail.
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
- }
-
- if (image_url.is_empty()) {
- data.release_original_info();
- } else {
- // Regardless of whether an image info exists, we make a new one.
- // Intentially make a raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url(image_url.spec());
- info->set_width(image_width);
- info->set_height(image_height);
- // This method consumes the raw pointer.
- data.set_allocated_original_info(info);
- }
-
- if (thumbnail_url.is_empty()) {
- data.release_thumbnail_info();
- } else {
- // Regardless of whether an image info exists, we make a new one.
- // Intentially make a raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url(thumbnail_url.spec());
- info->set_width(thumbnail_width);
- info->set_height(thumbnail_height);
- // This method consumes the raw pointer.
- data.set_allocated_thumbnail_info(info);
- }
- std::string output;
- bool result = data.SerializePartialToString(&output);
- if (!result)
- return false;
-
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, kImageDataKey, encoded);
- return true;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.h b/components/enhanced_bookmarks/enhanced_bookmark_model.h
deleted file mode 100644
index 3e4c8e5..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_model.h
+++ /dev/null
@@ -1,222 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_
-
-#include <map>
-#include <string>
-
-#include "base/cancelable_callback.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/linked_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/observer_list.h"
-#include "base/strings/string16.h"
-#include "components/bookmarks/browser/base_bookmark_model_observer.h"
-#include "components/bookmarks/browser/bookmark_node.h"
-#include "components/keyed_service/core/keyed_service.h"
-
-class GURL;
-
-namespace base {
-class Time;
-}
-
-namespace bookmarks {
-class BookmarkModel;
-class BookmarkNode;
-}
-
-FORWARD_DECLARE_TEST(EnhancedBookmarkModelTest, SetMultipleMetaInfo);
-
-namespace enhanced_bookmarks {
-
-class EnhancedBookmarkModelObserver;
-
-// Wrapper around BookmarkModel providing utility functions for enhanced
-// bookmarks.
-class EnhancedBookmarkModel : public KeyedService,
- public bookmarks::BaseBookmarkModelObserver {
- public:
- EnhancedBookmarkModel(bookmarks::BookmarkModel* bookmark_model,
- const std::string& version);
- ~EnhancedBookmarkModel() override;
-
- void Shutdown() override;
-
- void AddObserver(EnhancedBookmarkModelObserver* observer);
- void RemoveObserver(EnhancedBookmarkModelObserver* observer);
-
- // Moves |node| to |new_parent| and inserts it at the given |index|.
- void Move(const bookmarks::BookmarkNode* node,
- const bookmarks::BookmarkNode* new_parent,
- int index);
-
- // Adds a new folder node at the specified position.
- const bookmarks::BookmarkNode* AddFolder(
- const bookmarks::BookmarkNode* parent,
- int index,
- const base::string16& title);
-
- // Adds a url at the specified position.
- const bookmarks::BookmarkNode* AddURL(const bookmarks::BookmarkNode* parent,
- int index,
- const base::string16& title,
- const GURL& url,
- const base::Time& creation_time);
-
- // Returns the remote id for a bookmark |node|.
- std::string GetRemoteId(const bookmarks::BookmarkNode* node);
-
- // Returns the bookmark node corresponding to the given |remote_id|, or NULL
- // if there is no node with the id.
- const bookmarks::BookmarkNode* BookmarkForRemoteId(
- const std::string& remote_id);
-
- // Sets the description of a bookmark |node|.
- void SetDescription(const bookmarks::BookmarkNode* node,
- const std::string& description);
-
- // Returns the description of a bookmark |node|.
- std::string GetDescription(const bookmarks::BookmarkNode* node);
-
- // Sets the URL of an image representative of a bookmark |node|.
- // Expects the URL to be valid and not empty.
- // Returns true if the metainfo is successfully populated.
- bool SetOriginalImage(const bookmarks::BookmarkNode* node,
- const GURL& url,
- int width,
- int height);
-
- // Removes all image data for the node and sets the user_removed_image flag
- // so the server won't try to fetch a new image for the node.
- void RemoveImageData(const bookmarks::BookmarkNode* node);
-
- // Returns the url and dimensions of the original scraped image of a
- // bookmark |node|.
- // Returns true if the out variables are populated, false otherwise.
- bool GetOriginalImage(const bookmarks::BookmarkNode* node,
- GURL* url,
- int* width,
- int* height);
-
- // Returns the url and dimensions of the server provided thumbnail image for
- // a given bookmark |node|.
- // Returns true if the out variables are populated, false otherwise.
- bool GetThumbnailImage(const bookmarks::BookmarkNode* node,
- GURL* url,
- int* width,
- int* height);
-
- // Returns a brief server provided synopsis of the bookmarked page.
- // Returns the empty string if the snippet could not be extracted.
- std::string GetSnippet(const bookmarks::BookmarkNode* node);
-
- // Sets a custom suffix to be added to the version field when writing meta
- // info fields.
- void SetVersionSuffix(const std::string& version_suffix);
-
- // TODO(rfevang): Add method + enum for accessing/writing flags.
-
- // Used for testing, simulates the process that creates the thumbnails. Will
- // remove existing entries for empty urls or set them if the url is not empty.
- // Expects valid or empty urls. Returns true if the metainfo is successfully
- // populated.
- // TODO(rfevang): Move this to a testing only utility file.
- bool SetAllImages(const bookmarks::BookmarkNode* node,
- const GURL& image_url,
- int image_width,
- int image_height,
- const GURL& thumbnail_url,
- int thumbnail_width,
- int thumbnail_height);
-
- // TODO(rfevang): Ideally nothing should need the underlying bookmark model.
- // Remove when that is actually the case.
- bookmarks::BookmarkModel* bookmark_model() { return bookmark_model_; }
-
- // Returns true if the enhanced bookmark model is done loading.
- bool loaded() { return loaded_; }
-
- // Returns the version string to use when setting stars.version.
- std::string GetVersionString();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(::EnhancedBookmarkModelTest, SetMultipleMetaInfo);
-
- typedef std::map<std::string, const bookmarks::BookmarkNode*> IdToNodeMap;
- typedef std::map<const bookmarks::BookmarkNode*, std::string> NodeToIdMap;
-
- // bookmarks::BaseBookmarkModelObserver:
- void BookmarkModelChanged() override;
- void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
- bool ids_reassigned) override;
- void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* parent,
- int index) override;
- void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* parent,
- int old_index,
- const bookmarks::BookmarkNode* node,
- const std::set<GURL>& removed_urls) override;
- void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* node) override;
- void OnWillChangeBookmarkMetaInfo(
- bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* node) override;
- void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* node) override;
- void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
- const std::set<GURL>& removed_urls) override;
-
- // Initialize the mapping from remote ids to nodes.
- void InitializeIdMap();
-
- // Adds a node to the id map if it has a (unique) remote id. Must be followed
- // by a (Schedule)ResetDuplicateRemoteIds call when done adding nodes.
- void AddToIdMap(const bookmarks::BookmarkNode* node);
-
- // Recursively removes a node and all its children from the various maps.
- void RemoveNodeFromMaps(const bookmarks::BookmarkNode* node);
-
- // If there are nodes that needs to reset their remote ids, schedules
- // ResetDuplicateRemoteIds to be run asynchronously.
- void ScheduleResetDuplicateRemoteIds();
-
- // Clears out any duplicate remote ids detected by AddToIdMap calls.
- void ResetDuplicateRemoteIds();
-
- // Helper method for setting a meta info field on a node. Also updates the
- // version field.
- void SetMetaInfo(const bookmarks::BookmarkNode* node,
- const std::string& field,
- const std::string& value);
-
- // Helper method for setting multiple meta info fields at once. All the fields
- // in |meta_info| will be set, but the method will not delete fields not
- // present.
- void SetMultipleMetaInfo(const bookmarks::BookmarkNode* node,
- bookmarks::BookmarkNode::MetaInfoMap meta_info);
-
- bookmarks::BookmarkModel* bookmark_model_;
- bool loaded_;
-
- base::ObserverList<EnhancedBookmarkModelObserver> observers_;
-
- IdToNodeMap id_map_;
- NodeToIdMap nodes_to_reset_;
-
- // Caches the remote id of a node before its meta info changes.
- std::string prev_remote_id_;
-
- std::string version_;
- std::string version_suffix_;
-
- base::WeakPtrFactory<EnhancedBookmarkModel> weak_ptr_factory_;
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model_observer.h b/components/enhanced_bookmarks/enhanced_bookmark_model_observer.h
deleted file mode 100644
index 45714fb..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_model_observer.h
+++ /dev/null
@@ -1,51 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_OBSERVER_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_OBSERVER_H_
-
-#include <string>
-
-namespace bookmarks {
-class BookmarkNode;
-}
-
-namespace enhanced_bookmarks {
-
-class EnhancedBookmarkModelObserver {
- public:
- // Called when the model has finished loading.
- virtual void EnhancedBookmarkModelLoaded() = 0;
-
- // Called from EnhancedBookmarkModel::ShutDown.
- virtual void EnhancedBookmarkModelShuttingDown() = 0;
-
- // Called when a node is added to the model.
- virtual void EnhancedBookmarkAdded(const bookmarks::BookmarkNode* node) = 0;
-
- // Called when a node is removed from the model.
- virtual void EnhancedBookmarkRemoved(const bookmarks::BookmarkNode* node) = 0;
-
- // Called when a node has changed.
- virtual void EnhancedBookmarkNodeChanged(
- const bookmarks::BookmarkNode* node) = 0;
-
- // Called when all user editable nodes are removed from the model.
- virtual void EnhancedBookmarkAllUserNodesRemoved() = 0;
-
- // Called when the remote id of a node changes. If |remote_id| is empty, the
- // remote id has been cleared. This could happen if multiple nodes with the
- // same remote id has been detected.
- virtual void EnhancedBookmarkRemoteIdChanged(
- const bookmarks::BookmarkNode* node,
- const std::string& old_remote_id,
- const std::string& remote_id) {}
-
- protected:
- virtual ~EnhancedBookmarkModelObserver() {}
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_OBSERVER_H_
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc b/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc
deleted file mode 100644
index d953a27..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc
+++ /dev/null
@@ -1,718 +0,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 "components/enhanced_bookmarks/enhanced_bookmark_model.h"
-
-#include "base/base64.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/bookmarks/browser/bookmark_node.h"
-#include "components/bookmarks/test/test_bookmark_client.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h"
-#include "components/enhanced_bookmarks/proto/metadata.pb.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-using bookmarks::BookmarkModel;
-using bookmarks::BookmarkNode;
-using enhanced_bookmarks::EnhancedBookmarkModel;
-
-namespace {
-const std::string BOOKMARK_URL("http://example.com/index.html");
-const std::string IMAGE_URL("http://example.com/image.jpg");
-} // namespace
-
-class EnhancedBookmarkModelTest
- : public testing::Test,
- public enhanced_bookmarks::EnhancedBookmarkModelObserver {
- public:
- EnhancedBookmarkModelTest()
- : loaded_calls_(0),
- shutting_down_calls_(0),
- added_calls_(0),
- removed_calls_(0),
- changed_calls_(0),
- all_user_nodes_removed_calls_(0),
- remote_id_changed_calls_(0),
- last_added_(NULL),
- last_removed_(NULL),
- last_changed_(NULL),
- last_remote_id_node_(NULL) {}
- ~EnhancedBookmarkModelTest() override {}
-
- void SetUp() override {
- message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
- bookmark_client_.reset(new bookmarks::TestBookmarkClient());
- bookmark_model_.reset(bookmark_client_->CreateModel().release());
- model_.reset(new EnhancedBookmarkModel(bookmark_model_.get(), "v1.0"));
- model_->AddObserver(this);
- }
-
- void TearDown() override {
- if (model_)
- model_->Shutdown();
- model_.reset();
- bookmark_model_.reset();
- bookmark_client_.reset();
- message_loop_.reset();
- }
-
- protected:
- const BookmarkNode* AddBookmark() {
- return AddBookmark("Some title", bookmark_model_->other_node());
- }
-
- const BookmarkNode* AddFolder() {
- return AddFolder("Some title", bookmark_model_->other_node());
- }
-
- const BookmarkNode* AddBookmark(const std::string& name,
- const BookmarkNode* parent) {
- return model_->AddURL(parent,
- 0, // index.
- base::ASCIIToUTF16(name),
- GURL(BOOKMARK_URL),
- base::Time::Now());
- }
-
- const BookmarkNode* AddFolder(const std::string& name,
- const BookmarkNode* parent) {
- return model_->AddFolder(parent, 0, base::ASCIIToUTF16(name));
- }
-
- std::string GetVersion(const BookmarkNode* node) {
- return GetMetaInfoField(node, "stars.version");
- }
-
- std::string GetId(const BookmarkNode* node) {
- return GetMetaInfoField(node, "stars.id");
- }
-
- std::string GetOldId(const BookmarkNode* node) {
- return GetMetaInfoField(node, "stars.oldId");
- }
-
- std::string GetMetaInfoField(const BookmarkNode* node,
- const std::string& name) {
- std::string value;
- if (!node->GetMetaInfo(name, &value))
- return std::string();
- return value;
- }
-
- scoped_ptr<base::MessageLoop> message_loop_;
- scoped_ptr<bookmarks::TestBookmarkClient> bookmark_client_;
- scoped_ptr<BookmarkModel> bookmark_model_;
- scoped_ptr<EnhancedBookmarkModel> model_;
-
- // EnhancedBookmarkModelObserver implementation:
- void EnhancedBookmarkModelLoaded() override { loaded_calls_++; }
- void EnhancedBookmarkModelShuttingDown() override { shutting_down_calls_++; }
- void EnhancedBookmarkAdded(const BookmarkNode* node) override {
- added_calls_++;
- last_added_ = node;
- }
- void EnhancedBookmarkRemoved(const BookmarkNode* node) override {
- removed_calls_++;
- last_removed_ = node;
- }
- void EnhancedBookmarkNodeChanged(const BookmarkNode* node) override {
- changed_calls_++;
- last_changed_ = node;
- }
- void EnhancedBookmarkAllUserNodesRemoved() override {
- all_user_nodes_removed_calls_++;
- }
- void EnhancedBookmarkRemoteIdChanged(const BookmarkNode* node,
- const std::string& old_remote_id,
- const std::string& remote_id) override {
- remote_id_changed_calls_++;
- last_remote_id_node_ = node;
- last_old_remote_id_ = old_remote_id;
- last_remote_id_ = remote_id;
- }
-
- // Observer call counters:
- int loaded_calls_;
- int shutting_down_calls_;
- int added_calls_;
- int removed_calls_;
- int changed_calls_;
- int all_user_nodes_removed_calls_;
- int remote_id_changed_calls_;
-
- // Observer parameter cache:
- const BookmarkNode* last_added_;
- const BookmarkNode* last_removed_;
- const BookmarkNode* last_changed_;
- const BookmarkNode* last_remote_id_node_;
- std::string last_old_remote_id_;
- std::string last_remote_id_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelTest);
-};
-
-TEST_F(EnhancedBookmarkModelTest, TestEmptySnippet) {
- const BookmarkNode* node = AddBookmark();
-
- std::string snippet(model_->GetSnippet(node));
- EXPECT_EQ(snippet, "");
-};
-
-TEST_F(EnhancedBookmarkModelTest, TestSnippet) {
- const BookmarkNode* node = AddBookmark();
-
- // Binary serialize the protobuf.
- image::collections::PageData data;
- data.set_snippet("I'm happy!");
- ASSERT_TRUE(data.IsInitialized());
- std::string output;
- bool result = data.SerializeToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded);
-
- std::string snippet(model_->GetSnippet(node));
- EXPECT_EQ(snippet, "I'm happy!");
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestBadEncodingSnippet) {
- const BookmarkNode* node = AddBookmark();
-
- // Binary serialize the protobuf.
- image::collections::PageData data;
- data.set_snippet("You are happy!");
- ASSERT_TRUE(data.IsInitialized());
- std::string output;
- bool result = data.SerializeToString(&output);
- ASSERT_TRUE(result);
-
- // don't base 64 encode the output.
- bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", output);
-
- std::string snippet(model_->GetSnippet(node));
- EXPECT_EQ(snippet, "");
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestOriginalImage) {
- const BookmarkNode* node = AddBookmark();
-
- image::collections::ImageData data;
- // Intentionally make raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url("http://example.com/foobar");
- info->set_width(15);
- info->set_height(55);
- // This method consumes the pointer.
- data.set_allocated_original_info(info);
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded);
-
- GURL url;
- int width;
- int height;
- result = model_->GetOriginalImage(node, &url, &width, &height);
- ASSERT_TRUE(result);
- EXPECT_EQ(url, GURL("http://example.com/foobar"));
- EXPECT_EQ(width, 15);
- EXPECT_EQ(height, 55);
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestThumbnailImage) {
- const BookmarkNode* node = AddBookmark();
-
- image::collections::ImageData data;
- // Intentionally make raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url("http://example.com/foobar");
- info->set_width(15);
- info->set_height(55);
- // This method consumes the pointer.
- data.set_allocated_thumbnail_info(info);
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded);
-
- GURL url;
- int width;
- int height;
- result = model_->GetThumbnailImage(node, &url, &width, &height);
- ASSERT_TRUE(result);
- EXPECT_EQ(url, GURL("http://example.com/foobar"));
- EXPECT_EQ(width, 15);
- EXPECT_EQ(height, 55);
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestOriginalImageMissingDimensions) {
- const BookmarkNode* node = AddBookmark();
-
- image::collections::ImageData data;
- // Intentionally make raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url("http://example.com/foobar");
- // This method consumes the pointer.
- data.set_allocated_original_info(info);
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded);
-
- GURL url;
- int width;
- int height;
- result = model_->GetOriginalImage(node, &url, &width, &height);
- ASSERT_FALSE(result);
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestOriginalImageBadUrl) {
- const BookmarkNode* node = AddBookmark();
-
- image::collections::ImageData data;
- // Intentionally make raw pointer.
- image::collections::ImageData_ImageInfo* info =
- new image::collections::ImageData_ImageInfo;
- info->set_url("asdf. 13r");
- info->set_width(15);
- info->set_height(55);
- // This method consumes the pointer.
- data.set_allocated_original_info(info);
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded);
-
- GURL url;
- int width;
- int height;
- result = model_->GetOriginalImage(node, &url, &width, &height);
- ASSERT_FALSE(result);
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestEncodeDecode) {
- const BookmarkNode* node = AddBookmark();
-
- bool result =
- model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 22, 33);
- ASSERT_TRUE(result);
-
- GURL url;
- int width;
- int height;
- result = model_->GetOriginalImage(node, &url, &width, &height);
- ASSERT_TRUE(result);
- EXPECT_EQ(url, GURL("http://example.com/i.jpg"));
- EXPECT_EQ(width, 22);
- EXPECT_EQ(height, 33);
- EXPECT_EQ("v1.0", GetVersion(node));
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestDoubleEncodeDecode) {
- const BookmarkNode* node = AddBookmark();
-
- // Encode some information.
- bool result =
- model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 22, 33);
- ASSERT_TRUE(result);
- // Encode some different information.
- result =
- model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 33, 44);
- ASSERT_TRUE(result);
-
- GURL url;
- int width;
- int height;
- result = model_->GetOriginalImage(node, &url, &width, &height);
- ASSERT_TRUE(result);
- EXPECT_EQ(url, GURL("http://example.com/i.jpg"));
- EXPECT_EQ(width, 33);
- EXPECT_EQ(height, 44);
- EXPECT_EQ("v1.0", GetVersion(node));
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestRemoteId) {
- const BookmarkNode* node = AddBookmark();
- // Verify that the remote id starts with the correct prefix.
- EXPECT_TRUE(base::StartsWith(model_->GetRemoteId(node), "ebc_",
- base::CompareCase::SENSITIVE));
-
- // Getting the remote id for nodes that don't have them should return the
- // empty string.
- const BookmarkNode* existing_node =
- bookmark_model_->AddURL(bookmark_model_->other_node(),
- 0,
- base::ASCIIToUTF16("Title"),
- GURL(GURL(BOOKMARK_URL)));
- EXPECT_TRUE(model_->GetRemoteId(existing_node).empty());
-
- // Folder nodes should not have a remote id set on creation.
- const BookmarkNode* folder_node = AddFolder();
- EXPECT_TRUE(model_->GetRemoteId(folder_node).empty());
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestEmptyDescription) {
- const BookmarkNode* node = AddBookmark();
-
- std::string description(model_->GetDescription(node));
- EXPECT_EQ(description, "");
-}
-
-TEST_F(EnhancedBookmarkModelTest, TestDescription) {
- const BookmarkNode* node = AddBookmark();
- const std::string description("This is the most useful description of all.");
-
- // Set the description.
- model_->SetDescription(node, description);
-
- // Check the description is the one that was set.
- EXPECT_EQ(model_->GetDescription(node), description);
- EXPECT_EQ("v1.0", GetVersion(node));
-}
-
-// If there is no notes field, the description should fall back on the snippet.
-TEST_F(EnhancedBookmarkModelTest, TestDescriptionFallback) {
- const BookmarkNode* node = AddBookmark();
-
- // Binary serialize the protobuf.
- image::collections::PageData data;
- data.set_snippet("Joe Bar Team");
- ASSERT_TRUE(data.IsInitialized());
- std::string output;
- bool result = data.SerializeToString(&output);
- ASSERT_TRUE(result);
-
- // base64 encode the output.
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded);
-
- // The snippet is used as the description.
- std::string snippet(model_->GetSnippet(node));
- EXPECT_EQ("Joe Bar Team", model_->GetDescription(node));
-
- // Set the description.
- const std::string description("This is the most useful description of all.");
- model_->SetDescription(node, description);
-
- // Check the description is the one that was set.
- EXPECT_EQ(model_->GetDescription(node), description);
-}
-
-// Makes sure that the stars.version field is set every time
-// EnhancedBookmarkModel makes a change to a node.
-TEST_F(EnhancedBookmarkModelTest, TestVersionField) {
- const BookmarkNode* node =
- bookmark_model_->AddURL(bookmark_model_->other_node(), 0,
- base::ASCIIToUTF16("Title"), GURL(BOOKMARK_URL));
- EXPECT_EQ("", GetVersion(node));
-
- model_->SetDescription(node, "foo");
- EXPECT_EQ("v1.0", GetVersion(node));
-
- // Add a suffix to the version to set.
- model_->SetVersionSuffix("alpha");
-
- model_->SetDescription(node, "foo");
- // Since the description didn't actually change, the version field should
- // not either.
- EXPECT_EQ("v1.0", GetVersion(node));
-
- model_->SetDescription(node, "bar");
- EXPECT_EQ("v1.0/alpha", GetVersion(node));
-}
-
-// Verifies that duplicate nodes are reset when the model is created.
-TEST_F(EnhancedBookmarkModelTest, ResetDuplicateNodesOnInitialization) {
- model_->Shutdown();
-
- const BookmarkNode* parent = bookmark_model_->other_node();
- const BookmarkNode* node1 = bookmark_model_->AddURL(
- parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL));
- const BookmarkNode* node2 = bookmark_model_->AddURL(
- parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL));
- const BookmarkNode* node3 = bookmark_model_->AddURL(
- parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL));
- const BookmarkNode* node4 = bookmark_model_->AddURL(
- parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL));
-
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1");
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_2");
- bookmark_model_->SetNodeMetaInfo(node3, "stars.id", "c_1");
- bookmark_model_->SetNodeMetaInfo(node4, "stars.id", "c_1");
- EXPECT_EQ("c_1", GetId(node1));
- EXPECT_EQ("c_2", GetId(node2));
- EXPECT_EQ("c_1", GetId(node3));
- EXPECT_EQ("c_1", GetId(node4));
-
- model_.reset(new EnhancedBookmarkModel(bookmark_model_.get(), "v2.0"));
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ("c_2", GetId(node2));
- EXPECT_EQ("", GetId(node1));
- EXPECT_EQ("", GetId(node3));
- EXPECT_EQ("", GetId(node4));
- EXPECT_EQ("c_1", GetOldId(node1));
- EXPECT_EQ("c_1", GetOldId(node3));
- EXPECT_EQ("c_1", GetOldId(node4));
- EXPECT_EQ("v2.0", GetVersion(node1));
- EXPECT_EQ("v2.0", GetVersion(node3));
- EXPECT_EQ("v2.0", GetVersion(node4));
-}
-
-// Verifies that duplicate nodes are reset if one is created.
-TEST_F(EnhancedBookmarkModelTest, ResetDuplicateAddedNodes) {
- BookmarkNode::MetaInfoMap meta_info;
- meta_info["stars.id"] = "c_1";
- const BookmarkNode* parent = bookmark_model_->other_node();
-
- const BookmarkNode* node1 =
- bookmark_model_->AddURLWithCreationTimeAndMetaInfo(
- parent,
- 0,
- base::ASCIIToUTF16("Some title"),
- GURL(BOOKMARK_URL),
- base::Time::Now(),
- &meta_info);
- EXPECT_EQ("c_1", GetId(node1));
-
- const BookmarkNode* node2 =
- bookmark_model_->AddURLWithCreationTimeAndMetaInfo(
- parent,
- 0,
- base::ASCIIToUTF16("Some title"),
- GURL(BOOKMARK_URL),
- base::Time::Now(),
- &meta_info);
-
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ("", GetId(node1));
- EXPECT_EQ("", GetId(node2));
- EXPECT_EQ("c_1", GetOldId(node1));
- EXPECT_EQ("c_1", GetOldId(node2));
- EXPECT_EQ("v1.0", GetVersion(node1));
- EXPECT_EQ("v1.0", GetVersion(node2));
-}
-
-// Verifies that duplicate nodes are reset if an id is changed to a duplicate
-// value.
-TEST_F(EnhancedBookmarkModelTest, ResetDuplicateChangedNodes) {
- const BookmarkNode* node1 = AddBookmark();
- const BookmarkNode* node2 = AddBookmark();
-
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1");
- EXPECT_EQ("c_1", GetId(node1));
-
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1");
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ("", GetId(node1));
- EXPECT_EQ("", GetId(node2));
- EXPECT_EQ("c_1", GetOldId(node1));
- EXPECT_EQ("c_1", GetOldId(node2));
- EXPECT_EQ("v1.0", GetVersion(node1));
- EXPECT_EQ("v1.0", GetVersion(node2));
-}
-
-TEST_F(EnhancedBookmarkModelTest, SetMultipleMetaInfo) {
- const BookmarkNode* node = AddBookmark();
- BookmarkNode::MetaInfoMap meta_info;
- meta_info["a"] = "aa";
- meta_info["b"] = "bb";
-
- model_->SetVersionSuffix("1");
- model_->SetMultipleMetaInfo(node, meta_info);
- EXPECT_EQ("aa", GetMetaInfoField(node, "a"));
- EXPECT_EQ("bb", GetMetaInfoField(node, "b"));
- EXPECT_EQ("v1.0/1", GetVersion(node));
-
- // Not present fields does not erase the fields already set on the node.
- meta_info["a"] = "aaa";
- model_->SetVersionSuffix("2");
- model_->SetMultipleMetaInfo(node, meta_info);
- EXPECT_EQ("aaa", GetMetaInfoField(node, "a"));
- EXPECT_EQ("bb", GetMetaInfoField(node, "b"));
- EXPECT_EQ("v1.0/2", GetVersion(node));
-
- // Not actually changing any values should not set the version field.
- model_->SetVersionSuffix("3");
- model_->SetMultipleMetaInfo(node, meta_info);
- EXPECT_EQ("v1.0/2", GetVersion(node));
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverShuttingDownEvent) {
- EXPECT_EQ(0, shutting_down_calls_);
- model_->Shutdown();
- EXPECT_EQ(1, shutting_down_calls_);
- model_.reset();
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverNodeAddedEvent) {
- EXPECT_EQ(0, added_calls_);
- const BookmarkNode* node = AddBookmark();
- EXPECT_EQ(1, added_calls_);
- EXPECT_EQ(node, last_added_);
-
- const BookmarkNode* folder = AddFolder();
- EXPECT_EQ(2, added_calls_);
- EXPECT_EQ(folder, last_added_);
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverNodeRemovedEvent) {
- const BookmarkNode* node = AddBookmark();
- const BookmarkNode* folder = AddFolder();
-
- EXPECT_EQ(0, removed_calls_);
- bookmark_model_->Remove(node);
- EXPECT_EQ(1, removed_calls_);
- EXPECT_EQ(node, last_removed_);
-
- bookmark_model_->Remove(folder);
- EXPECT_EQ(2, removed_calls_);
- EXPECT_EQ(folder, last_removed_);
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverNodeChangedEvent) {
- const BookmarkNode* node = AddBookmark();
-
- EXPECT_EQ(0, changed_calls_);
- bookmark_model_->SetTitle(node, base::ASCIIToUTF16("New Title"));
- EXPECT_EQ(1, changed_calls_);
- EXPECT_EQ(node, last_changed_);
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverAllUserNodesRemovedEvent) {
- AddBookmark();
- AddFolder();
- EXPECT_EQ(0, all_user_nodes_removed_calls_);
- bookmark_model_->RemoveAllUserBookmarks();
- EXPECT_EQ(0, removed_calls_);
- EXPECT_EQ(1, all_user_nodes_removed_calls_);
-}
-
-TEST_F(EnhancedBookmarkModelTest, ObserverRemoteIdChangedEvent) {
- const BookmarkNode* node1 = AddFolder();
- const BookmarkNode* node2 = AddFolder();
-
- EXPECT_EQ(0, remote_id_changed_calls_);
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1");
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1, remote_id_changed_calls_);
- EXPECT_EQ(node1, last_remote_id_node_);
- EXPECT_EQ("", last_old_remote_id_);
- EXPECT_EQ("c_1", last_remote_id_);
-
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_2");
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, remote_id_changed_calls_);
- EXPECT_EQ(node2, last_remote_id_node_);
- EXPECT_EQ("", last_old_remote_id_);
- EXPECT_EQ("c_2", last_remote_id_);
-
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_3");
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(3, remote_id_changed_calls_);
- EXPECT_EQ(node1, last_remote_id_node_);
- EXPECT_EQ("c_1", last_old_remote_id_);
- EXPECT_EQ("c_3", last_remote_id_);
-
- // Set to duplicate ids.
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_3");
- EXPECT_EQ(4, remote_id_changed_calls_);
- EXPECT_EQ(node2, last_remote_id_node_);
- EXPECT_EQ("c_2", last_old_remote_id_);
- EXPECT_EQ("c_3", last_remote_id_);
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(6, remote_id_changed_calls_);
- EXPECT_EQ("", last_remote_id_);
-}
-
-TEST_F(EnhancedBookmarkModelTest, ShutDownWhileResetDuplicationScheduled) {
- const BookmarkNode* node1 = AddBookmark();
- const BookmarkNode* node2 = AddBookmark();
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1");
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1");
- model_->Shutdown();
- model_.reset();
- base::RunLoop().RunUntilIdle();
-}
-
-TEST_F(EnhancedBookmarkModelTest, NodeRemovedWhileResetDuplicationScheduled) {
- const BookmarkNode* node1 = AddBookmark();
- const BookmarkNode* node2 = AddBookmark();
- bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1");
- bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1");
- bookmark_model_->Remove(node1);
- base::RunLoop().RunUntilIdle();
-}
-
-TEST_F(EnhancedBookmarkModelTest,
- RemoveParentShouldRemoveChildrenFromMaps) {
- const BookmarkNode* parent = AddFolder();
- const BookmarkNode* node = AddBookmark("Title", parent);
- std::string remote_id = GetId(node);
- EXPECT_EQ(node, model_->BookmarkForRemoteId(remote_id));
-
- bookmark_model_->Remove(parent);
- EXPECT_FALSE(model_->BookmarkForRemoteId(remote_id));
-}
-
-TEST_F(EnhancedBookmarkModelTest, AddsRemoteIdToNonClonedKeys) {
- const std::set<std::string>& non_cloned_keys =
- bookmark_model_->non_cloned_keys();
- EXPECT_TRUE(non_cloned_keys.find("stars.id") != non_cloned_keys.end());
-}
-
-TEST_F(EnhancedBookmarkModelTest, RemoveImageData) {
- const BookmarkNode* node = AddBookmark();
- model_->SetAllImages(node, GURL(IMAGE_URL), 64, 64, GURL(IMAGE_URL), 16, 16);
-
- GURL url;
- int width, height;
- EXPECT_TRUE(model_->GetOriginalImage(node, &url, &width, &height));
- EXPECT_TRUE(model_->GetThumbnailImage(node, &url, &width, &height));
-
- model_->RemoveImageData(node);
- EXPECT_FALSE(model_->GetOriginalImage(node, &url, &width, &height));
- EXPECT_FALSE(model_->GetThumbnailImage(node, &url, &width, &height));
-
- std::string meta_info = GetMetaInfoField(node, "stars.imageData");
- std::string decoded;
- ASSERT_TRUE(base::Base64Decode(meta_info, &decoded));
- image::collections::ImageData data;
- ASSERT_TRUE(data.ParseFromString(decoded));
- EXPECT_TRUE(data.user_removed_image());
-}
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.cc b/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.cc
deleted file mode 100644
index ce28b3b..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2015 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 "components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h"
-
-namespace switches {
-
-// Enable Enhanced Bookmarks.
-const char kEnhancedBookmarksExperiment[] = "enhanced-bookmarks-experiment";
-
-} // namespace switches
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h b/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h
deleted file mode 100644
index 5aa2ceb..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 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 COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_SWITCHES_IOS_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_SWITCHES_IOS_H_
-
-namespace switches {
-
-extern const char kEnhancedBookmarksExperiment[];
-
-} // namespace switches
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_SWITCHES_IOS_H_
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_utils.cc b/components/enhanced_bookmarks/enhanced_bookmark_utils.cc
deleted file mode 100644
index 1ca96ca..0000000
--- a/components/enhanced_bookmarks/enhanced_bookmark_utils.cc
+++ /dev/null
@@ -1,66 +0,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 "components/enhanced_bookmarks/enhanced_bookmark_utils.h"
-
-#include "components/bookmarks/browser/bookmark_model.h"
-
-using bookmarks::BookmarkModel;
-using bookmarks::BookmarkNode;
-
-namespace enhanced_bookmarks {
-
-std::vector<const BookmarkNode*> PrimaryPermanentNodes(BookmarkModel* model) {
- DCHECK(model->loaded());
- std::vector<const BookmarkNode*> nodes;
- nodes.push_back(model->mobile_node());
- nodes.push_back(model->bookmark_bar_node());
- nodes.push_back(model->other_node());
- return nodes;
-}
-
-std::vector<const BookmarkNode*> RootLevelFolders(BookmarkModel* model) {
- std::vector<const BookmarkNode*> root_level_folders;
-
- // Find the direct folder children of the primary permanent nodes.
- std::vector<const BookmarkNode*> primary_permanent_nodes =
- PrimaryPermanentNodes(model);
- for (const BookmarkNode* parent : primary_permanent_nodes) {
- int child_count = parent->child_count();
- for (int i = 0; i < child_count; ++i) {
- const BookmarkNode* node = parent->GetChild(i);
- if (node->is_folder() && node->IsVisible())
- root_level_folders.push_back(node);
- }
- }
- return root_level_folders;
-}
-
-bool IsPrimaryPermanentNode(const BookmarkNode* node, BookmarkModel* model) {
- std::vector<const BookmarkNode*> primary_nodes(PrimaryPermanentNodes(model));
- if (std::find(primary_nodes.begin(), primary_nodes.end(), node) !=
- primary_nodes.end()) {
- return true;
- }
- return false;
-}
-
-const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node,
- BookmarkModel* model) {
- // This helper function doesn't work for managed bookmarks. This checks that
- // |node| is editable by the user, which currently covers all the other
- // bookmarks except the managed bookmarks.
- DCHECK(model->client()->CanBeEditedByUser(node));
-
- const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model));
- const BookmarkNode* top = node;
- while (top &&
- std::find(root_folders.begin(), root_folders.end(), top) ==
- root_folders.end()) {
- top = top->parent();
- }
- return top;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_utils.h b/components/enhanced_bookmarks/enhanced_bookmark_utils.h
index 33a872f..30150aa 100644
--- a/components/enhanced_bookmarks/enhanced_bookmark_utils.h
+++ b/components/enhanced_bookmarks/enhanced_bookmark_utils.h
@@ -5,15 +5,6 @@
#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_UTILS_H_
#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_UTILS_H_
-#include <set>
-#include <string>
-#include <vector>
-
-namespace bookmarks {
-class BookmarkModel;
-class BookmarkNode;
-}
-
namespace enhanced_bookmarks {
// Possible locations where a bookmark can be opened from.
@@ -31,29 +22,6 @@ enum LaunchLocation {
COUNT = 6,
};
-// Returns the permanent nodes whose url children are considered uncategorized
-// and whose folder children should be shown in the bookmark menu.
-// |model| must be loaded.
-std::vector<const bookmarks::BookmarkNode*> PrimaryPermanentNodes(
- bookmarks::BookmarkModel* model);
-
-// Returns an unsorted vector of folders that are considered to be at the "root"
-// level of the bookmark hierarchy. Functionally, this means all direct
-// descendants of PrimaryPermanentNodes.
-std::vector<const bookmarks::BookmarkNode*> RootLevelFolders(
- bookmarks::BookmarkModel* model);
-
-// Returns whether |node| is a primary permanent node in the sense of
-// |PrimaryPermanentNodes|.
-bool IsPrimaryPermanentNode(const bookmarks::BookmarkNode* node,
- bookmarks::BookmarkModel* model);
-
-// Returns the root level folder in which this node is directly, or indirectly
-// via subfolders, located.
-const bookmarks::BookmarkNode* RootLevelFolderForNode(
- const bookmarks::BookmarkNode* node,
- bookmarks::BookmarkModel* model);
-
} // namespace enhanced_bookmarks
#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_UTILS_H_
diff --git a/components/enhanced_bookmarks/image_record.cc b/components/enhanced_bookmarks/image_record.cc
deleted file mode 100644
index 96cc443..0000000
--- a/components/enhanced_bookmarks/image_record.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2015 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 "components/enhanced_bookmarks/image_record.h"
-
-#include <utility>
-
-namespace enhanced_bookmarks {
-
-ImageRecord::ImageRecord(scoped_ptr<gfx::Image> image,
- const GURL& url,
- SkColor dominant_color)
- : image(std::move(image)), url(url), dominant_color(dominant_color) {}
-
-ImageRecord::ImageRecord(scoped_ptr<gfx::Image> image, const GURL& url)
- : ImageRecord(std::move(image), url, SK_ColorBLACK) {}
-
-ImageRecord::ImageRecord()
- : ImageRecord(scoped_ptr<gfx::Image>(new gfx::Image()), GURL()) {
-}
-
-ImageRecord::~ImageRecord() {
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/image_record.h b/components/enhanced_bookmarks/image_record.h
deleted file mode 100644
index e93f3b8..0000000
--- a/components/enhanced_bookmarks/image_record.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2015 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 COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_RECORD_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_RECORD_H_
-
-#include "base/memory/ref_counted.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/image/image.h"
-#include "url/gurl.h"
-
-namespace enhanced_bookmarks {
-
-// Defines a record of a bookmark image in the ImageStore.
-class ImageRecord : public base::RefCountedThreadSafe<ImageRecord> {
- public:
- ImageRecord(scoped_ptr<gfx::Image> image,
- const GURL& url,
- SkColor dominant_color);
- ImageRecord(scoped_ptr<gfx::Image> image, const GURL& url);
- ImageRecord();
-
- // The image data.
- scoped_ptr<gfx::Image> image;
- // The URL that hosts the image.
- GURL url;
- // The dominant color of the image.
- SkColor dominant_color;
-
- private:
- friend class base::RefCountedThreadSafe<ImageRecord>;
-
- ~ImageRecord();
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_RECORD_H_
diff --git a/components/enhanced_bookmarks/image_store.cc b/components/enhanced_bookmarks/image_store.cc
deleted file mode 100644
index c0759c1..0000000
--- a/components/enhanced_bookmarks/image_store.cc
+++ /dev/null
@@ -1,24 +0,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 "components/enhanced_bookmarks/image_store.h"
-
-#include "url/gurl.h"
-
-ImageStore::ImageStore() {
-}
-
-ImageStore::~ImageStore() {
-}
-
-void ImageStore::ChangeImageURL(const GURL& from, const GURL& to) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- if (!HasKey(from))
- return;
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> record = Get(from);
- Erase(from);
- Insert(to, record);
-}
diff --git a/components/enhanced_bookmarks/image_store.h b/components/enhanced_bookmarks/image_store.h
deleted file mode 100644
index d1bf505..0000000
--- a/components/enhanced_bookmarks/image_store.h
+++ /dev/null
@@ -1,72 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_
-
-#include <stdint.h>
-
-#include <set>
-
-#include "base/macros.h"
-#include "base/sequence_checker.h"
-#include "components/enhanced_bookmarks/image_record.h"
-#include "ui/gfx/geometry/size.h"
-
-class GURL;
-
-// The ImageStore keeps an image for each URL. This class is not thread safe,
-// and will check the thread using base::ThreadChecker, except the constructor.
-class ImageStore {
- public:
- ImageStore();
- virtual ~ImageStore();
-
- // Returns true if there is an image for this url.
- virtual bool HasKey(const GURL& page_url) = 0;
-
- // Inserts an ImageRecord in the store for the given page url. The image can
- // be null indicating that the download of the image at this URL or
- // encoding for insertion failed previously. On non-iOS platforms, |image|
- // must have exactly one representation with a scale factor of 1.
- virtual void Insert(
- const GURL& page_url,
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) = 0;
-
- // Removes an image from the store.
- virtual void Erase(const GURL& page_url) = 0;
-
- // Returns the image associated with this url. Returns an ImageRecord with an
- // empty image if there is no image for this url. It also returns the
- // image_url where the image was downloaded from or failed to be downloaded
- // from. When the image is not empty, the dominant color of the image is also
- // filled.
- virtual scoped_refptr<enhanced_bookmarks::ImageRecord> Get(
- const GURL& page_url) = 0;
-
- // Returns the size of the image stored for this URL or empty size if no
- // images are present.
- virtual gfx::Size GetSize(const GURL& page_url) = 0;
-
- // Populates |urls| with all the urls that have an image in the store.
- virtual void GetAllPageUrls(std::set<GURL>* urls) = 0;
-
- // Removes all images.
- virtual void ClearAll() = 0;
-
- // Moves an image from one url to another.
- void ChangeImageURL(const GURL& from, const GURL& to);
-
- // Returns the saved images storage size in bytes. If the storage doesn't
- // exist yet or failed to read, returns -1.
- virtual int64_t GetStoreSizeInBytes() = 0;
-
- protected:
- base::SequenceChecker sequence_checker_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ImageStore);
-};
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_H_
diff --git a/components/enhanced_bookmarks/image_store_ios_unittest.mm b/components/enhanced_bookmarks/image_store_ios_unittest.mm
deleted file mode 100644
index 2efa981..0000000
--- a/components/enhanced_bookmarks/image_store_ios_unittest.mm
+++ /dev/null
@@ -1,161 +0,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 "components/enhanced_bookmarks/image_store.h"
-
-#import <UIKit/UIKit.h>
-
-#include "base/files/scoped_temp_dir.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/macros.h"
-#include "components/enhanced_bookmarks/image_record.h"
-#include "components/enhanced_bookmarks/image_store_util.h"
-#include "components/enhanced_bookmarks/persistent_image_store.h"
-#include "components/enhanced_bookmarks/test_image_store.h"
-#include "testing/platform_test.h"
-#include "ui/gfx/geometry/size.h"
-#include "ui/gfx/image/image.h"
-#include "url/gurl.h"
-
-namespace {
-
-// Generates a gfx::Image with a random UIImage representation. Uses off-center
-// circle gradient to make all pixels slightly different in order to detect
-// small image alterations.
-scoped_ptr<gfx::Image> GenerateRandomUIImage(const gfx::Size& size,
- float scale) {
- UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width(),
- size.height()),
- YES, // opaque.
- scale);
- // Create the gradient's colors.
- CGFloat locations[] = { 0.0, 1.0 };
- CGFloat components[] = { rand()/CGFloat(RAND_MAX), // Start color r
- rand()/CGFloat(RAND_MAX), // g
- rand()/CGFloat(RAND_MAX), // b
- 1.0, // Alpha
- rand()/CGFloat(RAND_MAX), // End color r
- rand()/CGFloat(RAND_MAX), // g
- rand()/CGFloat(RAND_MAX), // b
- 1.0 }; // Alpha
- CGPoint center = CGPointMake(size.width() / 3, size.height() / 3);
- CGFloat radius = MAX(size.width(), size.height());
-
- base::ScopedCFTypeRef<CGColorSpaceRef>
- colorspace(CGColorSpaceCreateDeviceRGB());
- base::ScopedCFTypeRef<CGGradientRef>
- gradient(CGGradientCreateWithColorComponents(colorspace,
- components,
- locations,
- arraysize(locations)));
- CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(),
- gradient,
- center,
- 0,
- center,
- radius,
- kCGGradientDrawsAfterEndLocation);
- UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return scoped_ptr<gfx::Image>(new gfx::Image([image retain]));
-}
-
-// Returns true if the two images are identical.
-bool CompareImages(const gfx::Image& image_1, const gfx::Image& image_2) {
- if (image_1.IsEmpty() && image_2.IsEmpty())
- return true;
- if (image_1.IsEmpty() || image_2.IsEmpty())
- return false;
-
- scoped_refptr<base::RefCountedMemory> image_1_bytes =
- enhanced_bookmarks::BytesForImage(image_1);
- scoped_refptr<base::RefCountedMemory> image_2_bytes =
- enhanced_bookmarks::BytesForImage(image_2);
-
- if (image_1_bytes->size() != image_2_bytes->size())
- return false;
-
- return !memcmp(image_1_bytes->front(),
- image_2_bytes->front(),
- image_1_bytes->size());
-}
-
-// Factory functions for creating instances of the implementations.
-template <class T>
-ImageStore* CreateStore(base::ScopedTempDir& folder);
-
-template <>
-ImageStore* CreateStore<TestImageStore>(
- base::ScopedTempDir& folder) {
- return new TestImageStore();
-}
-
-template <>
-ImageStore* CreateStore<PersistentImageStore>(
- base::ScopedTempDir& folder) {
- return new PersistentImageStore(folder.path());
-}
-
-// Methods to check if persistence is on or not.
-template <class T> bool ShouldPersist();
-template <> bool ShouldPersist<TestImageStore>() { return false; }
-template <> bool ShouldPersist<PersistentImageStore>() { return true; }
-
-// Test fixture class template for the abstract API.
-template <class T>
-class ImageStoreUnitTestIOS : public PlatformTest {
- protected:
- ImageStoreUnitTestIOS() {}
- ~ImageStoreUnitTestIOS() override {}
-
- void SetUp() override {
- bool success = temp_dir_.CreateUniqueTempDir();
- ASSERT_TRUE(success);
- store_.reset(CreateStore<T>(temp_dir_));
- }
-
- void TearDown() override {
- if (store_ && use_persistent_store())
- store_->ClearAll();
- }
-
- bool use_persistent_store() const { return ShouldPersist<T>(); }
- void ResetStore() { store_.reset(CreateStore<T>(temp_dir_)); }
-
- // The directory the database is saved into.
- base::ScopedTempDir temp_dir_;
- // The object the fixture is testing, via its base interface.
- scoped_ptr<ImageStore> store_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ImageStoreUnitTestIOS);
-};
-
-// The list of implementations of the abstract API that are going to be tested.
-typedef testing::Types<TestImageStore,
- PersistentImageStore> Implementations;
-
-TYPED_TEST_CASE(ImageStoreUnitTestIOS, Implementations);
-
-TYPED_TEST(ImageStoreUnitTestIOS, StoringImagesPreservesScale) {
- const CGFloat scales[] = {0.0, 1.0, 2.0};
- const gfx::Size image_size(42, 24);
- for (unsigned long i = 0; i < arraysize(scales); i++) {
- const GURL url("foo://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
- new enhanced_bookmarks::ImageRecord(
- GenerateRandomUIImage(image_size, scales[i]),
- GURL("http://a.jpg"),
- SK_ColorGREEN));
- this->store_->Insert(url, image_in);
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
- this->store_->Get(url);
-
- EXPECT_EQ(image_in->url, image_out->url);
- EXPECT_TRUE(CompareImages(*image_in->image, *image_out->image));
- EXPECT_EQ(image_in->dominant_color, image_out->dominant_color);
- }
-}
-
-} // namespace
diff --git a/components/enhanced_bookmarks/image_store_unittest.cc b/components/enhanced_bookmarks/image_store_unittest.cc
deleted file mode 100644
index 598e6f9..0000000
--- a/components/enhanced_bookmarks/image_store_unittest.cc
+++ /dev/null
@@ -1,341 +0,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 "components/enhanced_bookmarks/image_store.h"
-
-#include <stdint.h>
-
-#include "base/files/file_path.h"
-#include "base/files/scoped_temp_dir.h"
-#include "base/macros.h"
-#include "base/strings/string_number_conversions.h"
-#include "build/build_config.h"
-#include "components/enhanced_bookmarks/image_record.h"
-#include "components/enhanced_bookmarks/image_store_util.h"
-#include "components/enhanced_bookmarks/persistent_image_store.h"
-#include "components/enhanced_bookmarks/test_image_store.h"
-#include "sql/statement.h"
-#include "testing/platform_test.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "url/gurl.h"
-
-namespace {
-
-scoped_ptr<gfx::Image> CreateImage(
- int width, int height, int a, int r, int g, int b) {
- SkBitmap bitmap;
- bitmap.allocN32Pixels(width, height);
- bitmap.eraseARGB(a, r, g, b);
- scoped_ptr<gfx::Image> image(
- new gfx::Image(gfx::Image::CreateFrom1xBitmap(bitmap)));
-
-#if defined(OS_IOS)
- // Make sure the image has a kImageRepCocoaTouch.
- image->ToUIImage();
-#endif // defined(OS_IOS)
-
- return image;
-}
-
-scoped_ptr<gfx::Image> GenerateWhiteImage() {
- return CreateImage(42, 24, 255, 255, 255, 255);
-}
-
-scoped_ptr<gfx::Image> GenerateBlackImage(int width, int height) {
- return CreateImage(width, height, 255, 0, 0, 0);
-}
-
-scoped_ptr<gfx::Image> GenerateBlackImage() {
- return GenerateBlackImage(42, 24);
-}
-
-// Returns true if the two images are identical.
-bool CompareImages(const gfx::Image& image_1, const gfx::Image& image_2) {
- if (image_1.IsEmpty() && image_2.IsEmpty())
- return true;
-
- if (image_1.IsEmpty() || image_2.IsEmpty())
- return false;
-
- scoped_refptr<base::RefCountedMemory> image_1_bytes =
- enhanced_bookmarks::BytesForImage(image_1);
- scoped_refptr<base::RefCountedMemory> image_2_bytes =
- enhanced_bookmarks::BytesForImage(image_2);
-
- if (image_1_bytes->size() != image_2_bytes->size())
- return false;
-
- return !memcmp(image_1_bytes->front(),
- image_2_bytes->front(),
- image_1_bytes->size());
-}
-
-bool CreateV1PersistentImageStoreDB(const base::FilePath& path) {
- sql::Connection db;
- if (!db.Open(path))
- return false;
-
- if (db.DoesTableExist("images_by_url"))
- return false;
-
- const char kV1TableSql[] =
- "CREATE TABLE IF NOT EXISTS images_by_url ("
- "page_url LONGVARCHAR NOT NULL,"
- "image_url LONGVARCHAR NOT NULL,"
- "image_data BLOB,"
- "width INTEGER,"
- "height INTEGER"
- ")";
- if (!db.Execute(kV1TableSql))
- return false;
-
- const char kV1IndexSql[] =
- "CREATE INDEX IF NOT EXISTS images_by_url_idx ON images_by_url(page_url)";
- if (!db.Execute(kV1IndexSql))
- return false;
-
- sql::Statement statement(db.GetUniqueStatement(
- "INSERT INTO images_by_url "
- "(page_url, image_url, image_data, width, height) "
- "VALUES (?, ?, ?, ?, ?)"));
- statement.BindString(0, "foo://bar");
- statement.BindString(1, "http://a.jpg");
- scoped_refptr<base::RefCountedMemory> image_bytes =
- enhanced_bookmarks::BytesForImage(*GenerateWhiteImage());
- statement.BindBlob(2, image_bytes->front(), (int)image_bytes->size());
- statement.BindInt(3, 42);
- statement.BindInt(4, 24);
-
- return statement.Run();
-}
-
-// Factory functions for creating instances of the implementations.
-template <class T>
-ImageStore* CreateStore(base::ScopedTempDir& folder);
-
-template <>
-ImageStore* CreateStore<TestImageStore>(
- base::ScopedTempDir& folder) {
- return new TestImageStore();
-}
-
-template <>
-ImageStore* CreateStore<PersistentImageStore>(
- base::ScopedTempDir& folder) {
- return new PersistentImageStore(folder.path());
-}
-
-// Methods to check if persistence is on or not.
-template <class T> bool ShouldPersist();
-template <> bool ShouldPersist<TestImageStore>() { return false; }
-template <> bool ShouldPersist<PersistentImageStore>() { return true; }
-
-// Test fixture class template for the abstract API.
-template <class T>
-class ImageStoreUnitTest : public PlatformTest {
- protected:
- ImageStoreUnitTest() {}
- ~ImageStoreUnitTest() override {}
-
- void SetUp() override {
- bool success = tempDir_.CreateUniqueTempDir();
- ASSERT_TRUE(success);
- store_.reset(CreateStore<T>(tempDir_));
- }
-
- void TearDown() override {
- if (store_ && use_persistent_store())
- store_->ClearAll();
- }
-
- bool use_persistent_store() const { return ShouldPersist<T>(); }
- void ResetStore() { store_.reset(CreateStore<T>(tempDir_)); }
-
- // The directory the database is saved into.
- base::ScopedTempDir tempDir_;
- // The object the fixture is testing, via its base interface.
- scoped_ptr<ImageStore> store_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ImageStoreUnitTest);
-};
-
-// The list of implementations of the abstract API that are going to be tested.
-typedef testing::Types<TestImageStore,
- PersistentImageStore> Implementations;
-
-TYPED_TEST_CASE(ImageStoreUnitTest, Implementations);
-
-// All those tests are run on all the implementations.
-TYPED_TEST(ImageStoreUnitTest, StartsEmpty) {
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(0u, all_urls.size());
-}
-
-TYPED_TEST(ImageStoreUnitTest, StoreOne) {
- scoped_refptr<enhanced_bookmarks::ImageRecord> image(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
- this->store_->Insert(GURL("foo://bar"), image);
-
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(1u, all_urls.size());
- EXPECT_EQ(GURL("foo://bar"), *all_urls.begin());
- EXPECT_TRUE(this->store_->HasKey(GURL("foo://bar")));
-}
-
-TYPED_TEST(ImageStoreUnitTest, Retrieve) {
- const GURL url("foo://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
- new enhanced_bookmarks::ImageRecord(
- CreateImage(42, 24, 1, 0, 0, 1), GURL("http://a.jpg"), SK_ColorBLUE));
- this->store_->Insert(url, image_in);
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
- this->store_->Get(url);
- const gfx::Size size = this->store_->GetSize(url);
-
- EXPECT_EQ(42, size.width());
- EXPECT_EQ(24, size.height());
- EXPECT_EQ(image_in->url, image_out->url);
- EXPECT_TRUE(CompareImages(*image_in->image, *image_out->image));
- EXPECT_EQ(SK_ColorBLUE, image_out->dominant_color);
-}
-
-TYPED_TEST(ImageStoreUnitTest, Erase) {
- const GURL url("foo://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> image(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
- this->store_->Insert(url, image);
- this->store_->Erase(url);
-
- EXPECT_FALSE(this->store_->HasKey(url));
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(0u, all_urls.size());
-}
-
-TYPED_TEST(ImageStoreUnitTest, ClearAll) {
- const GURL url_foo("http://foo");
- scoped_refptr<enhanced_bookmarks::ImageRecord> black_image(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
- this->store_->Insert(url_foo, black_image);
- const GURL url_bar("http://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> white_image(
- new enhanced_bookmarks::ImageRecord(
- GenerateWhiteImage(), GURL("http://a.jpg"), SK_ColorWHITE));
- this->store_->Insert(url_bar, white_image);
-
- this->store_->ClearAll();
-
- EXPECT_FALSE(this->store_->HasKey(url_foo));
- EXPECT_FALSE(this->store_->HasKey(url_bar));
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(0u, all_urls.size());
-}
-
-TYPED_TEST(ImageStoreUnitTest, Update) {
- const GURL url("foo://bar");
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> image1(
- new enhanced_bookmarks::ImageRecord(
- GenerateWhiteImage(), GURL("1.jpg"), SK_ColorWHITE));
- this->store_->Insert(url, image1);
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> image2(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("2.jpg"), SK_ColorBLACK));
- this->store_->Insert(url, image2);
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
- this->store_->Get(url);
-
- EXPECT_TRUE(this->store_->HasKey(url));
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(1u, all_urls.size());
- EXPECT_EQ(image2->url, image_out->url);
- EXPECT_TRUE(CompareImages(*image2->image, *image_out->image));
- EXPECT_EQ(SK_ColorBLACK, image_out->dominant_color);
-}
-
-TYPED_TEST(ImageStoreUnitTest, Persistence) {
- const GURL url("foo://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
- this->store_->Insert(url, image_in);
-
- this->ResetStore();
- if (this->use_persistent_store()) {
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(1u, all_urls.size());
- EXPECT_EQ(url, *all_urls.begin());
- EXPECT_TRUE(this->store_->HasKey(url));
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
- this->store_->Get(url);
-
- EXPECT_EQ(image_in->url, image_out->url);
- EXPECT_TRUE(CompareImages(*image_in->image, *image_out->image));
- EXPECT_EQ(image_in->dominant_color, image_out->dominant_color);
- } else {
- std::set<GURL> all_urls;
- this->store_->GetAllPageUrls(&all_urls);
- EXPECT_EQ(0u, all_urls.size());
- EXPECT_FALSE(this->store_->HasKey(url));
- }
-}
-
-TYPED_TEST(ImageStoreUnitTest, MigrationToV2) {
- // Migration is available only with persistent stores.
- if (!this->use_persistent_store())
- return;
-
- // Set up v1 DB.
- EXPECT_TRUE(CreateV1PersistentImageStoreDB(this->tempDir_.path().Append(
- base::FilePath::FromUTF8Unsafe("BookmarkImageAndUrlStore.db"))));
-
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
- this->store_->Get(GURL("foo://bar"));
- EXPECT_EQ(SK_ColorWHITE, image_out->dominant_color);
-}
-
-TYPED_TEST(ImageStoreUnitTest, GetSize) {
- const GURL url("foo://bar");
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
- new enhanced_bookmarks::ImageRecord(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
-
- int64_t size = 0;
- if (this->use_persistent_store()) {
- // File shouldn't exist before we actually start using it since we do lazy
- // initialization.
- EXPECT_EQ(this->store_->GetStoreSizeInBytes(), -1);
- } else {
- EXPECT_LE(this->store_->GetStoreSizeInBytes(), 1024);
- }
- for (int i = 0; i < 100; ++i) {
- this->store_->Insert(GURL(url.spec() + '/' + base::IntToString(i)),
- image_in);
- EXPECT_GE(this->store_->GetStoreSizeInBytes(), size);
- size = this->store_->GetStoreSizeInBytes();
- }
-
- if (this->use_persistent_store()) {
- EXPECT_GE(this->store_->GetStoreSizeInBytes(), 80 * 1024); // 80kb
- EXPECT_LE(this->store_->GetStoreSizeInBytes(), 200 * 1024); // 200kb
- } else {
- EXPECT_GE(this->store_->GetStoreSizeInBytes(), 400 * 1024); // 400kb
- EXPECT_LE(this->store_->GetStoreSizeInBytes(), 500 * 1024); // 500kb
- }
-}
-
-} // namespace
diff --git a/components/enhanced_bookmarks/image_store_util.cc b/components/enhanced_bookmarks/image_store_util.cc
deleted file mode 100644
index ef3979d..0000000
--- a/components/enhanced_bookmarks/image_store_util.cc
+++ /dev/null
@@ -1,39 +0,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 "components/enhanced_bookmarks/image_store_util.h"
-
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/color_analysis.h"
-#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/image/image_util.h"
-
-namespace {
-const int kJpegEncodingQuality = 70;
-} // namespace
-
-namespace enhanced_bookmarks {
-
-scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
- DCHECK(image.AsImageSkia().image_reps().size() == 1);
- DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f);
-
- std::vector<unsigned char> data;
- bool succeeded =
- gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data);
-
- if (!succeeded)
- return scoped_refptr<base::RefCountedMemory>();
-
- return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data));
-}
-
-gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) {
- return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size());
-}
-
-SkColor DominantColorForImage(const gfx::Image& image) {
- return color_utils::CalculateKMeanColorOfBitmap(*image.ToSkBitmap());
-}
-}
diff --git a/components/enhanced_bookmarks/image_store_util.h b/components/enhanced_bookmarks/image_store_util.h
deleted file mode 100644
index 8537197..0000000
--- a/components/enhanced_bookmarks/image_store_util.h
+++ /dev/null
@@ -1,31 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_
-
-#include "base/memory/ref_counted_memory.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/geometry/size.h"
-#include "ui/gfx/image/image.h"
-
-namespace enhanced_bookmarks {
-// The two methods below archive and unarchive an image to and from a bag of
-// bytes. There is no API on gfx::Image capable of doing it while preserving the
-// scale of the image.
-
-// Encode |image| to bytes, that can be decoded using the below |ImageForBytes|
-// function. If encoding fails, then returned scoped_refptr has NULL.
-scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image);
-
-// Decode the image bytes encoded by the above |BytesForImage| function and
-// returns a gfx::Image. If decoding fails, returns an empty image.
-gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data);
-
-// Returns the dominant color for |image|. This method can be slow on very large
-// images.
-SkColor DominantColorForImage(const gfx::Image& image);
-}
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_IMAGE_STORE_UTIL_H_
diff --git a/components/enhanced_bookmarks/image_store_util_ios.mm b/components/enhanced_bookmarks/image_store_util_ios.mm
deleted file mode 100644
index 22cea25d..0000000
--- a/components/enhanced_bookmarks/image_store_util_ios.mm
+++ /dev/null
@@ -1,56 +0,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 "components/enhanced_bookmarks/image_store_util.h"
-
-#include <stddef.h>
-#import <UIKit/UIKit.h>
-
-#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/macros.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/color_analysis.h"
-
-namespace {
-// An implementation of RefCountedMemory, where the bytes are stored in a
-// NSData. This class assumes the NSData is non mutable to avoid a copy.
-class RefCountedNSDataMemory : public base::RefCountedMemory {
- public:
- explicit RefCountedNSDataMemory(NSData* memory) : data_([memory retain]) {}
-
- const unsigned char* front() const override {
- return reinterpret_cast<const unsigned char*>([data_ bytes]);
- }
-
- size_t size() const override { return [data_ length]; }
-
-private:
- ~RefCountedNSDataMemory() override {}
-
- base::scoped_nsobject<NSData> data_;
- DISALLOW_COPY_AND_ASSIGN(RefCountedNSDataMemory);
-};
-} // namespace
-
-namespace enhanced_bookmarks {
-
-// Encodes the UIImage representation of a gfx::Image.
-scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
- DCHECK(image.HasRepresentation(gfx::Image::kImageRepCocoaTouch));
- return scoped_refptr<RefCountedNSDataMemory>(new RefCountedNSDataMemory(
- [NSKeyedArchiver archivedDataWithRootObject:image.ToUIImage()]));
-}
-
-// Decodes the UIImage in the bytes and returns a gfx::Image.
-gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data) {
- return gfx::Image([[NSKeyedUnarchiver unarchiveObjectWithData:
- [NSData dataWithBytes:data->front() length:data->size()]] retain]);
-}
-
-SkColor DominantColorForImage(const gfx::Image& image) {
- return color_utils::CalculateKMeanColorOfBitmap(*image.ToSkBitmap());
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/item_position.cc b/components/enhanced_bookmarks/item_position.cc
deleted file mode 100644
index 98f0b14..0000000
--- a/components/enhanced_bookmarks/item_position.cc
+++ /dev/null
@@ -1,179 +0,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 "components/enhanced_bookmarks/item_position.h"
-
-#include "base/logging.h"
-#include "base/macros.h"
-
-namespace {
-const unsigned kPositionBase = 64;
-const char kPositionAlphabet[] =
- ".0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
-} // namespace
-
-namespace enhanced_bookmarks {
-
-ItemPosition::ItemPosition() {
-}
-
-ItemPosition::ItemPosition(const PositionVector& position)
- : position_(position) {
-}
-
-ItemPosition::~ItemPosition() {
-}
-
-// static
-ItemPosition ItemPosition::CreateInitialPosition() {
- PositionVector position(1, kPositionBase / 2);
- return ItemPosition(position);
-}
-
-// static
-ItemPosition ItemPosition::CreateBefore(const ItemPosition& other) {
- DCHECK(other.IsValid());
- return ItemPosition(CreateBeforeImpl(other.position_, 0));
-}
-
-// static
-ItemPosition::PositionVector ItemPosition::CreateBeforeImpl(
- const PositionVector& other,
- size_t from_index) {
- DCHECK_LT(from_index, other.size());
- PositionVector before(other.begin() + from_index, other.end());
-
- // Decrement the last character instead of going half-way to 0 in order to
- // make sure chaining CreateBefore calls result in logarithmic rather than
- // linear length growth.
- before[before.size() - 1] /= 2;
- if (before[before.size() - 1] != 0) {
- // If the last digit didn't change to 0, we're done!
- return before;
- }
-
- // Reset trailing zeros, then decrement the last non-zero digit.
- int index = before.size() - 1;
- while (index >= 0 && before[index] == 0) {
- before[index--] = kPositionBase / 2;
- }
-
- // Negative index means all digits were zeros. Put that many zeros to the
- // front of the string to get one that is comes before the input given.
- // This will cause the returned string to be twice as long as the input one,
- // (and about twice as long as needed for a valid return value), however that
- // means this function can be called many times more before we need to
- // increase the string size again. Increasing it with the minimum length
- // would result in a linear string size growth.
- if (index < 0) {
- before.insert(before.begin(), before.size(), 0);
- } else {
- before[index] /= 2;
- }
- return before;
-}
-
-// static
-ItemPosition ItemPosition::CreateAfter(const ItemPosition& other) {
- DCHECK(other.IsValid());
- return ItemPosition(CreateAfterImpl(other.position_, 0));
-}
-
-// static
-ItemPosition::PositionVector ItemPosition::CreateAfterImpl(
- const PositionVector& other,
- size_t from_index) {
- DCHECK_LE(from_index, other.size());
- if (from_index == other.size()) {
- return PositionVector(1, kPositionBase / 2);
- }
-
- PositionVector after(other.begin() + from_index, other.end());
-
- // Instead of splitting the position with infinity, increment the last digit
- // possible, and reset all digits after. This makes sure chaining createAfter
- // will result in a logarithmic rather than linear length growth.
- size_t index = after.size() - 1;
- do {
- after[index] += (kPositionBase - after[index] + 1) / 2;
- if (after[index] != kPositionBase)
- return after;
- after[index] = kPositionBase / 2;
- } while (index-- > 0);
-
- // All digits must have been at the maximal value already, so the string
- // length has to increase. Double it's size to ensure CreateAfter can be
- // called exponentially more times every time this needs to happen.
- after.insert(after.begin(), after.size(), kPositionBase - 1);
-
- return after;
-}
-
-// static
-ItemPosition ItemPosition::CreateBetween(const ItemPosition& before,
- const ItemPosition& after) {
- DCHECK(before.IsValid() && after.IsValid());
- return ItemPosition(CreateBetweenImpl(before.position_, after.position_));
-}
-
-// static
-ItemPosition::PositionVector ItemPosition::CreateBetweenImpl(
- const PositionVector& before,
- const PositionVector& after) {
- DCHECK(before < after);
-
- PositionVector between;
- for (size_t i = 0; i < before.size(); i++) {
- if (before[i] == after[i]) {
- // Add the common prefix to the return value.
- between.push_back(before[i]);
- continue;
- }
- if (before[i] < after[i] - 1) {
- // Split the difference between the two characters.
- between.push_back((before[i] + after[i]) / 2);
- return between;
- }
- // The difference between before[i] and after[i] is one character. A valid
- // return is that character, plus something that comes after the remaining
- // characters of before.
- between.push_back(before[i]);
- PositionVector suffix = CreateAfterImpl(before, i + 1);
- between.insert(between.end(), suffix.begin(), suffix.end());
- return between;
- }
-
- // |before| must be a prefix of |after|, so return that prefix followed by
- // something that comes before the remaining digits of |after|.
- PositionVector suffix = CreateBeforeImpl(after, before.size());
- between.insert(between.end(), suffix.begin(), suffix.end());
- return between;
-}
-
-std::string ItemPosition::ToString() const {
- DCHECK_GT(arraysize(kPositionAlphabet), kPositionBase);
-
- std::string str;
- str.reserve(position_.size());
- for (size_t i = 0; i < position_.size(); i++) {
- unsigned char val = position_[i];
- CHECK_LT(val, kPositionBase);
- str.push_back(kPositionAlphabet[position_[i]]);
- }
- return str;
-}
-
-bool ItemPosition::IsValid() const {
- return !position_.empty() && position_[position_.size() - 1] != 0;
-}
-
-bool ItemPosition::Equals(const ItemPosition& other) const {
- return position_ == other.position_;
-}
-
-bool ItemPosition::LessThan(const ItemPosition& other) const {
- return position_ < other.position_;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/item_position.h b/components/enhanced_bookmarks/item_position.h
deleted file mode 100644
index 689fe10..0000000
--- a/components/enhanced_bookmarks/item_position.h
+++ /dev/null
@@ -1,59 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_
-
-#include <stddef.h>
-
-#include <string>
-#include <vector>
-
-namespace enhanced_bookmarks {
-
-// Convenience class for generating string based relative ordering between
-// bookmark nodes.
-class ItemPosition {
- public:
- ~ItemPosition();
-
- // Creates a position suitable to use as a starting point.
- static ItemPosition CreateInitialPosition();
-
- // Creates positions relative to other positions.
- static ItemPosition CreateBefore(const ItemPosition& other);
- static ItemPosition CreateBetween(const ItemPosition& before,
- const ItemPosition& after);
- static ItemPosition CreateAfter(const ItemPosition& other);
-
- bool IsValid() const;
-
- // Returns a string representation of the position. The string representations
- // of two position have the same ordering as the positions themselves when
- // compared using ASCII order.
- std::string ToString() const;
-
- // Comparison functions.
- bool Equals(const ItemPosition& other) const;
- bool LessThan(const ItemPosition& other) const;
-
- private:
- typedef std::vector<unsigned char> PositionVector;
-
- ItemPosition();
- explicit ItemPosition(const PositionVector& position);
-
- static PositionVector CreateBeforeImpl(const PositionVector& before,
- size_t from_index);
- static PositionVector CreateBetweenImpl(const PositionVector& before,
- const PositionVector& after);
- static PositionVector CreateAfterImpl(const PositionVector& after,
- size_t from_index);
-
- PositionVector position_;
-};
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_
diff --git a/components/enhanced_bookmarks/item_position_unittest.cc b/components/enhanced_bookmarks/item_position_unittest.cc
deleted file mode 100644
index 2321e0c..0000000
--- a/components/enhanced_bookmarks/item_position_unittest.cc
+++ /dev/null
@@ -1,81 +0,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 "components/enhanced_bookmarks/item_position.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-using enhanced_bookmarks::ItemPosition;
-
-namespace {
-
-class ItemPositionTest : public testing::Test {};
-
-TEST_F(ItemPositionTest, TestCreateBefore) {
- ItemPosition current = ItemPosition::CreateInitialPosition();
- for (int i = 0; i < 10000; i++) {
- ItemPosition next = ItemPosition::CreateBefore(current);
- EXPECT_LT(next.ToString(), current.ToString());
- current = next;
- }
- // Make sure string lengths stay reasonable.
- EXPECT_LT(current.ToString().size(), 20u);
-}
-
-TEST_F(ItemPositionTest, TestCreateAfter) {
- ItemPosition current = ItemPosition::CreateInitialPosition();
- for (int i = 0; i < 10000; i++) {
- ItemPosition next = ItemPosition::CreateAfter(current);
- EXPECT_GT(next.ToString(), current.ToString());
- current = next;
- }
- // Make sure string lengths stay reasonable.
- EXPECT_LT(current.ToString().size(), 20u);
-}
-
-TEST_F(ItemPositionTest, TestCreateBetweenLeftBias) {
- ItemPosition before = ItemPosition::CreateInitialPosition();
- ItemPosition after = ItemPosition::CreateAfter(before);
- for (int i = 0; i < 10000; i++) {
- ItemPosition next = ItemPosition::CreateBetween(before, after);
- EXPECT_GT(next.ToString(), before.ToString());
- EXPECT_LT(next.ToString(), after.ToString());
- after = next;
- }
- // Make sure string lengths stay reasonable.
- EXPECT_LT(after.ToString().size(), 20u);
-}
-
-TEST_F(ItemPositionTest, TestCreateBetweenRightBias) {
- ItemPosition before = ItemPosition::CreateInitialPosition();
- ItemPosition after = ItemPosition::CreateAfter(before);
- for (int i = 0; i < 10000; i++) {
- ItemPosition next = ItemPosition::CreateBetween(before, after);
- EXPECT_GT(next.ToString(), before.ToString());
- EXPECT_LT(next.ToString(), after.ToString());
- before = next;
- }
- // Make sure string lengths stay reasonable.
- EXPECT_LT(before.ToString().size(), 20u);
-}
-
-TEST_F(ItemPositionTest, TestCreateBetweenAlternating) {
- ItemPosition before = ItemPosition::CreateInitialPosition();
- ItemPosition after = ItemPosition::CreateAfter(before);
- for (int i = 0; i < 1000; i++) {
- ItemPosition next = ItemPosition::CreateBetween(before, after);
- EXPECT_GT(next.ToString(), before.ToString());
- EXPECT_LT(next.ToString(), after.ToString());
- if ((i & 1) == 1)
- before = next;
- else
- after = next;
- }
- // There's no way to keep the string length down for all possible insertion
- // scenarios, and this one should be fairly rare in practice. Still verify
- // that at least the growth is restricted to about n*log_2(kPositionBase).
- EXPECT_LT(before.ToString().size(), 200u);
-}
-
-} // namespace
diff --git a/components/enhanced_bookmarks/metadata_accessor.cc b/components/enhanced_bookmarks/metadata_accessor.cc
deleted file mode 100644
index 40c5de9..0000000
--- a/components/enhanced_bookmarks/metadata_accessor.cc
+++ /dev/null
@@ -1,258 +0,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 "components/enhanced_bookmarks/metadata_accessor.h"
-
-#include <iomanip>
-
-#include "base/base64.h"
-#include "base/rand_util.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/enhanced_bookmarks/proto/metadata.pb.h"
-#include "ui/base/models/tree_node_iterator.h"
-
-using namespace image::collections;
-using bookmarks::BookmarkModel;
-using bookmarks::BookmarkNode;
-
-namespace {
-
-// Helper method for working with bookmark metainfo.
-std::string DataForMetaInfoField(const BookmarkNode* node,
- const std::string& field) {
- const BookmarkNode::MetaInfoMap* map = node->GetMetaInfoMap();
- if (!map)
- return "";
-
- BookmarkNode::MetaInfoMap::const_iterator it = map->find(field);
- if (it == map->end())
- return "";
-
- std::string decoded;
- bool result = base::Base64Decode((*it).second, &decoded);
- if (!result)
- return "";
-
- return decoded;
-}
-
-// Sets a new remote id on a bookmark.
-std::string SetRemoteIdOnBookmark(BookmarkModel* bookmark_model,
- const BookmarkNode* node) {
- // Generate 16 digit hex string random id.
- std::stringstream random_id;
- random_id << std::hex << std::setfill('0') << std::setw(16);
- random_id << base::RandUint64() << base::RandUint64();
- std::string random_id_str = random_id.str();
- bookmark_model->SetNodeMetaInfo(
- node, enhanced_bookmarks::kIdDataKey, random_id_str);
- return random_id_str;
-}
-
-// Helper method for working with ImageData_ImageInfo.
-bool PopulateImageData(const ImageData_ImageInfo& info,
- GURL* out_url,
- int* width,
- int* height) {
- if (!info.has_url() || !info.has_width() || !info.has_height())
- return false;
-
- GURL url(info.url());
- if (!url.is_valid())
- return false;
-
- *out_url = url;
- *width = info.width();
- *height = info.height();
- return true;
-}
-
-} // namespace
-
-namespace enhanced_bookmarks {
-
-const char* kPageDataKey = "stars.pageData";
-const char* kImageDataKey = "stars.imageData";
-const char* kIdDataKey = "stars.id";
-const char* kNoteKey = "stars.note";
-
-std::string RemoteIdFromBookmark(BookmarkModel* bookmark_model,
- const BookmarkNode* node) {
- const BookmarkNode::MetaInfoMap* map = node->GetMetaInfoMap();
- if (!map)
- return SetRemoteIdOnBookmark(bookmark_model, node);
-
- BookmarkNode::MetaInfoMap::const_iterator it = map->find(kIdDataKey);
- if (it == map->end() || it->second.empty())
- return SetRemoteIdOnBookmark(bookmark_model, node);
-
- return it->second;
-}
-
-void SetDescriptionForBookmark(BookmarkModel* bookmark_model,
- const BookmarkNode* node,
- const std::string& description) {
- bookmark_model->SetNodeMetaInfo(node, kNoteKey, description);
-}
-
-std::string DescriptionFromBookmark(const BookmarkNode* node) {
- const BookmarkNode::MetaInfoMap* map = node->GetMetaInfoMap();
- if (!map)
- return "";
-
- // First, look for a custom note set by the user.
- BookmarkNode::MetaInfoMap::const_iterator it = map->find(kNoteKey);
- if (it != map->end() && !it->second.empty())
- return it->second;
-
- // If none are present, return the snippet.
- return SnippetFromBookmark(node);
-}
-
-bool SetOriginalImageForBookmark(BookmarkModel* bookmark_model,
- const BookmarkNode* node,
- const GURL& url,
- int width,
- int height) {
- DCHECK(url.is_valid());
-
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- ImageData data;
-
- // Try to populate the imageData with the existing data.
- if (!decoded.empty()) {
- // If the parsing fails, something is wrong. Immediately fail.
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
- }
-
- scoped_ptr<ImageData_ImageInfo> info(new ImageData_ImageInfo);
- info->set_url(url.spec());
- info->set_width(width);
- info->set_height(height);
- data.set_allocated_original_info(info.release());
-
- std::string output;
- bool result = data.SerializePartialToString(&output);
- if (!result)
- return false;
-
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model->SetNodeMetaInfo(node, kImageDataKey, encoded);
- // Ensure that the bookmark has a stars.id, to trigger the server processing.
- RemoteIdFromBookmark(bookmark_model, node);
- return true;
-}
-
-bool OriginalImageFromBookmark(const BookmarkNode* node,
- GURL* url,
- int* width,
- int* height) {
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- if (decoded.empty())
- return false;
-
- ImageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
-
- if (!data.has_original_info())
- return false;
-
- return PopulateImageData(data.original_info(), url, width, height);
-}
-
-bool ThumbnailImageFromBookmark(const BookmarkNode* node,
- GURL* url,
- int* width,
- int* height) {
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- if (decoded.empty())
- return false;
-
- ImageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
-
- if (!data.has_thumbnail_info())
- return false;
-
- return PopulateImageData(data.thumbnail_info(), url, width, height);
-}
-
-std::string SnippetFromBookmark(const BookmarkNode* node) {
- std::string decoded(DataForMetaInfoField(node, kPageDataKey));
- if (decoded.empty())
- return decoded;
-
- PageData data;
- bool result = data.ParseFromString(decoded);
- if (!result)
- return "";
-
- return data.snippet();
-}
-
-bool SetAllImagesForBookmark(BookmarkModel* bookmark_model,
- const BookmarkNode* node,
- const GURL& image_url,
- int image_width,
- int image_height,
- const GURL& thumbnail_url,
- int thumbnail_width,
- int thumbnail_height) {
- DCHECK(image_url.is_valid() || image_url.is_empty());
- DCHECK(thumbnail_url.is_valid() || thumbnail_url.is_empty());
- std::string decoded(DataForMetaInfoField(node, kImageDataKey));
- ImageData data;
-
- // Try to populate the imageData with the existing data.
- if (!decoded.empty()) {
- // If the parsing fails, something is wrong. Immediately fail.
- bool result = data.ParseFromString(decoded);
- if (!result)
- return false;
- }
-
- if (image_url.is_empty()) {
- data.release_original_info();
- } else {
- // Regardless of whether an image info exists, we make a new one.
- // Intentially make a raw pointer.
- ImageData_ImageInfo* info = new ImageData_ImageInfo;
- info->set_url(image_url.spec());
- info->set_width(image_width);
- info->set_height(image_height);
- // This method consumes the raw pointer.
- data.set_allocated_original_info(info);
- }
-
- if (thumbnail_url.is_empty()) {
- data.release_thumbnail_info();
- } else {
- // Regardless of whether an image info exists, we make a new one.
- // Intentially make a raw pointer.
- ImageData_ImageInfo* info = new ImageData_ImageInfo;
- info->set_url(thumbnail_url.spec());
- info->set_width(thumbnail_width);
- info->set_height(thumbnail_height);
- // This method consumes the raw pointer.
- data.set_allocated_thumbnail_info(info);
- }
- std::string output;
- bool result = data.SerializePartialToString(&output);
- if (!result)
- return false;
-
- std::string encoded;
- base::Base64Encode(output, &encoded);
- bookmark_model->SetNodeMetaInfo(node, kImageDataKey, encoded);
- return true;
-}
-
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/metadata_accessor.h b/components/enhanced_bookmarks/metadata_accessor.h
deleted file mode 100644
index dea97b2..0000000
--- a/components/enhanced_bookmarks/metadata_accessor.h
+++ /dev/null
@@ -1,91 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
-
-#include <set>
-#include <string>
-#include <vector>
-
-class GURL;
-
-namespace bookmarks {
-class BookmarkModel;
-class BookmarkNode;
-}
-
-// TODO(rfevang): Remove this file once the remaining caller
-// is converted (enhanced_bookmarks_bridge.cc)
-
-// The functions in this file store and retrieve structured data encoded in the
-// bookmark metadata. This information suplements the data in the bookmark with
-// images and descriptions related to the url.
-namespace enhanced_bookmarks {
-
-typedef std::vector<const bookmarks::BookmarkNode*> NodeVector;
-typedef std::set<const bookmarks::BookmarkNode*> NodeSet;
-
-// The keys used to store the data in the bookmarks metadata dictionary.
-extern const char* kPageDataKey;
-extern const char* kImageDataKey;
-extern const char* kIdDataKey;
-extern const char* kNoteKey;
-
-// Returns the remoteId for a bookmark. If the bookmark doesn't have one already
-// this function will create and set one.
-std::string RemoteIdFromBookmark(bookmarks::BookmarkModel* bookmark_model,
- const bookmarks::BookmarkNode* node);
-
-// Sets the description of a bookmark.
-void SetDescriptionForBookmark(bookmarks::BookmarkModel* bookmark_model,
- const bookmarks::BookmarkNode* node,
- const std::string& description);
-
-// Returns the description of a bookmark.
-std::string DescriptionFromBookmark(const bookmarks::BookmarkNode* node);
-
-// Sets the URL of an image representative of the page.
-// Expects the URL to be valid and not empty.
-// Returns true if the metainfo is successfully populated.
-bool SetOriginalImageForBookmark(bookmarks::BookmarkModel* bookmark_model,
- const bookmarks::BookmarkNode* node,
- const GURL& url,
- int width,
- int height);
-
-// Returns the url and dimensions of the original scraped image.
-// Returns true if the out variables are populated, false otherwise.
-bool OriginalImageFromBookmark(const bookmarks::BookmarkNode* node,
- GURL* url,
- int* width,
- int* height);
-
-// Returns the url and dimensions of the server provided thumbnail image.
-// Returns true if the out variables are populated, false otherwise.
-bool ThumbnailImageFromBookmark(const bookmarks::BookmarkNode* node,
- GURL* url,
- int* width,
- int* height);
-
-// Returns a brief server provided synopsis of the bookmarked page.
-// Returns the empty string if the snippet could not be extracted.
-std::string SnippetFromBookmark(const bookmarks::BookmarkNode* node);
-
-// Used for testing, simulates the process that creates the thumnails. Will
-// remove existing entries for empty urls or set them if the url is not empty.
-// expects valid or empty urls. Returns true if the metainfo is successfully
-// populated.
-bool SetAllImagesForBookmark(bookmarks::BookmarkModel* bookmark_model,
- const bookmarks::BookmarkNode* node,
- const GURL& image_url,
- int image_width,
- int image_height,
- const GURL& thumbnail_url,
- int thumbnail_width,
- int thumbnail_height);
-
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_METADATA_ACCESSOR_H_
diff --git a/components/enhanced_bookmarks/persistent_image_store.cc b/components/enhanced_bookmarks/persistent_image_store.cc
deleted file mode 100644
index b36cb6d..0000000
--- a/components/enhanced_bookmarks/persistent_image_store.cc
+++ /dev/null
@@ -1,343 +0,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 "components/enhanced_bookmarks/persistent_image_store.h"
-
-#include <stddef.h>
-
-#include "base/files/file.h"
-#include "base/logging.h"
-#include "components/enhanced_bookmarks/image_store_util.h"
-#include "sql/statement.h"
-#include "sql/transaction.h"
-#include "ui/gfx/geometry/size.h"
-#include "url/gurl.h"
-
-namespace {
-// Current version number. Databases are written at the "current" version
-// number, but any previous version that can read the "compatible" one can make
-// do with our database without *too* many bad effects.
-const int kCurrentVersionNumber = 2;
-const int kCompatibleVersionNumber = 1;
-
-bool InitTables(sql::Connection& db) {
- const char kTableSql[] =
- "CREATE TABLE IF NOT EXISTS images_by_url ("
- "page_url LONGVARCHAR NOT NULL,"
- "image_url LONGVARCHAR NOT NULL,"
- "image_data BLOB,"
- "width INTEGER,"
- "height INTEGER,"
- "image_dominant_color INTEGER"
- ")";
- if (!db.Execute(kTableSql))
- return false;
- return true;
-}
-
-bool InitIndices(sql::Connection& db) {
- const char kIndexSql[] =
- "CREATE INDEX IF NOT EXISTS images_by_url_idx ON images_by_url(page_url)";
- if (!db.Execute(kIndexSql))
- return false;
- return true;
-}
-
-// V1 didn't store the dominant color of an image. Creates the column to store
-// a dominant color in the database. The value will be filled when queried for a
-// one time cost.
-bool MigrateImagesWithNoDominantColor(sql::Connection& db) {
- if (!db.DoesTableExist("images_by_url")) {
- NOTREACHED() << "images_by_url table should exist before migration.";
- return false;
- }
-
- if (!db.DoesColumnExist("images_by_url", "image_dominant_color")) {
- // The initial version doesn't have the image_dominant_color column, it is
- // added to the table here.
- if (!db.Execute(
- "ALTER TABLE images_by_url "
- "ADD COLUMN image_dominant_color INTEGER")) {
- return false;
- }
- }
- return true;
-}
-
-sql::InitStatus EnsureCurrentVersion(sql::Connection& db,
- sql::MetaTable& meta_table) {
- // 1- Newer databases than designed for can't be read.
- if (meta_table.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
- LOG(WARNING) << "Image DB is too new.";
- return sql::INIT_TOO_NEW;
- }
-
- int cur_version = meta_table.GetVersionNumber();
-
- // 2- Put migration code here.
-
- if (cur_version == 1) {
- if (!MigrateImagesWithNoDominantColor(db)) {
- LOG(WARNING) << "Unable to update image DB to version 1.";
- return sql::INIT_FAILURE;
- }
- ++cur_version;
- meta_table.SetVersionNumber(cur_version);
- meta_table.SetCompatibleVersionNumber(
- std::min(cur_version, kCompatibleVersionNumber));
- }
-
- // 3- When the version is too old, just try to continue anyway, there should
- // not be a released product that makes a database too old to handle.
- LOG_IF(WARNING, cur_version < kCurrentVersionNumber)
- << "Image DB version " << cur_version << " is too old to handle.";
-
- return sql::INIT_OK;
-}
-
-sql::InitStatus OpenDatabaseImpl(sql::Connection& db,
- sql::MetaTable& meta_table,
- const base::FilePath& db_path) {
- DCHECK(!db.is_open());
-
- db.set_histogram_tag("BookmarkImages");
- // TODO(noyau): Set page and cache sizes?
- // TODO(noyau): Set error callback?
-
- // Run the database in exclusive mode. Nobody else should be accessing the
- // database while running, and this will give somewhat improved performance.
- db.set_exclusive_locking();
-
- if (!db.Open(db_path))
- return sql::INIT_FAILURE;
-
- // Scope initialization in a transaction so it can't be partially initialized.
- sql::Transaction transaction(&db);
- if (!transaction.Begin())
- return sql::INIT_FAILURE;
-
- // Initialize the meta table.
- int cur_version = meta_table.DoesTableExist(&db)
- ? kCurrentVersionNumber
- : 1; // Only v1 didn't have a meta table.
- if (!meta_table.Init(&db, cur_version,
- std::min(cur_version, kCompatibleVersionNumber)))
- return sql::INIT_FAILURE;
-
- // Create the tables.
- if (!InitTables(db) || !InitIndices(db))
- return sql::INIT_FAILURE;
-
- // Check the version.
- sql::InitStatus version_status = EnsureCurrentVersion(db, meta_table);
- if (version_status != sql::INIT_OK)
- return version_status;
-
- // Initialization is complete.
- if (!transaction.Commit())
- return sql::INIT_FAILURE;
-
- return sql::INIT_OK;
-}
-
-} // namespace
-
-const char PersistentImageStore::kBookmarkImageStoreDb[] =
- "BookmarkImageAndUrlStore.db";
-
-PersistentImageStore::PersistentImageStore(const base::FilePath& path)
- : ImageStore(),
- path_(path.Append(
- base::FilePath::FromUTF8Unsafe(kBookmarkImageStoreDb))) {
-}
-
-bool PersistentImageStore::HasKey(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- if (OpenDatabase() != sql::INIT_OK)
- return false;
-
- sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "SELECT COUNT(*) FROM images_by_url WHERE page_url = ?"));
- statement.BindString(0, page_url.possibly_invalid_spec());
-
- int count = statement.Step() ? statement.ColumnInt(0) : 0;
-
- return !!count;
-}
-
-void PersistentImageStore::Insert(
- const GURL& page_url,
- scoped_refptr<enhanced_bookmarks::ImageRecord> record) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- if (OpenDatabase() != sql::INIT_OK)
- return;
-
- Erase(page_url); // Remove previous image for this url, if any.
- sql::Statement statement(db_.GetCachedStatement(
- SQL_FROM_HERE,
- "INSERT INTO images_by_url "
- "(page_url, image_url, image_data, width, height, image_dominant_color)"
- "VALUES (?, ?, ?, ?, ?, ?)"));
-
- statement.BindString(0, page_url.possibly_invalid_spec());
- statement.BindString(1, record->url.possibly_invalid_spec());
-
- scoped_refptr<base::RefCountedMemory> image_bytes =
- enhanced_bookmarks::BytesForImage(*record->image);
-
- // Insert an empty image in case encoding fails.
- if (!image_bytes.get())
- image_bytes = enhanced_bookmarks::BytesForImage(gfx::Image());
-
- CHECK(image_bytes.get());
-
- statement.BindBlob(2, image_bytes->front(), (int)image_bytes->size());
-
- statement.BindInt(3, record->image->Size().width());
- statement.BindInt(4, record->image->Size().height());
- statement.BindInt(5, record->dominant_color);
- statement.Run();
-}
-
-void PersistentImageStore::Erase(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- if (OpenDatabase() != sql::INIT_OK)
- return;
-
- sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "DELETE FROM images_by_url WHERE page_url = ?"));
- statement.BindString(0, page_url.possibly_invalid_spec());
- statement.Run();
-}
-
-scoped_refptr<enhanced_bookmarks::ImageRecord> PersistentImageStore::Get(
- const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_record(
- new enhanced_bookmarks::ImageRecord());
- if (OpenDatabase() != sql::INIT_OK)
- return image_record;
-
- bool stored_image_record_needs_update = false;
-
- // Scope the SELECT statement.
- {
- sql::Statement statement(db_.GetCachedStatement(
- SQL_FROM_HERE,
- "SELECT image_data, image_url, image_dominant_color FROM images_by_url "
- "WHERE page_url = ?"));
-
- statement.BindString(0, page_url.possibly_invalid_spec());
-
- if (!statement.Step())
- return image_record;
-
- // Image.
- if (statement.ColumnByteLength(0) > 0) {
- scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
- statement.ColumnBlobAsVector(0, &data->data());
- *image_record->image = enhanced_bookmarks::ImageForBytes(data);
- }
-
- // URL.
- image_record->url = GURL(statement.ColumnString(1));
-
- // Dominant color.
- if (statement.ColumnType(2) != sql::COLUMN_TYPE_NULL) {
- image_record->dominant_color = SkColor(statement.ColumnInt(2));
- } else {
- // The dominant color was not computed when the image was first
- // stored.
- // Compute it now.
- image_record->dominant_color =
- enhanced_bookmarks::DominantColorForImage(*image_record->image);
- stored_image_record_needs_update = true;
- }
-
- // Make sure there is only one record for page_url.
- DCHECK(!statement.Step());
- }
-
- if (stored_image_record_needs_update) {
- Erase(page_url);
- Insert(page_url, image_record);
- }
-
- return image_record;
-}
-
-gfx::Size PersistentImageStore::GetSize(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- if (OpenDatabase() != sql::INIT_OK)
- return gfx::Size();
-
- sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "SELECT width, height FROM images_by_url WHERE page_url = ?"));
-
- statement.BindString(0, page_url.possibly_invalid_spec());
-
- while (statement.Step()) {
- if (statement.ColumnByteLength(0) > 0) {
- int width = statement.ColumnInt(0);
- int height = statement.ColumnInt(1);
- return gfx::Size(width, height);
- }
- }
- return gfx::Size();
-}
-
-void PersistentImageStore::GetAllPageUrls(std::set<GURL>* urls) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- DCHECK(urls->empty());
- if (OpenDatabase() != sql::INIT_OK)
- return;
-
- sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "SELECT page_url FROM images_by_url"));
- while (statement.Step())
- urls->insert(GURL(statement.ColumnString(0)));
-}
-
-void PersistentImageStore::ClearAll() {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- if (OpenDatabase() != sql::INIT_OK)
- return;
-
- sql::Statement statement(db_.GetCachedStatement(
- SQL_FROM_HERE, "DELETE FROM images_by_url"));
- statement.Run();
-}
-
-int64_t PersistentImageStore::GetStoreSizeInBytes() {
- base::File file(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
- return file.IsValid() ? file.GetLength() : -1;
-}
-
-PersistentImageStore::~PersistentImageStore() {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-}
-
-sql::InitStatus PersistentImageStore::OpenDatabase() {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- if (db_.is_open())
- return sql::INIT_OK;
-
- const size_t kAttempts = 2;
-
- sql::InitStatus status = sql::INIT_FAILURE;
- for (size_t i = 0; i < kAttempts; ++i) {
- status = OpenDatabaseImpl(db_, meta_table_, path_);
- if (status == sql::INIT_OK)
- return status;
-
- // Can't open, raze().
- if (db_.is_open())
- db_.Raze();
- db_.Close();
- }
-
- DCHECK(false) << "Can't open image DB";
- return sql::INIT_FAILURE;
-}
diff --git a/components/enhanced_bookmarks/persistent_image_store.h b/components/enhanced_bookmarks/persistent_image_store.h
deleted file mode 100644
index 8857f47..0000000
--- a/components/enhanced_bookmarks/persistent_image_store.h
+++ /dev/null
@@ -1,50 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_PERSISTENT_IMAGE_STORE_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_PERSISTENT_IMAGE_STORE_H_
-
-#include "components/enhanced_bookmarks/image_store.h"
-
-#include <stdint.h>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "sql/connection.h"
-#include "sql/init_status.h"
-#include "sql/meta_table.h"
-
-// The PersistentImageStore is an implementation of ImageStore that persists its
-// data on disk.
-class PersistentImageStore : public ImageStore {
- public:
- static const char kBookmarkImageStoreDb[];
-
- // Creates a PersistentImageStore in the directory at the given path.
- explicit PersistentImageStore(const base::FilePath& path);
- bool HasKey(const GURL& page_url) override;
- void Insert(const GURL& page_url,
- scoped_refptr<enhanced_bookmarks::ImageRecord> image) override;
- void Erase(const GURL& page_url) override;
- scoped_refptr<enhanced_bookmarks::ImageRecord> Get(
- const GURL& page_url) override;
- gfx::Size GetSize(const GURL& page_url) override;
- void GetAllPageUrls(std::set<GURL>* urls) override;
- void ClearAll() override;
- int64_t GetStoreSizeInBytes() override;
-
- protected:
- ~PersistentImageStore() override;
-
- private:
- sql::InitStatus OpenDatabase();
-
- const base::FilePath path_;
- sql::Connection db_;
- sql::MetaTable meta_table_;
-
- DISALLOW_COPY_AND_ASSIGN(PersistentImageStore);
-};
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_PERSISTENT_IMAGE_STORE_H_
diff --git a/components/enhanced_bookmarks/pref_names.cc b/components/enhanced_bookmarks/pref_names.cc
deleted file mode 100644
index 6eb0777..0000000
--- a/components/enhanced_bookmarks/pref_names.cc
+++ /dev/null
@@ -1,13 +0,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 "components/enhanced_bookmarks/pref_names.h"
-
-namespace enhanced_bookmarks {
-namespace prefs {
-
-const char kBookmarkClusters[] =
- "enhanced_bookmarks_component.bookmark_clusters";
-} // namespace prefs
-} // namespace enhanced_bookmarks
diff --git a/components/enhanced_bookmarks/pref_names.h b/components/enhanced_bookmarks/pref_names.h
deleted file mode 100644
index a063d7e..0000000
--- a/components/enhanced_bookmarks/pref_names.h
+++ /dev/null
@@ -1,19 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_PREF_NAMES_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_PREF_NAMES_H_
-
-#include "build/build_config.h"
-
-namespace enhanced_bookmarks {
-namespace prefs {
-
-// Stores the last retrieved bookmark clusters from the server.
-extern const char kBookmarkClusters[];
-
-} // namespace prefs
-} // namespace enhanced_bookmarks
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_PREF_NAMES_H_
diff --git a/components/enhanced_bookmarks/proto/BUILD.gn b/components/enhanced_bookmarks/proto/BUILD.gn
deleted file mode 100644
index 579884a..0000000
--- a/components/enhanced_bookmarks/proto/BUILD.gn
+++ /dev/null
@@ -1,13 +0,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.
-
-import("//third_party/protobuf/proto_library.gni")
-
-proto_library("proto") {
- sources = [
- "cluster.proto",
- "metadata.proto",
- "search.proto",
- ]
-}
diff --git a/components/enhanced_bookmarks/proto/cluster.proto b/components/enhanced_bookmarks/proto/cluster.proto
deleted file mode 100644
index 9901541..0000000
--- a/components/enhanced_bookmarks/proto/cluster.proto
+++ /dev/null
@@ -1,34 +0,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.
-//
-syntax = "proto2";
-option optimize_for = LITE_RUNTIME;
-
-package image_collections;
-
-message ClusterRequest {
- // Optional list of docs we want to cluster--a subset of the user's available
- // docs.
- repeated string docs = 1;
-
- // When docs is empty, used to determine which clips are clustered. If set to
- // true, cluster all the user's clips. Otherwise (default) cluster all of the
- // user's uncategorized clips.
- optional bool cluster_all = 3 [default = false];
-
- extensions 2;
-}
-
-message ClusterResponse {
- message Cluster {
- repeated string docs = 1;
- // May be empty or unset if no reasonable title could be found.
- optional string title = 2;
- }
-
- // Each of ClusterRequest.docs will exist in exactly one cluster. Some
- // clusters may be singletons, so
- // ClusterResponse.clusters_size() <= ClusterRequest.docs_size().
- repeated Cluster clusters = 1;
-}
diff --git a/components/enhanced_bookmarks/proto/metadata.proto b/components/enhanced_bookmarks/proto/metadata.proto
deleted file mode 100644
index 4a5f2ec..0000000
--- a/components/enhanced_bookmarks/proto/metadata.proto
+++ /dev/null
@@ -1,60 +0,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.
-//
-syntax = "proto2";
-option optimize_for = LITE_RUNTIME;
-
-package image.collections;
-
-message ImageData {
- // Encrypted 64-bit image doc id, if it has been crawled,
- // e.g. "kY7_4LKgNqDrbM:"
- optional string doc_id = 1;
-
- message ImageInfo {
- // The (normalized) URL this image can be found at.
- optional string url = 1;
-
- // The dimensions in pixels.
- optional int32 width = 2;
- optional int32 height = 3;
- }
-
- // Information about the original collected image.
- optional ImageInfo original_info = 2;
-
- // Information about the server hosted thumbnail.
- optional ImageInfo thumbnail_info = 3;
-
- // The expiration timestamp of the served thumbnail, in microseconds since
- // epoch. The thumbnail is only guaranteed until this time, afterwards the
- // URL may be broken.
- // If expiration_timestamp is not present, then whoever set the thumbnail_info
- // should guarantee that the thumbnail will not expire.
- optional int64 expiration_timestamp = 5;
-
- // Represents an explicit user action to remove an image. This will prevent
- // any additional backfilling once this is set.
- optional bool user_removed_image = 6;
-}
-
-message PageData {
- // The title of the web page.
- optional string title = 1;
-
- // A snippet of text from the web page, either computed by us or chosen by
- // the user.
- optional string snippet = 2;
-
- // The (normalized) URL of the web page.
- optional string url = 3;
-
- // The /url redirect signed URL for the web page. This could be appended to
- // "www.google.com" to create a URL redirect.
- optional string signed_url = 5;
-
- // The doc id of the page, if in the index. Uses the same encrypted docid
- // format as ImageData.
- optional string doc_id = 4;
-}
diff --git a/components/enhanced_bookmarks/proto/search.proto b/components/enhanced_bookmarks/proto/search.proto
deleted file mode 100644
index df508ab..0000000
--- a/components/enhanced_bookmarks/proto/search.proto
+++ /dev/null
@@ -1,30 +0,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.
-//
-syntax = "proto2";
-option optimize_for = LITE_RUNTIME;
-
-package image.collections;
-
-// Contains the result of a full text search.
-message CorpusSearchResult {
- // Encodes the status of the response.
- enum Status {
- UNKNOWN = 0;
- OK = 1;
- FAILED_RPC = 2;
- NO_VALID_BACKEND = 3;
- INVALID_INPUT = 4;
- }
- optional Status status = 1;
-
- // For each results returns the clip id, the title and a snippet highlighting
- // the context of the match on the search term.
- message ClipResult {
- optional string clip_id = 1;
- optional string title = 2;
- optional string snippet = 3;
- }
- repeated ClipResult results = 2;
-}
diff --git a/components/enhanced_bookmarks/test_image_store.cc b/components/enhanced_bookmarks/test_image_store.cc
deleted file mode 100644
index b28bd70..0000000
--- a/components/enhanced_bookmarks/test_image_store.cc
+++ /dev/null
@@ -1,89 +0,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 "components/enhanced_bookmarks/test_image_store.h"
-
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/geometry/size.h"
-#include "url/gurl.h"
-
-TestImageStore::TestImageStore() {
-}
-
-bool TestImageStore::HasKey(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- return store_.find(page_url) != store_.end();
-}
-
-void TestImageStore::Insert(
- const GURL& page_url,
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- Erase(page_url);
- store_.insert(std::make_pair(page_url, image_record));
-}
-
-void TestImageStore::Erase(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- store_.erase(page_url);
-}
-
-scoped_refptr<enhanced_bookmarks::ImageRecord> TestImageStore::Get(
- const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- if (store_.find(page_url) == store_.end()) {
- return scoped_refptr<enhanced_bookmarks::ImageRecord>(
- new enhanced_bookmarks::ImageRecord());
- }
-
- return store_[page_url];
-}
-
-gfx::Size TestImageStore::GetSize(const GURL& page_url) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- ImageMap::const_iterator pair_enumerator = store_.find(page_url);
- if (pair_enumerator == store_.end())
- return gfx::Size();
-
- return store_[page_url]->image->Size();
-}
-
-void TestImageStore::GetAllPageUrls(std::set<GURL>* urls) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- DCHECK(urls->empty());
-
- for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it)
- urls->insert(it->first);
-}
-
-void TestImageStore::ClearAll() {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-
- store_.clear();
-}
-
-int64_t TestImageStore::GetStoreSizeInBytes() {
- // Not 100% accurate, but it's for testing so the actual value is not
- // important.
- int64_t size = sizeof(store_);
- for (ImageMap::const_iterator it = store_.begin(); it != store_.end(); ++it) {
- size += sizeof(it->first);
- size += it->first.spec().length();
- size += sizeof(it->second);
- SkBitmap bitmap = it->second->image->AsBitmap();
- size += bitmap.getSize();
- size += it->second->url.spec().length();
- size += sizeof(it->second->dominant_color);
- }
- return size;
-}
-
-TestImageStore::~TestImageStore() {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
-}
diff --git a/components/enhanced_bookmarks/test_image_store.h b/components/enhanced_bookmarks/test_image_store.h
deleted file mode 100644
index e17c71c..0000000
--- a/components/enhanced_bookmarks/test_image_store.h
+++ /dev/null
@@ -1,42 +0,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.
-
-#ifndef COMPONENTS_ENHANCED_BOOKMARKS_TEST_IMAGE_STORE_H_
-#define COMPONENTS_ENHANCED_BOOKMARKS_TEST_IMAGE_STORE_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "components/enhanced_bookmarks/image_store.h"
-
-// The TestImageStore is an implementation of ImageStore that keeps all its
-// data in memory. When deallocated all the associations are lost.
-// Used in tests.
-class TestImageStore : public ImageStore {
- public:
- TestImageStore();
- bool HasKey(const GURL& page_url) override;
- void Insert(
- const GURL& page_url,
- scoped_refptr<enhanced_bookmarks::ImageRecord> image_record) override;
- void Erase(const GURL& page_url) override;
- scoped_refptr<enhanced_bookmarks::ImageRecord> Get(
- const GURL& page_url) override;
- gfx::Size GetSize(const GURL& page_url) override;
- void GetAllPageUrls(std::set<GURL>* urls) override;
- void ClearAll() override;
- int64_t GetStoreSizeInBytes() override;
-
- protected:
- ~TestImageStore() override;
-
- private:
- typedef std::map<const GURL, scoped_refptr<enhanced_bookmarks::ImageRecord>>
- ImageMap;
- ImageMap store_;
-
- DISALLOW_COPY_AND_ASSIGN(TestImageStore);
-};
-
-#endif // COMPONENTS_ENHANCED_BOOKMARKS_TEST_IMAGE_STORE_H_
diff --git a/components/enhanced_bookmarks_strings.grdp b/components/enhanced_bookmarks_strings.grdp
deleted file mode 100644
index 3892985..0000000
--- a/components/enhanced_bookmarks_strings.grdp
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<grit-part>
- <message name="IDS_FLAGS_ENHANCED_BOOKMARKS_NAME" desc="Name of about:flags option to enable Enhanced Bookmarks extension.">
- Enhanced Bookmarks
- </message>
- <message name="IDS_FLAGS_ENHANCED_BOOKMARKS_DESCRIPTION" desc="Description of about:flags option to enable Enhanced Bookmarks extension.">
- Provides an off switch for enhanced bookmarks experiment
- </message>
-</grit-part>
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index da49571..387e6f9 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -963,7 +963,7 @@ enum HistogramValue {
DELETED_COPRESENCESOCKET_DESTROYPEER,
DELETED_COPRESENCESOCKET_SEND,
DELETED_COPRESENCESOCKET_DISCONNECT,
- BOOKMARKMANAGERPRIVATE_SETVERSION,
+ DELETED_BOOKMARKMANAGERPRIVATE_SETVERSION,
FILESYSTEMPROVIDER_NOTIFY,
USB_GETUSERSELECTEDDEVICES,
INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG,
diff --git a/ios/chrome/BUILD.gn b/ios/chrome/BUILD.gn
index 0371de2..b651982 100644
--- a/ios/chrome/BUILD.gn
+++ b/ios/chrome/BUILD.gn
@@ -45,7 +45,6 @@ test("ios_chrome_unittests") {
"//base:prefs_test_support",
"//base/test:test_support",
"//components/bookmarks/test",
- "//components/enhanced_bookmarks:test_support",
"//components/favicon_base",
"//components/metrics",
"//components/metrics:test_support",
diff --git a/ios/chrome/browser/BUILD.gn b/ios/chrome/browser/BUILD.gn
index c282ab6..86ce135 100644
--- a/ios/chrome/browser/BUILD.gn
+++ b/ios/chrome/browser/BUILD.gn
@@ -517,7 +517,6 @@ source_set("browser") {
"//components/dom_distiller/core",
"//components/dom_distiller/ios",
"//components/domain_reliability",
- "//components/enhanced_bookmarks",
"//components/favicon/core",
"//components/favicon_base",
"//components/gcm_driver",
@@ -635,7 +634,6 @@ source_set("about_flags") {
"//base",
"//components/autofill/core/common",
"//components/dom_distiller/core",
- "//components/enhanced_bookmarks",
"//components/flags_ui",
"//components/strings",
"//google_apis",
diff --git a/ios/chrome/browser/DEPS b/ios/chrome/browser/DEPS
index 2c11e45..5764658 100644
--- a/ios/chrome/browser/DEPS
+++ b/ios/chrome/browser/DEPS
@@ -19,7 +19,6 @@ include_rules = [
"+components/dom_distiller/core",
"+components/dom_distiller/ios",
"+components/domain_reliability",
- "+components/enhanced_bookmarks",
"+components/favicon/core",
"+components/favicon_base",
"+components/flags_ui",
diff --git a/ios/chrome/browser/about_flags.mm b/ios/chrome/browser/about_flags.mm
index df6eb55..b5bf587 100644
--- a/ios/chrome/browser/about_flags.mm
+++ b/ios/chrome/browser/about_flags.mm
@@ -21,7 +21,6 @@
#include "base/sys_info.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/dom_distiller/core/dom_distiller_switches.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h"
#include "components/flags_ui/feature_entry.h"
#include "components/flags_ui/feature_entry_macros.h"
#include "components/flags_ui/flags_storage.h"
@@ -56,13 +55,6 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
flags_ui::kOsIos,
ENABLE_DISABLE_VALUE_TYPE(switches::kEnableContextualSearch,
switches::kDisableContextualSearch)},
- {"enhanced-bookmarks-experiment", IDS_FLAGS_ENHANCED_BOOKMARKS_NAME,
- IDS_FLAGS_ENHANCED_BOOKMARKS_DESCRIPTION,
- flags_ui::kOsIos,
- ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(switches::kEnhancedBookmarksExperiment,
- "1",
- switches::kEnhancedBookmarksExperiment,
- "0")},
};
// Add all switches from experimental flags to |command_line|.
@@ -126,17 +118,6 @@ void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
command_line->AppendSwitch(switches::kDisableIOSPasswordGeneration);
}
- // Populate command line flags from EnableBookmarkCollections.
- NSString* bookmarkCollectionState =
- [defaults stringForKey:@"BookmarkCollectionState"];
- if ([bookmarkCollectionState isEqualToString:@"OptIn"]) {
- command_line->AppendSwitchNative(switches::kEnhancedBookmarksExperiment,
- "1");
- } else if ([bookmarkCollectionState isEqualToString:@"OptOut"]) {
- command_line->AppendSwitchNative(switches::kEnhancedBookmarksExperiment,
- "0");
- }
-
// Web page replay flags.
BOOL webPageReplayEnabled = [defaults boolForKey:@"WebPageReplayEnabled"];
NSString* webPageReplayProxy =
diff --git a/ios/chrome/browser/experimental_flags.mm b/ios/chrome/browser/experimental_flags.mm
index 76b321c..662dd6d 100644
--- a/ios/chrome/browser/experimental_flags.mm
+++ b/ios/chrome/browser/experimental_flags.mm
@@ -16,7 +16,6 @@
#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "components/autofill/core/common/autofill_switches.h"
-#include "components/enhanced_bookmarks/enhanced_bookmark_switches_ios.h"
#include "components/variations/variations_associated_data.h"
#include "ios/chrome/browser/chrome_switches.h"
#include "ios/web/public/web_view_creation_util.h"
@@ -49,24 +48,7 @@ bool IsAlertOnBackgroundUploadEnabled() {
}
bool IsBookmarkCollectionEnabled() {
- // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
- // "" - default, "0" - user opted out, "1" - user opted in. Tests also use
- // the command line flag to force enhanced bookmark to be on.
- // If none is specified, the finch experiment is checked. If not disabled in
- // finch, the default is opt-in.
- std::string switch_value =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kEnhancedBookmarksExperiment);
- if (switch_value == "1")
- return true;
- if (switch_value == "0")
- return false;
-
- // Check if the finch experiment is turned on.
- std::string group_name =
- base::FieldTrialList::FindFullName("IOSNewBookmarksUI");
- return !base::StartsWith(group_name, "Disabled",
- base::CompareCase::INSENSITIVE_ASCII);
+ return true;
}
void SetWKWebViewTrialEligibility(bool eligible) {
diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp
index 9374c69..4ecd67e 100644
--- a/ios/chrome/ios_chrome.gyp
+++ b/ios/chrome/ios_chrome.gyp
@@ -65,7 +65,6 @@
'../../components/components.gyp:dom_distiller_core',
'../../components/components.gyp:dom_distiller_ios',
'../../components/components.gyp:domain_reliability',
- '../../components/components.gyp:enhanced_bookmarks',
'../../components/components.gyp:favicon_base',
'../../components/components.gyp:favicon_core',
'../../components/components.gyp:gcm_driver',
@@ -701,7 +700,6 @@
'../../base/base.gyp:base',
'../../components/components.gyp:autofill_core_common',
'../../components/components.gyp:dom_distiller_core',
- '../../components/components.gyp:enhanced_bookmarks',
'../../components/components.gyp:flags_ui',
'../../components/components.gyp:sync_driver',
'../../components/components_strings.gyp:components_strings',
diff --git a/ios/chrome/ios_chrome_tests.gyp b/ios/chrome/ios_chrome_tests.gyp
index 2130a16..367dfd1 100644
--- a/ios/chrome/ios_chrome_tests.gyp
+++ b/ios/chrome/ios_chrome_tests.gyp
@@ -15,7 +15,6 @@
'../../base/base.gyp:base_prefs_test_support',
'../../base/base.gyp:test_support_base',
'../../components/components.gyp:bookmarks_test_support',
- '../../components/components.gyp:enhanced_bookmarks_test_support',
'../../components/components.gyp:favicon_base',
'../../components/components.gyp:metrics',
'../../components/components.gyp:metrics_test_support',
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index bc68c7b..ce77e63 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -63894,7 +63894,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="902" label="DELETED_COPRESENCESOCKET_DESTROYPEER"/>
<int value="903" label="DELETED_COPRESENCESOCKET_SEND"/>
<int value="904" label="DELETED_COPRESENCESOCKET_DISCONNECT"/>
- <int value="905" label="BOOKMARKMANAGERPRIVATE_SETVERSION"/>
+ <int value="905" label="DELETED_BOOKMARKMANAGERPRIVATE_SETVERSION"/>
<int value="906" label="FILESYSTEMPROVIDER_NOTIFY"/>
<int value="907" label="USB_GETUSERSELECTEDDEVICES"/>
<int value="908" label="INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG"/>