Index: components/enhanced_bookmarks/bookmark_server_cluster_service.h |
diff --git a/components/enhanced_bookmarks/bookmark_server_cluster_service.h b/components/enhanced_bookmarks/bookmark_server_cluster_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..93626273bbf5c454fe159ab18aa126e4156bad73 |
--- /dev/null |
+++ b/components/enhanced_bookmarks/bookmark_server_cluster_service.h |
@@ -0,0 +1,116 @@ |
+// 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; |
+class BookmarkServerClusterClient; |
Yaron
2014/09/05 05:18:01
unused
noyau (Ping after 24h)
2014/09/10 08:53:57
Done.
|
+ |
+namespace enhanced_bookmarks { |
+ |
+// Manages requests to the bookmark server to do just-in-time requests. |
Yaron
2014/09/05 05:18:01
seems out of date. Should just talk about clusteri
noyau (Ping after 24h)
2014/09/10 08:53:57
Done.
|
+class BookmarkServerClusterService : public KeyedService, |
+ public BookmarkServerService, |
+ public SigninManagerBase::Observer { |
+ public: |
+ typedef std::map<std::string, std::vector<std::string> > ClusterMap; |
+ BookmarkServerClusterService( |
+ const std::string& application_language_code, |
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
+ ProfileOAuth2TokenService* token_service, |
+ SigninManagerBase* signin_manager, |
+ BookmarkModel* bookmark_model, |
+ PrefService* pref_service); |
+ virtual ~BookmarkServerClusterService(); |
+ |
+ // Retrieves all the bookmarks associated with a cluster. |
+ 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. |
+ const std::vector<std::string> GetClusters() const; |
+ |
+ // Registers server cluster service prefs. |
+ static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry); |
+ |
+ protected: |
+ virtual net::URLFetcher* CreateFetcherWithToken( |
+ const std::string& access_token) OVERRIDE; |
+ |
+ virtual bool ProcessResponse(const std::string& response, |
+ bool* should_notify) OVERRIDE; |
+ |
+ virtual void CleanAfterFailure() OVERRIDE; |
+ |
+ // BookmarkModelObserver methods. |
+ virtual void BookmarkModelLoaded(BookmarkModel* model, |
+ bool ids_reassigned) OVERRIDE; |
+ virtual void BookmarkNodeAdded(BookmarkModel* model, |
+ const BookmarkNode* parent, |
+ int index) OVERRIDE; |
+ virtual void BookmarkMetaInfoChanged(BookmarkModel* model, |
+ const BookmarkNode* node) OVERRIDE; |
+ virtual void BookmarkAllUserNodesRemoved( |
+ BookmarkModel* model, |
+ const std::set<GURL>& removed_urls) OVERRIDE; |
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); |
+ FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Serialization); |
+ FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SaveToPrefs); |
+ FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, BadAuth); |
+ 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_| 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 UpdateModel(ClusterMap* cluster_map); |
+ // Updates |cluster_data_| from profile prefs. |
+ void LoadModel(); |
+ |
+ // Returns true on success. |
+ // The result is swapped into |out_result|. |
+ static bool Serialize(const ClusterMap& cluster_map, |
+ std::string* out_result, |
+ 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 std::string& input, |
+ ClusterMap* out_map, |
+ const std::string& auth_id); |
+ |
+ // 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 starsid. |
+ ClusterMap cluster_data_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterService); |
+}; |
+} // namespace enhanced_bookmarks |
+ |
+#endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_ |