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

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

Issue 563363002: Only set remote id during url node creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_ 5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
6 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_ 6 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "components/bookmarks/browser/bookmark_model_observer.h" 11 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h"
12 #include "google_apis/gaia/google_service_auth_error.h" 12 #include "google_apis/gaia/google_service_auth_error.h"
13 #include "google_apis/gaia/oauth2_token_service.h" 13 #include "google_apis/gaia/oauth2_token_service.h"
14 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h" 15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h" 16 #include "net/url_request/url_request_context_getter.h"
17 17
18 class BookmarkModel;
19 class ProfileOAuth2TokenService; 18 class ProfileOAuth2TokenService;
20 class SigninManagerBase; 19 class SigninManagerBase;
20 class BookmarkNode;
21 21
22 namespace enhanced_bookmarks { 22 namespace enhanced_bookmarks {
23 23
24 class BookmarkServerService; 24 class BookmarkServerService;
25 class EnhancedBookmarkModel;
25 26
26 class BookmarkServerServiceObserver { 27 class BookmarkServerServiceObserver {
27 public: 28 public:
28 virtual void OnChange(BookmarkServerService* service) = 0; 29 virtual void OnChange(BookmarkServerService* service) = 0;
29 30
30 protected: 31 protected:
31 virtual ~BookmarkServerServiceObserver() {} 32 virtual ~BookmarkServerServiceObserver() {}
32 }; 33 };
33 34
34 // This abstract class manages the connection to the bookmark servers and 35 // This abstract class manages the connection to the bookmark servers and
35 // stores the maps necessary to translate the response from stars.id to 36 // stores the maps necessary to translate the response from stars.id to
36 // BookmarkNodes. Subclasses just have to provide the right query and the 37 // BookmarkNodes. Subclasses just have to provide the right query and the
37 // parsing of the response. 38 // parsing of the response.
38 class BookmarkServerService : protected net::URLFetcherDelegate, 39 class BookmarkServerService : protected net::URLFetcherDelegate,
39 protected BookmarkModelObserver, 40 private OAuth2TokenService::Consumer,
40 private OAuth2TokenService::Consumer { 41 public EnhancedBookmarkModelObserver {
41 public: 42 public:
42 BookmarkServerService( 43 BookmarkServerService(
43 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 44 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
44 ProfileOAuth2TokenService* token_service, 45 ProfileOAuth2TokenService* token_service,
45 SigninManagerBase* signin_manager, 46 SigninManagerBase* signin_manager,
46 BookmarkModel* bookmark_model); 47 EnhancedBookmarkModel* enhanced_bookmark_model);
47 virtual ~BookmarkServerService(); 48 virtual ~BookmarkServerService();
48 49
49 void AddObserver(BookmarkServerServiceObserver* observer); 50 void AddObserver(BookmarkServerServiceObserver* observer);
50 void RemoveObserver(BookmarkServerServiceObserver* observer); 51 void RemoveObserver(BookmarkServerServiceObserver* observer);
51 52
52 protected: 53 protected:
53 // Retrieves a bookmark by using its remote id. Returns null if nothing 54 // Retrieves a bookmark by using its remote id. Returns null if nothing
54 // matches. 55 // matches.
55 virtual const BookmarkNode* BookmarkForRemoteId( 56 virtual const BookmarkNode* BookmarkForRemoteId(
56 const std::string& remote_id) const; 57 const std::string& remote_id) const;
(...skipping 11 matching lines...) Expand all
68 // Processes the response to the query. Returns true on successful parsing, 69 // Processes the response to the query. Returns true on successful parsing,
69 // false on failure. The implementation can assume that |should_notify| is set 70 // false on failure. The implementation can assume that |should_notify| is set
70 // to true by default, if changed to false there will be no OnChange 71 // to true by default, if changed to false there will be no OnChange
71 // notification send. 72 // notification send.
72 virtual bool ProcessResponse(const std::string& response, 73 virtual bool ProcessResponse(const std::string& response,
73 bool* should_notify) = 0; 74 bool* should_notify) = 0;
74 75
75 // If the token can't be retrieved or the query fails this method is called. 76 // If the token can't be retrieved or the query fails this method is called.
76 virtual void CleanAfterFailure() = 0; 77 virtual void CleanAfterFailure() = 0;
77 78
78 // BookmarkModelObserver methods. 79 // EnhancedBookmarkModelObserver:
79 virtual void BookmarkModelLoaded(BookmarkModel* model, 80 virtual void EnhancedBookmarkModelShuttingDown() OVERRIDE;
80 bool ids_reassigned) OVERRIDE;
81 virtual void BookmarkNodeMoved(BookmarkModel* model,
82 const BookmarkNode* old_parent,
83 int old_index,
84 const BookmarkNode* new_parent,
85 int new_index) OVERRIDE {};
86 virtual void BookmarkNodeAdded(BookmarkModel* model,
87 const BookmarkNode* parent,
88 int index) OVERRIDE;
89 virtual void BookmarkNodeRemoved(BookmarkModel* model,
90 const BookmarkNode* parent,
91 int old_index,
92 const BookmarkNode* node,
93 const std::set<GURL>& removed_urls) OVERRIDE;
94 virtual void BookmarkNodeChanged(BookmarkModel* model,
95 const BookmarkNode* node) OVERRIDE {};
96 virtual void OnWillChangeBookmarkMetaInfo(BookmarkModel* model,
97 const BookmarkNode* node) OVERRIDE;
98
99 virtual void BookmarkMetaInfoChanged(BookmarkModel* model,
100 const BookmarkNode* node) OVERRIDE;
101
102 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
103 const BookmarkNode* node) OVERRIDE {};
104 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
105 const BookmarkNode* node)
106 OVERRIDE {};
107 virtual void BookmarkAllUserNodesRemoved(
108 BookmarkModel* model,
109 const std::set<GURL>& removed_urls) OVERRIDE;
110 81
111 SigninManagerBase* GetSigninManager(); 82 SigninManagerBase* GetSigninManager();
112 83
113 // Cached pointer to the bookmarks model. 84 // Cached pointer to the bookmarks model.
114 BookmarkModel* bookmark_model_; // weak 85 EnhancedBookmarkModel* model_; // weak
115 86
116 private: 87 private:
117 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); 88 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster);
118 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, 89 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest,
119 ClearClusterMapOnRemoveAllBookmarks); 90 ClearClusterMapOnRemoveAllBookmarks);
120 91
121 // Once the model is ready this method fills in the starsid_to_bookmark_ map.
122 void BuildIdMap();
123
124 // net::URLFetcherDelegate methods. Called when the query is finished. 92 // net::URLFetcherDelegate methods. Called when the query is finished.
125 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 93 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
126 94
127 // OAuth2TokenService::Consumer methods. 95 // OAuth2TokenService::Consumer methods.
128 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 96 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
129 const std::string& access_token, 97 const std::string& access_token,
130 const base::Time& expiration_time) OVERRIDE; 98 const base::Time& expiration_time) OVERRIDE;
131 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, 99 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
132 const GoogleServiceAuthError& error) OVERRIDE; 100 const GoogleServiceAuthError& error) OVERRIDE;
133 101
134 // The observers. 102 // The observers.
135 ObserverList<BookmarkServerServiceObserver> observers_; 103 ObserverList<BookmarkServerServiceObserver> observers_;
136 // The Auth service is used to get a token for auth with the server. 104 // The Auth service is used to get a token for auth with the server.
137 ProfileOAuth2TokenService* token_service_; // Weak 105 ProfileOAuth2TokenService* token_service_; // Weak
138 // The request to the token service. 106 // The request to the token service.
139 scoped_ptr<OAuth2TokenService::Request> token_request_; 107 scoped_ptr<OAuth2TokenService::Request> token_request_;
140 // To get the currently signed in user. 108 // To get the currently signed in user.
141 SigninManagerBase* signin_manager_; // Weak 109 SigninManagerBase* signin_manager_; // Weak
142 // To have access to the right context getter for the profile. 110 // To have access to the right context getter for the profile.
143 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 111 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
144 // The fetcher used to query the server. 112 // The fetcher used to query the server.
145 scoped_ptr<net::URLFetcher> url_fetcher_; 113 scoped_ptr<net::URLFetcher> url_fetcher_;
146 // A map from stars.id to bookmark nodes. With no null entries. 114 // A map from stars.id to bookmark nodes. With no null entries.
147 std::map<std::string, const BookmarkNode*> starsid_to_bookmark_; 115 std::map<std::string, const BookmarkNode*> starsid_to_bookmark_;
148 // Set to true during the creation of a new bookmark in order to send only the
149 // proper notification.
150 bool inhibit_change_notifications_;
151 116
152 DISALLOW_COPY_AND_ASSIGN(BookmarkServerService); 117 DISALLOW_COPY_AND_ASSIGN(BookmarkServerService);
153 }; 118 };
154 } // namespace enhanced_bookmarks 119 } // namespace enhanced_bookmarks
155 120
156 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_ 121 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698