Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(724)

Side by Side Diff: components/enhanced_bookmarks/bookmark_server_cluster_service.h

Issue 539173004: Bring up of the enhanced bookmarks cluster service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@intermediary2
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
5 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
6
7 #include <string>
8 #include <vector>
9
10 #include "base/compiler_specific.h"
11 #include "components/enhanced_bookmarks/bookmark_server_service.h"
12 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
13 #include "components/signin/core/browser/signin_manager_base.h"
14 #include "net/url_request/url_fetcher.h"
15
16 class PrefService;
17 class BookmarkServerClusterClient;
18
19 namespace enhanced_bookmarks {
20
21 // Manages requests to the bookmark server to retrieve the current clustering
22 // state.
23 class BookmarkServerClusterService : public KeyedService,
24 public BookmarkServerService,
25 public SigninManagerBase::Observer {
26 public:
27 typedef std::map<std::string, std::vector<std::string> > ClusterMap;
28 BookmarkServerClusterService(
29 const std::string& application_language_code,
30 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
31 ProfileOAuth2TokenService* token_service,
32 SigninManagerBase* signin_manager,
33 BookmarkModel* bookmark_model,
34 PrefService* pref_service);
35 virtual ~BookmarkServerClusterService();
36
37 // Retrieves all the bookmarks associated with a cluster.
38 const std::vector<const BookmarkNode*> BookmarksForClusterNamed(
39 const std::string& cluster_name) const;
40
41 // Returns the clusters in which the passed bookmark is in, if any.
42 const std::vector<std::string> ClustersForBookmark(
43 const BookmarkNode* bookmark) const;
44
45 // Dynamically generates a vector of all clusters.
46 const std::vector<std::string> GetClusters() const;
47
48 // Registers server cluster service prefs.
49 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);
50
51 protected:
52 virtual net::URLFetcher* CreateFetcher() OVERRIDE;
53
54 virtual bool ProcessResponse(const std::string& response,
55 bool* should_notify) OVERRIDE;
56
57 virtual void CleanAfterFailure() OVERRIDE;
58
59 // BookmarkModelObserver methods.
60 virtual void BookmarkModelLoaded(BookmarkModel* model,
61 bool ids_reassigned) OVERRIDE;
62 virtual void BookmarkNodeAdded(BookmarkModel* model,
63 const BookmarkNode* parent,
64 int index) OVERRIDE;
65 virtual void BookmarkMetaInfoChanged(BookmarkModel* model,
66 const BookmarkNode* node) OVERRIDE;
67 virtual void BookmarkAllUserNodesRemoved(
68 BookmarkModel* model,
69 const std::set<GURL>& removed_urls) OVERRIDE;
70
71 private:
72 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster);
73 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Serialization);
74 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SaveToPrefs);
75 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, BadAuth);
76 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest,
77 ClearClusterMapOnRemoveAllBookmarks);
78
79 // Overriden from SigninManagerBase::Observer.
80 virtual void GoogleSignedOut(const std::string& account_id,
81 const std::string& username) OVERRIDE;
82
83 // Updates |cluster_data_| and saves the result to profile prefs.
84 // All changes to |cluster_data_| should go through this method to ensure
85 // profile prefs is always up to date.
86 // TODO(noyau): This is probably a misuse of profile prefs. While the expected
87 // amount of data is small (<1kb), it can theoretically reach megabytes in
88 // size.
89 void UpdateModel(ClusterMap* cluster_map);
90 // Updates |cluster_data_| from profile prefs.
91 void LoadModel();
92
93 // Returns true on success.
94 // The result is swapped into |out_result|.
95 static bool Serialize(const ClusterMap& cluster_map,
96 std::string* out_result,
97 const std::string& auth_id);
98 // Returns true on success.
99 // The result is swapped into |out_map|.
100 // |auth_id| must match the serialized auth_id for this method to succeed.
101 static bool Deserialize(const std::string& input,
102 ClusterMap* out_map,
103 const std::string& auth_id);
104
105 // The ISO 639-1 code of the language used by the application.
106 const std::string application_language_code_;
107 // The preferences services associated with the relevant profile.
108 PrefService* pref_service_;
109 // The cluster data, a map from cluster name to a vector of starsid.
110 ClusterMap cluster_data_;
111
112 DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterService);
113 };
114 } // namespace enhanced_bookmarks
115
116 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698