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

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: Nits: consts. Created 6 years, 2 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
5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
6 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "components/enhanced_bookmarks/bookmark_server_service.h"
13 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
14 #include "components/signin/core/browser/signin_manager_base.h"
15 #include "net/url_request/url_fetcher.h"
16
17 class PrefService;
18
19 namespace enhanced_bookmarks {
20
21 // Manages requests to the bookmark server to retrieve the current clustering
22 // state for the bookmarks. A cluster is simply a named set of bookmarks related
23 // to each others.
24 class BookmarkServerClusterService : public KeyedService,
25 public BookmarkServerService,
26 public SigninManagerBase::Observer {
27 public:
28 // Maps a cluster name to the stars.id of the bookmarks.
29 typedef std::map<std::string, std::vector<std::string>> ClusterMap;
30 // |application_language_code| should be a ISO 639-1 compliant string. Aka
31 // 'en' or 'en-US'. Note that this code should only specify the language, not
32 // the locale, so 'en_US' (english language with US locale) and 'en-GB_US'
33 // (British english person in the US) are not language code.
34 BookmarkServerClusterService(
35 const std::string& application_language_code,
36 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
37 ProfileOAuth2TokenService* token_service,
38 SigninManagerBase* signin_manager,
39 EnhancedBookmarkModel* enhanced_bookmark_model,
40 PrefService* pref_service);
41 virtual ~BookmarkServerClusterService();
42
43 // Retrieves all the bookmarks associated with a cluster. The returned
44 // BookmarkNodes are owned by the bookmark model, and one must listen to the
45 // model observer notification to clear them.
46 const std::vector<const BookmarkNode*> BookmarksForClusterNamed(
47 const std::string& cluster_name) const;
48
49 // Returns the clusters in which the passed bookmark is in, if any.
50 const std::vector<std::string> ClustersForBookmark(
51 const BookmarkNode* bookmark) const;
52
53 // Dynamically generates a vector of all clusters.
54 const std::vector<std::string> GetClusters() const;
55
56 // Registers server cluster service prefs.
57 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);
58
59 protected:
60 // BookmarkServerService methods.
61 virtual net::URLFetcher* CreateFetcher() OVERRIDE;
62
63 virtual bool ProcessResponse(const std::string& response,
64 bool* should_notify) OVERRIDE;
65
66 virtual void CleanAfterFailure() OVERRIDE;
67
68 // EnhancedBookmarkModelObserver methods.
69 virtual void EnhancedBookmarkModelLoaded() OVERRIDE;
70 virtual void EnhancedBookmarkAdded(const BookmarkNode* node) OVERRIDE;
71 virtual void EnhancedBookmarkRemoved(const BookmarkNode* node) OVERRIDE;
72 virtual void EnhancedBookmarkAllUserNodesRemoved() OVERRIDE;
73 virtual void EnhancedBookmarkRemoteIdChanged(
74 const BookmarkNode* node,
75 const std::string& old_remote_id,
76 const std::string& remote_id) OVERRIDE;
77
78 private:
79 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster);
80 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Serialization);
81 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SaveToPrefs);
82 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, BadAuth);
83 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest,
84 ClearClusterMapOnRemoveAllBookmarks);
85
86 // Overriden from SigninManagerBase::Observer.
87 virtual void GoogleSignedOut(const std::string& account_id,
88 const std::string& username) OVERRIDE;
89
90 // Updates |cluster_data_| with the |cluster_map| and saves the result to
91 // profile prefs. All changes to |cluster_data_| should go through this method
92 // to ensure profile prefs is always up to date.
93 // TODO(noyau): This is probably a misuse of profile prefs. While the expected
94 // amount of data is small (<1kb), it can theoretically reach megabytes in
95 // size.
96 void UpdateModel(ClusterMap* cluster_map);
97 // Updates |cluster_data_| from profile prefs.
98 void LoadModel();
99
100 // Serialize the |cluster_map| into the returned dictionaty value.. The
Yaron 2014/10/01 23:45:21 s/dictionaty value../dictionary value./
noyau (Ping after 24h) 2014/10/06 16:21:15 Done.
101 // |auth_id| uniquely identify the signed in user, to avoid deserializing data
102 // for a different one.
103 static scoped_ptr<base::DictionaryValue> Serialize(
104 const ClusterMap& cluster_map,
105 const std::string& auth_id);
106 // Returns true on success.
107 // The result is swapped into |out_map|.
108 // |auth_id| must match the serialized auth_id for this method to succeed.
109 static bool Deserialize(const base::DictionaryValue& value,
110 const std::string& auth_id,
111 ClusterMap* out_map);
112
113 // The ISO 639-1 code of the language used by the application.
114 const std::string application_language_code_;
115 // The preferences services associated with the relevant profile.
116 PrefService* pref_service_;
117 // The cluster data, a map from cluster name to a vector of stars.id.
118 ClusterMap cluster_data_;
119
120 DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterService);
121 };
122
123 } // namespace enhanced_bookmarks
124
125 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_
OLDNEW
« no previous file with comments | « components/enhanced_bookmarks/DEPS ('k') | components/enhanced_bookmarks/bookmark_server_cluster_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698