Chromium Code Reviews| OLD | NEW |
|---|---|
| (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. | |
|
battre
2014/09/26 14:33:05
Add a description of what a cluster and cluster na
noyau (Ping after 24h)
2014/10/01 16:04:43
Done.
| |
| 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; | |
|
battre
2014/09/26 14:33:05
describe key and value?
noyau (Ping after 24h)
2014/10/01 16:04:44
Done.
| |
| 28 BookmarkServerClusterService( | |
| 29 const std::string& application_language_code, | |
|
battre
2014/09/26 14:33:05
describe parameter? (see above)
noyau (Ping after 24h)
2014/10/01 16:04:43
Done.
| |
| 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. | |
|
battre
2014/09/26 14:33:05
Comment on ownership of BookmarkNodes?
noyau (Ping after 24h)
2014/10/01 16:04:43
Done.
| |
| 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: | |
|
battre
2014/09/26 14:33:05
// BookmarkServerService methods.
noyau (Ping after 24h)
2014/10/01 16:04:43
Done.
| |
| 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. | |
|
battre
2014/09/26 14:33:05
I can't find this inheritance.
noyau (Ping after 24h)
2014/10/01 16:04:44
Yes, the code changed, and this inheritance disapp
| |
| 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. | |
|
battre
2014/09/26 14:33:05
What's the cluster_map parameter?
noyau (Ping after 24h)
2014/10/01 16:04:44
Done.
| |
| 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 // The result is swapped into |out_result|. | |
| 94 static void Serialize(const ClusterMap& cluster_map, | |
| 95 std::string* out_result, | |
| 96 const std::string& auth_id); | |
|
battre
2014/09/26 14:33:05
make the output parameter the last one? (same for
noyau (Ping after 24h)
2014/10/01 16:04:43
Done.
| |
| 97 // Returns true on success. | |
| 98 // The result is swapped into |out_map|. | |
| 99 // |auth_id| must match the serialized auth_id for this method to succeed. | |
| 100 static bool Deserialize(const std::string& input, | |
| 101 ClusterMap* out_map, | |
| 102 const std::string& auth_id); | |
| 103 | |
| 104 // The ISO 639-1 code of the language used by the application. | |
| 105 const std::string application_language_code_; | |
| 106 // The preferences services associated with the relevant profile. | |
| 107 PrefService* pref_service_; | |
| 108 // The cluster data, a map from cluster name to a vector of starsid. | |
| 109 ClusterMap cluster_data_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(BookmarkServerClusterService); | |
| 112 }; | |
| 113 } // namespace enhanced_bookmarks | |
| 114 | |
| 115 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_CLUSTER_SERVICE_H_ | |
| OLD | NEW |