OLD | NEW |
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 |
(...skipping 27 matching lines...) Expand all Loading... |
38 // parsing of the response. | 38 // parsing of the response. |
39 class BookmarkServerService : protected net::URLFetcherDelegate, | 39 class BookmarkServerService : protected net::URLFetcherDelegate, |
40 private OAuth2TokenService::Consumer, | 40 private OAuth2TokenService::Consumer, |
41 public EnhancedBookmarkModelObserver { | 41 public EnhancedBookmarkModelObserver { |
42 public: | 42 public: |
43 BookmarkServerService( | 43 BookmarkServerService( |
44 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 44 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
45 ProfileOAuth2TokenService* token_service, | 45 ProfileOAuth2TokenService* token_service, |
46 SigninManagerBase* signin_manager, | 46 SigninManagerBase* signin_manager, |
47 EnhancedBookmarkModel* enhanced_bookmark_model); | 47 EnhancedBookmarkModel* enhanced_bookmark_model); |
48 virtual ~BookmarkServerService(); | 48 ~BookmarkServerService() override; |
49 | 49 |
50 virtual void AddObserver(BookmarkServerServiceObserver* observer); | 50 virtual void AddObserver(BookmarkServerServiceObserver* observer); |
51 void RemoveObserver(BookmarkServerServiceObserver* observer); | 51 void RemoveObserver(BookmarkServerServiceObserver* observer); |
52 | 52 |
53 protected: | 53 protected: |
54 // 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 |
55 // matches. | 55 // matches. |
56 virtual const BookmarkNode* BookmarkForRemoteId( | 56 virtual const BookmarkNode* BookmarkForRemoteId( |
57 const std::string& remote_id) const; | 57 const std::string& remote_id) const; |
58 const std::string RemoteIDForBookmark(const BookmarkNode* bookmark) const; | 58 const std::string RemoteIDForBookmark(const BookmarkNode* bookmark) const; |
(...skipping 11 matching lines...) Expand all Loading... |
70 // 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 |
71 // 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 |
72 // notification send. | 72 // notification send. |
73 virtual bool ProcessResponse(const std::string& response, | 73 virtual bool ProcessResponse(const std::string& response, |
74 bool* should_notify) = 0; | 74 bool* should_notify) = 0; |
75 | 75 |
76 // 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. |
77 virtual void CleanAfterFailure() = 0; | 77 virtual void CleanAfterFailure() = 0; |
78 | 78 |
79 // EnhancedBookmarkModelObserver: | 79 // EnhancedBookmarkModelObserver: |
80 virtual void EnhancedBookmarkModelShuttingDown() override; | 80 void EnhancedBookmarkModelShuttingDown() override; |
81 | 81 |
82 SigninManagerBase* GetSigninManager(); | 82 SigninManagerBase* GetSigninManager(); |
83 | 83 |
84 // Cached pointer to the bookmarks model. | 84 // Cached pointer to the bookmarks model. |
85 EnhancedBookmarkModel* model_; // weak | 85 EnhancedBookmarkModel* model_; // weak |
86 | 86 |
87 protected: | 87 protected: |
88 // The observers. | 88 // The observers. |
89 ObserverList<BookmarkServerServiceObserver> observers_; | 89 ObserverList<BookmarkServerServiceObserver> observers_; |
90 | 90 |
91 private: | 91 private: |
92 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); | 92 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, Cluster); |
93 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SignOut); | 93 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, SignOut); |
94 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, | 94 FRIEND_TEST_ALL_PREFIXES(BookmarkServerServiceTest, |
95 ClearClusterMapOnRemoveAllBookmarks); | 95 ClearClusterMapOnRemoveAllBookmarks); |
96 | 96 |
97 // net::URLFetcherDelegate methods. Called when the query is finished. | 97 // net::URLFetcherDelegate methods. Called when the query is finished. |
98 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 98 void OnURLFetchComplete(const net::URLFetcher* source) override; |
99 | 99 |
100 // OAuth2TokenService::Consumer methods. | 100 // OAuth2TokenService::Consumer methods. |
101 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 101 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
102 const std::string& access_token, | 102 const std::string& access_token, |
103 const base::Time& expiration_time) override; | 103 const base::Time& expiration_time) override; |
104 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 104 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
105 const GoogleServiceAuthError& error) override; | 105 const GoogleServiceAuthError& error) override; |
106 | 106 |
107 // The Auth service is used to get a token for auth with the server. | 107 // The Auth service is used to get a token for auth with the server. |
108 ProfileOAuth2TokenService* token_service_; // Weak | 108 ProfileOAuth2TokenService* token_service_; // Weak |
109 // The request to the token service. | 109 // The request to the token service. |
110 scoped_ptr<OAuth2TokenService::Request> token_request_; | 110 scoped_ptr<OAuth2TokenService::Request> token_request_; |
111 // To get the currently signed in user. | 111 // To get the currently signed in user. |
112 SigninManagerBase* signin_manager_; // Weak | 112 SigninManagerBase* signin_manager_; // Weak |
113 // To have access to the right context getter for the profile. | 113 // To have access to the right context getter for the profile. |
114 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 114 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
115 // The fetcher used to query the server. | 115 // The fetcher used to query the server. |
116 scoped_ptr<net::URLFetcher> url_fetcher_; | 116 scoped_ptr<net::URLFetcher> url_fetcher_; |
117 | 117 |
118 DISALLOW_COPY_AND_ASSIGN(BookmarkServerService); | 118 DISALLOW_COPY_AND_ASSIGN(BookmarkServerService); |
119 }; | 119 }; |
120 } // namespace enhanced_bookmarks | 120 } // namespace enhanced_bookmarks |
121 | 121 |
122 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_ | 122 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SERVICE_H_ |
OLD | NEW |