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; | |
|
Yaron
2014/09/05 05:18:01
unused
noyau (Ping after 24h)
2014/09/10 08:53:57
Done.
| |
| 18 | |
| 19 namespace enhanced_bookmarks { | |
| 20 | |
| 21 // 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.
| |
| 22 class BookmarkServerClusterService : public KeyedService, | |
| 23 public BookmarkServerService, | |
| 24 public SigninManagerBase::Observer { | |
| 25 public: | |
| 26 typedef std::map<std::string, std::vector<std::string> > ClusterMap; | |
| 27 BookmarkServerClusterService( | |
| 28 const std::string& application_language_code, | |
| 29 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | |
| 30 ProfileOAuth2TokenService* token_service, | |
| 31 SigninManagerBase* signin_manager, | |
| 32 BookmarkModel* bookmark_model, | |
| 33 PrefService* pref_service); | |
| 34 virtual ~BookmarkServerClusterService(); | |
| 35 | |
| 36 // Retrieves all the bookmarks associated with a cluster. | |
| 37 const std::vector<const BookmarkNode*> BookmarksForClusterNamed( | |
| 38 const std::string& cluster_name) const; | |
| 39 | |
| 40 // Returns the clusters in which the passed bookmark is in, if any. | |
| 41 const std::vector<std::string> ClustersForBookmark( | |
| 42 const BookmarkNode* bookmark) const; | |
| 43 | |
| 44 // Dynamically generates a vector of all clusters. | |
| 45 const std::vector<std::string> GetClusters() const; | |
| 46 | |
| 47 // Registers server cluster service prefs. | |
| 48 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 49 | |
| 50 protected: | |
| 51 virtual net::URLFetcher* CreateFetcherWithToken( | |
| 52 const std::string& access_token) 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_ | |
| OLD | NEW |