diff options
author | sorin <sorin@chromium.org> | 2014-10-07 18:06:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-08 01:07:24 +0000 |
commit | 67861504c4cf1b53c7f03662384e58b92772a434 (patch) | |
tree | f87503f288f6a88b344e6f9dd8f7f680ce18b3af /components/enhanced_bookmarks | |
parent | 4e645e9bc69350f9799262584ad8b82255d0dd8e (diff) | |
download | chromium_src-67861504c4cf1b53c7f03662384e58b92772a434.zip chromium_src-67861504c4cf1b53c7f03662384e58b92772a434.tar.gz chromium_src-67861504c4cf1b53c7f03662384e58b92772a434.tar.bz2 |
Revert of Bring up of the enhanced bookmarks cluster service. (patchset #13 id:320001 of https://codereview.chromium.org/539173004/)
Reason for revert:
This CL added static initializers which broke the sizes bots on Mac, Linux, and Linux x64.
Before the change:
# Static initializers in src/out/Release/chrome:
# HINT: To get this list, run tools/linux/dump_static_initializers.py
# HINT: diff against the log from the last run to see what changed
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x65
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xaa
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x6b
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xc2
# atomicops_internals_x86_gcc.cc google::protobuf::internal::AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc google::protobuf::internal::AtomicOps_Internalx86CPUFeatures+0x1
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x65
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xaa
# atomicops_internals_x86_gcc.cc v8::base::AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# debugallocation_shim.cc module_enter_exit_hook
# debugallocation_shim.cc (anonymous namespace)::large_alloc_threshold
# debugallocation_shim.cc TCMallocGuard::TCMallocGuard()
# debugallocation_shim.cc __cxa_atexit@plt [registers a dtor to run at exit]
# debugallocation_shim.cc __init_array_end+0x3538
# debugallocation_shim.cc __init_array_end+0x3540
# debugallocation_shim.cc __init_array_end+0x3548
# memory_region_map.cc libpthread_initialized
# spinlock.cc _GLOBAL__sub_I_spinlock.cc+0x12
# spinlock.cc NumCPUs()
# spinlock.cc adaptive_spin_count
# spinlock_internal.cc _GLOBAL__sub_I_spinlock_internal.cc+0x79
# spinlock_internal.cc have_futex
# spinlock_internal.cc futex_private_flag
# spinlock_internal.cc syscall@plt
# Found 34 static initializers in 7 files.
After the change:
# Static initializers in src/out/Release/chrome:
# HINT: To get this list, run tools/linux/dump_static_initializers.py
# HINT: diff against the log from the last run to see what changed
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x65
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xaa
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x6b
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xc2
# atomicops_internals_x86_gcc.cc google::protobuf::internal::AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc google::protobuf::internal::AtomicOps_Internalx86CPUFeatures+0x1
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# atomicops_internals_x86_gcc.cc .L.str
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0x65
# atomicops_internals_x86_gcc.cc _GLOBAL__sub_I_atomicops_internals_x86_gcc.cc+0xaa
# atomicops_internals_x86_gcc.cc v8::base::AtomicOps_Internalx86CPUFeatures
# atomicops_internals_x86_gcc.cc __stack_chk_fail@plt
# atomicops_internals_x86_gcc.cc strcmp@plt
# bookmark_server_cluster_service.cc .L.str
# bookmark_server_cluster_service.cc (anonymous namespace)::kClusterUrl
# bookmark_server_cluster_service.cc std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@plt
# bookmark_server_cluster_service.cc __cxa_atexit@plt [registers a dtor to run at exit]
# bookmark_server_cluster_service.cc __init_array_end+0x3540
# bookmark_server_cluster_service.cc __init_array_end+0xe220
# debugallocation_shim.cc module_enter_exit_hook
# debugallocation_shim.cc (anonymous namespace)::large_alloc_threshold
# debugallocation_shim.cc TCMallocGuard::TCMallocGuard()
# debugallocation_shim.cc __cxa_atexit@plt [registers a dtor to run at exit]
# debugallocation_shim.cc __init_array_end+0x3538
# debugallocation_shim.cc __init_array_end+0x3540
# debugallocation_shim.cc __init_array_end+0x3548
# memory_region_map.cc libpthread_initialized
# spinlock.cc _GLOBAL__sub_I_spinlock.cc+0x12
# spinlock.cc NumCPUs()
# spinlock.cc adaptive_spin_count
# spinlock_internal.cc _GLOBAL__sub_I_spinlock_internal.cc+0x79
# spinlock_internal.cc have_futex
# spinlock_internal.cc futex_private_flag
# spinlock_internal.cc syscall@plt
# Found 40 static initializers in 8 files.
See this bot, as an example: https://build.chromium.org/p/chromium/builders/Linux%20x64/builds/71728/steps/sizes/logs/stdio
In addition to this, the CL declares a static instance of std::string which is not allowed. The S string constants also should be declared as const char kPrefServiceVersionKey[] = "version" for example.
Original issue's description:
> Bring up of the enhanced bookmarks cluster service.
>
> This service retrieves the cluster of bookmarks from the bookmark
> server.
>
> BUG=None
>
> Committed: https://crrev.com/6bb374fc58bfeeb7966b6a548b1c7b41af9c8e47
> Cr-Commit-Position: refs/heads/master@{#298582}
TBR=blundell@chromium.org,yfriedman@chromium.org,mcolbert@chromium.org,kkimlabs@chromium.org,battre@chromium.org,zea@chromium.org,sky@chromium.org,noyau@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=None
Review URL: https://codereview.chromium.org/641473002
Cr-Commit-Position: refs/heads/master@{#298629}
Diffstat (limited to 'components/enhanced_bookmarks')
14 files changed, 24 insertions, 548 deletions
diff --git a/components/enhanced_bookmarks/BUILD.gn b/components/enhanced_bookmarks/BUILD.gn index 736ac97..5ff23d6 100644 --- a/components/enhanced_bookmarks/BUILD.gn +++ b/components/enhanced_bookmarks/BUILD.gn @@ -4,32 +4,15 @@ source_set("enhanced_bookmarks") { sources = [ - "bookmark_image_service.cc", - "bookmark_image_service.h", - "bookmark_server_cluster_service.cc", - "bookmark_server_cluster_service.h", - "bookmark_server_search_service.cc", - "bookmark_server_search_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_utils.cc", - "enhanced_bookmark_utils.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 = [ diff --git a/components/enhanced_bookmarks/DEPS b/components/enhanced_bookmarks/DEPS index 2716044..5383ad5 100644 --- a/components/enhanced_bookmarks/DEPS +++ b/components/enhanced_bookmarks/DEPS @@ -1,7 +1,6 @@ include_rules = [ "+components/bookmarks", "+components/keyed_service", - "+components/pref_registry", "+components/signin", "+google_apis/gaia", "+jni", 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 9cdd243..0000000 --- a/components/enhanced_bookmarks/bookmark_server_cluster_service.cc +++ /dev/null @@ -1,315 +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 "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 "net/base/url_util.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_context_getter.h" - -namespace { -const std::string 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, - PrefService* pref_service) - : BookmarkServerService(request_context_getter, - token_service, - signin_manager, - enhanced_bookmark_model), - application_language_code_(application_language_code), - pref_service_(pref_service) { - LoadModel(); - - if (model_->loaded()) - TriggerTokenRequest(false); - - GetSigninManager()->AddObserver(this); -} - -BookmarkServerClusterService::~BookmarkServerClusterService() { - 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_) - cluster_names.push_back(pair.first); - - return cluster_names; -} - -// static -void BookmarkServerClusterService::RegisterPrefs( - user_prefs::PrefRegistrySyncable* registry) { - registry->RegisterDictionaryPref( - prefs::kBookmarkClusters, - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); -} - -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) { - // Nothing to do. -} - -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. -} - -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); -} - -// -// 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.Pass(); -} - -// 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 ae7cc08..0000000 --- a/components/enhanced_bookmarks/bookmark_server_cluster_service.h +++ /dev/null @@ -1,125 +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 "components/enhanced_bookmarks/bookmark_server_service.h" -#include "components/keyed_service/content/browser_context_keyed_service_factory.h" -#include "components/signin/core/browser/signin_manager_base.h" -#include "net/url_request/url_fetcher.h" - -class PrefService; - -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. -class BookmarkServerClusterService : public KeyedService, - public BookmarkServerService, - public SigninManagerBase::Observer { - 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, - PrefService* pref_service); - virtual ~BookmarkServerClusterService(); - - // 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 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 BookmarkNode* bookmark) const; - - // Dynamically generates a vector of all clusters names. - const std::vector<std::string> GetClusters() const; - - // Registers server cluster service prefs. - static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry); - - protected: - // BookmarkServerService methods. - virtual scoped_ptr<net::URLFetcher> CreateFetcher() override; - virtual bool ProcessResponse(const std::string& response, - bool* should_notify) override; - virtual void CleanAfterFailure() override; - - // EnhancedBookmarkModelObserver methods. - virtual void EnhancedBookmarkModelLoaded() override; - virtual void EnhancedBookmarkAdded(const BookmarkNode* node) override; - virtual void EnhancedBookmarkRemoved(const BookmarkNode* node) override; - virtual void EnhancedBookmarkAllUserNodesRemoved() override; - virtual void EnhancedBookmarkRemoteIdChanged( - const BookmarkNode* node, - const std::string& old_remote_id, - const std::string& remote_id) override; - - private: - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SignOut); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Serialization); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SaveToPrefs); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, BadAuth); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, EmptyAuth); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, - ClearClusterMapOnRemoveAllBookmarks); - - // Overriden from SigninManagerBase::Observer. - virtual 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(); - - // 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_; - // 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_; - - 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_search_service.cc b/components/enhanced_bookmarks/bookmark_server_search_service.cc index 274c822..5ab2d66 100644 --- a/components/enhanced_bookmarks/bookmark_server_search_service.cc +++ b/components/enhanced_bookmarks/bookmark_server_search_service.cc @@ -4,7 +4,6 @@ #include "components/enhanced_bookmarks/bookmark_server_search_service.h" -#include "components/enhanced_bookmarks/enhanced_bookmark_model.h" #include "components/enhanced_bookmarks/enhanced_bookmark_utils.h" #include "components/enhanced_bookmarks/proto/search.pb.h" #include "net/base/url_util.h" @@ -57,16 +56,15 @@ std::vector<const BookmarkNode*> BookmarkServerSearchService::ResultForQuery( return result; } -scoped_ptr<net::URLFetcher> BookmarkServerSearchService::CreateFetcher() { +net::URLFetcher* BookmarkServerSearchService::CreateFetcher() { // Add the necessary arguments to the URI. GURL url(kSearchUrl); url = net::AppendQueryParameter(url, "output", "proto"); url = net::AppendQueryParameter(url, "q", current_query_); - 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::GET, this)); + net::URLFetcher* url_fetcher = + net::URLFetcher::Create(url, net::URLFetcher::GET, this); return url_fetcher; } diff --git a/components/enhanced_bookmarks/bookmark_server_search_service.h b/components/enhanced_bookmarks/bookmark_server_search_service.h index 946b184..94ea943 100644 --- a/components/enhanced_bookmarks/bookmark_server_search_service.h +++ b/components/enhanced_bookmarks/bookmark_server_search_service.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "components/bookmarks/browser/base_bookmark_model_observer.h" #include "components/enhanced_bookmarks/bookmark_server_service.h" #include "net/url_request/url_fetcher.h" @@ -37,7 +38,8 @@ class BookmarkServerSearchService : public BookmarkServerService { std::vector<const BookmarkNode*> ResultForQuery(const std::string& query); protected: - virtual scoped_ptr<net::URLFetcher> CreateFetcher() override; + + virtual net::URLFetcher* CreateFetcher() override; virtual bool ProcessResponse(const std::string& response, bool* should_notify) override; diff --git a/components/enhanced_bookmarks/bookmark_server_service.cc b/components/enhanced_bookmarks/bookmark_server_service.cc index 08217a2..b6bd583 100644 --- a/components/enhanced_bookmarks/bookmark_server_service.cc +++ b/components/enhanced_bookmarks/bookmark_server_service.cc @@ -48,7 +48,11 @@ void BookmarkServerService::RemoveObserver( const BookmarkNode* BookmarkServerService::BookmarkForRemoteId( const std::string& remote_id) const { - return model_->BookmarkForRemoteId(remote_id); + std::map<std::string, const BookmarkNode*>::const_iterator it = + starsid_to_bookmark_.find(remote_id); + if (it == starsid_to_bookmark_.end()) + return NULL; + return it->second; } const std::string BookmarkServerService::RemoteIDForBookmark( @@ -87,8 +91,7 @@ void BookmarkServerService::OnGetTokenSuccess( const OAuth2TokenService::Request* request, const std::string& access_token, const base::Time& expiration_time) { - url_fetcher_ = CreateFetcher(); - + url_fetcher_.reset(CreateFetcher()); // Free the token request. token_request_.reset(); diff --git a/components/enhanced_bookmarks/bookmark_server_service.h b/components/enhanced_bookmarks/bookmark_server_service.h index d8cba89..8df0e2f 100644 --- a/components/enhanced_bookmarks/bookmark_server_service.h +++ b/components/enhanced_bookmarks/bookmark_server_service.h @@ -64,7 +64,7 @@ class BookmarkServerService : protected net::URLFetcherDelegate, 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; + virtual 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 @@ -86,7 +86,6 @@ class BookmarkServerService : protected net::URLFetcherDelegate, private: FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); - FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SignOut); FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, ClearClusterMapOnRemoveAllBookmarks); @@ -112,6 +111,8 @@ class BookmarkServerService : protected net::URLFetcherDelegate, scoped_refptr<net::URLRequestContextGetter> request_context_getter_; // The fetcher used to query the server. scoped_ptr<net::URLFetcher> url_fetcher_; + // A map from stars.id to bookmark nodes. With no null entries. + std::map<std::string, const BookmarkNode*> starsid_to_bookmark_; DISALLOW_COPY_AND_ASSIGN(BookmarkServerService); }; diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.cc b/components/enhanced_bookmarks/enhanced_bookmark_model.cc index 7f89f82..6ffcaf3 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_model.cc +++ b/components/enhanced_bookmarks/enhanced_bookmark_model.cc @@ -91,18 +91,15 @@ EnhancedBookmarkModel::EnhancedBookmarkModel(BookmarkModel* bookmark_model, } 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; - } + FOR_EACH_OBSERVER(EnhancedBookmarkModelObserver, + observers_, + EnhancedBookmarkModelShuttingDown()); + weak_ptr_factory_.InvalidateWeakPtrs(); + bookmark_model_->RemoveObserver(this); + bookmark_model_ = NULL; } void EnhancedBookmarkModel::AddObserver( diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.h b/components/enhanced_bookmarks/enhanced_bookmark_model.h index 19cc030..70fe42e 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_model.h +++ b/components/enhanced_bookmarks/enhanced_bookmark_model.h @@ -127,9 +127,6 @@ class EnhancedBookmarkModel : public KeyedService, // 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); @@ -182,6 +179,9 @@ class EnhancedBookmarkModel : public KeyedService, void SetMultipleMetaInfo(const BookmarkNode* node, BookmarkNode::MetaInfoMap meta_info); + // Returns the version string to use when setting stars.version. + std::string GetVersionString(); + BookmarkModel* bookmark_model_; bool loaded_; 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 index 579884a..f6e932d 100644 --- a/components/enhanced_bookmarks/proto/BUILD.gn +++ b/components/enhanced_bookmarks/proto/BUILD.gn @@ -6,7 +6,6 @@ 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; -} |