OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
12 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
13 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 13 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
15 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
16 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 class OAuth2AccessTokenFetcher; | 19 class OAuth2AccessTokenFetcher; |
20 | 20 |
21 namespace gdata { | 21 namespace gdata { |
22 | 22 |
| 23 // Callback type for ProcessURLFetchResults. |
| 24 typedef base::Callback<void(bool result)> ProcessURLFetchResultsCallback; |
| 25 |
23 //================================ AuthOperation =============================== | 26 //================================ AuthOperation =============================== |
24 | 27 |
25 // OAuth2 authorization token retrieval operation. | 28 // OAuth2 authorization token retrieval operation. |
26 class AuthOperation : public GDataOperationRegistry::Operation, | 29 class AuthOperation : public GDataOperationRegistry::Operation, |
27 public OAuth2AccessTokenConsumer { | 30 public OAuth2AccessTokenConsumer { |
28 public: | 31 public: |
29 AuthOperation(GDataOperationRegistry* registry, | 32 AuthOperation(GDataOperationRegistry* registry, |
30 Profile* profile, | 33 Profile* profile, |
31 const AuthStatusCallback& callback, | 34 const AuthStatusCallback& callback, |
32 const std::string& refresh_token); | 35 const std::string& refresh_token); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // override this method to specify any extra headers needed for the request. | 108 // override this method to specify any extra headers needed for the request. |
106 virtual std::vector<std::string> GetExtraRequestHeaders() const; | 109 virtual std::vector<std::string> GetExtraRequestHeaders() const; |
107 // Used by a derived class to add any content data to the request. | 110 // Used by a derived class to add any content data to the request. |
108 // Returns true if |upload_content_type| and |upload_content| are updated | 111 // Returns true if |upload_content_type| and |upload_content| are updated |
109 // with the content type and data for the request. | 112 // with the content type and data for the request. |
110 virtual bool GetContentData(std::string* upload_content_type, | 113 virtual bool GetContentData(std::string* upload_content_type, |
111 std::string* upload_content); | 114 std::string* upload_content); |
112 | 115 |
113 // Invoked by OnURLFetchComplete when the operation completes without an | 116 // Invoked by OnURLFetchComplete when the operation completes without an |
114 // authentication error. Must be implemented by a derived class. | 117 // authentication error. Must be implemented by a derived class. |
115 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) = 0; | 118 virtual void ProcessURLFetchResults( |
| 119 const net::URLFetcher* source, |
| 120 const ProcessURLFetchResultsCallback& callback) = 0; |
116 | 121 |
117 // Invoked when it needs to notify the status. Chunked operations that | 122 // Invoked when it needs to notify the status. Chunked operations that |
118 // constructs a logically single operation from multiple physical operations | 123 // constructs a logically single operation from multiple physical operations |
119 // should notify resume/suspend instead of start/finish. | 124 // should notify resume/suspend instead of start/finish. |
120 virtual void NotifyStartToOperationRegistry(); | 125 virtual void NotifyStartToOperationRegistry(); |
121 virtual void NotifySuccessToOperationRegistry(); | 126 virtual void NotifySuccessToOperationRegistry(); |
122 | 127 |
123 // Invoked by this base class upon an authentication error or cancel by | 128 // Invoked by this base class upon an authentication error or cancel by |
124 // an user operation. Must be implemented by a derived class. | 129 // an user operation. Must be implemented by a derived class. |
125 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 130 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
126 | 131 |
127 // Implement GDataOperationRegistry::Operation | 132 // Implement GDataOperationRegistry::Operation |
128 virtual void DoCancel() OVERRIDE; | 133 virtual void DoCancel() OVERRIDE; |
129 | 134 |
130 // Overridden from URLFetcherDelegate. | 135 // Overridden from URLFetcherDelegate. |
131 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 136 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
132 | 137 |
| 138 // Invoked when ProcessURLFetchResults() is completed. |
| 139 void OnProcessURLFetchResultsComplete(bool result); |
| 140 |
133 // Overridden from GDataOperationInterface. | 141 // Overridden from GDataOperationInterface. |
134 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 142 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
135 | 143 |
136 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 144 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
137 // the status of the URLFetcher. | 145 // the status of the URLFetcher. |
138 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; | 146 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; |
139 | 147 |
140 std::string GetResponseHeadersAsString( | 148 std::string GetResponseHeadersAsString( |
141 const net::URLFetcher* url_fetcher); | 149 const net::URLFetcher* url_fetcher); |
142 | 150 |
143 Profile* profile_; | 151 Profile* profile_; |
144 ReAuthenticateCallback re_authenticate_callback_; | 152 ReAuthenticateCallback re_authenticate_callback_; |
145 int re_authenticate_count_; | 153 int re_authenticate_count_; |
146 bool save_temp_file_; | 154 bool save_temp_file_; |
147 FilePath output_file_path_; | 155 FilePath output_file_path_; |
148 scoped_ptr<net::URLFetcher> url_fetcher_; | 156 scoped_ptr<net::URLFetcher> url_fetcher_; |
149 bool started_; | 157 bool started_; |
| 158 |
| 159 private: |
| 160 base::WeakPtrFactory<UrlFetchOperationBase> weak_ptr_factory_; |
150 }; | 161 }; |
151 | 162 |
152 //============================ EntryActionOperation ============================ | 163 //============================ EntryActionOperation ============================ |
153 | 164 |
154 // This class performs a simple action over a given entry (document/file). | 165 // This class performs a simple action over a given entry (document/file). |
155 // It is meant to be used for operations that return no JSON blobs. | 166 // It is meant to be used for operations that return no JSON blobs. |
156 class EntryActionOperation : public UrlFetchOperationBase { | 167 class EntryActionOperation : public UrlFetchOperationBase { |
157 public: | 168 public: |
158 EntryActionOperation(GDataOperationRegistry* registry, | 169 EntryActionOperation(GDataOperationRegistry* registry, |
159 Profile* profile, | 170 Profile* profile, |
160 const EntryActionCallback& callback, | 171 const EntryActionCallback& callback, |
161 const GURL& document_url); | 172 const GURL& document_url); |
162 virtual ~EntryActionOperation(); | 173 virtual ~EntryActionOperation(); |
163 | 174 |
164 protected: | 175 protected: |
165 // Overridden from UrlFetchOperationBase. | 176 // Overridden from UrlFetchOperationBase. |
166 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 177 virtual void ProcessURLFetchResults( |
| 178 const net::URLFetcher* source, |
| 179 const ProcessURLFetchResultsCallback& callback) OVERRIDE; |
167 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 180 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
168 | 181 |
169 const GURL& document_url() const { return document_url_; } | 182 const GURL& document_url() const { return document_url_; } |
170 | 183 |
171 private: | 184 private: |
172 EntryActionCallback callback_; | 185 EntryActionCallback callback_; |
173 GURL document_url_; | 186 GURL document_url_; |
174 | 187 |
175 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 188 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
176 }; | 189 }; |
177 | 190 |
178 //============================== GetDataOperation ============================== | 191 //============================== GetDataOperation ============================== |
179 | 192 |
180 // This class performs the operation for fetching and parsing JSON data content. | 193 // This class performs the operation for fetching and parsing JSON data content. |
181 class GetDataOperation : public UrlFetchOperationBase { | 194 class GetDataOperation : public UrlFetchOperationBase { |
182 public: | 195 public: |
183 GetDataOperation(GDataOperationRegistry* registry, | 196 GetDataOperation(GDataOperationRegistry* registry, |
184 Profile* profile, | 197 Profile* profile, |
185 const GetDataCallback& callback); | 198 const GetDataCallback& callback); |
186 virtual ~GetDataOperation(); | 199 virtual ~GetDataOperation(); |
187 | 200 |
188 // Parse GData JSON response. | 201 // Parse GData JSON response. |
189 virtual base::Value* ParseResponse(const std::string& data); | 202 virtual void ParseResponse( |
| 203 GDataErrorCode fetch_error_code, |
| 204 const std::string& data, |
| 205 const ProcessURLFetchResultsCallback& result_callback); |
190 | 206 |
191 protected: | 207 protected: |
192 // Overridden from UrlFetchOperationBase. | 208 // Overridden from UrlFetchOperationBase. |
193 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 209 virtual void ProcessURLFetchResults( |
194 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 210 const net::URLFetcher* source, |
| 211 const ProcessURLFetchResultsCallback& callback) OVERRIDE; |
| 212 virtual void RunCallbackOnPrematureFailure( |
| 213 GDataErrorCode fetch_error_code) OVERRIDE; |
| 214 void RunCallback(GDataErrorCode fetch_error_code, |
| 215 scoped_ptr<base::Value> value); |
195 | 216 |
196 private: | 217 private: |
197 GetDataCallback callback_; | 218 GetDataCallback callback_; |
| 219 |
198 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 220 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
199 }; | 221 }; |
200 | 222 |
201 } // namespace gdata | 223 } // namespace gdata |
202 | 224 |
203 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 225 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
OLD | NEW |