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; | |
hashimoto
2012/07/20 04:07:37
nit: s/CallBack/Callback/ We use 'callback' as one
yoshiki
2012/07/24 16:58:32
Done
hashimoto
2012/07/25 06:14:21
How about making OnDataParsed() a private method o
| |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 // override this method to specify any extra headers needed for the request. | 107 // override this method to specify any extra headers needed for the request. |
105 virtual std::vector<std::string> GetExtraRequestHeaders() const; | 108 virtual std::vector<std::string> GetExtraRequestHeaders() const; |
106 // Used by a derived class to add any content data to the request. | 109 // Used by a derived class to add any content data to the request. |
107 // Returns true if |upload_content_type| and |upload_content| are updated | 110 // Returns true if |upload_content_type| and |upload_content| are updated |
108 // with the content type and data for the request. | 111 // with the content type and data for the request. |
109 virtual bool GetContentData(std::string* upload_content_type, | 112 virtual bool GetContentData(std::string* upload_content_type, |
110 std::string* upload_content); | 113 std::string* upload_content); |
111 | 114 |
112 // Invoked by OnURLFetchComplete when the operation completes without an | 115 // Invoked by OnURLFetchComplete when the operation completes without an |
113 // authentication error. Must be implemented by a derived class. | 116 // authentication error. Must be implemented by a derived class. |
114 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) = 0; | 117 virtual void ProcessURLFetchResults( |
118 const net::URLFetcher* source, | |
119 const ProcessURLFetchResultsCallBack& callback) = 0; | |
115 | 120 |
116 // Invoked when it needs to notify the status. Chunked operations that | 121 // Invoked when it needs to notify the status. Chunked operations that |
117 // constructs a logically single operation from multiple physical operations | 122 // constructs a logically single operation from multiple physical operations |
118 // should notify resume/suspend instead of start/finish. | 123 // should notify resume/suspend instead of start/finish. |
119 virtual void NotifyStartToOperationRegistry(); | 124 virtual void NotifyStartToOperationRegistry(); |
120 virtual void NotifySuccessToOperationRegistry(); | 125 virtual void NotifySuccessToOperationRegistry(); |
121 | 126 |
122 // Invoked by this base class upon an authentication error or cancel by | 127 // Invoked by this base class upon an authentication error or cancel by |
123 // an user operation. Must be implemented by a derived class. | 128 // an user operation. Must be implemented by a derived class. |
124 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 129 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
125 | 130 |
126 // Implement GDataOperationRegistry::Operation | 131 // Implement GDataOperationRegistry::Operation |
127 virtual void DoCancel() OVERRIDE; | 132 virtual void DoCancel() OVERRIDE; |
128 | 133 |
129 // Overridden from URLFetcherDelegate. | 134 // Overridden from URLFetcherDelegate. |
130 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 135 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
131 | 136 |
137 // Invoked when ProcessURLFetchResults() is completed. | |
138 void OnProcessURLFetchResultsComplete(bool result); | |
139 | |
132 // Overridden from GDataOperationInterface. | 140 // Overridden from GDataOperationInterface. |
133 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 141 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
134 | 142 |
135 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 143 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
136 // the status of the URLFetcher. | 144 // the status of the URLFetcher. |
137 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; | 145 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; |
138 | 146 |
139 std::string GetResponseHeadersAsString( | 147 std::string GetResponseHeadersAsString( |
140 const net::URLFetcher* url_fetcher); | 148 const net::URLFetcher* url_fetcher); |
141 | 149 |
142 Profile* profile_; | 150 Profile* profile_; |
143 ReAuthenticateCallback re_authenticate_callback_; | 151 ReAuthenticateCallback re_authenticate_callback_; |
144 int re_authenticate_count_; | 152 int re_authenticate_count_; |
145 bool save_temp_file_; | 153 bool save_temp_file_; |
146 FilePath output_file_path_; | 154 FilePath output_file_path_; |
147 scoped_ptr<net::URLFetcher> url_fetcher_; | 155 scoped_ptr<net::URLFetcher> url_fetcher_; |
148 bool started_; | 156 bool started_; |
157 base::WeakPtrFactory<UrlFetchOperationBase> weak_ptr_factory_; | |
hashimoto
2012/07/20 04:07:37
Can't this be private instead of protected?
yoshiki
2012/07/24 16:58:32
Done.
| |
149 }; | 158 }; |
150 | 159 |
151 //============================ EntryActionOperation ============================ | 160 //============================ EntryActionOperation ============================ |
152 | 161 |
153 // This class performs a simple action over a given entry (document/file). | 162 // This class performs a simple action over a given entry (document/file). |
154 // It is meant to be used for operations that return no JSON blobs. | 163 // It is meant to be used for operations that return no JSON blobs. |
155 class EntryActionOperation : public UrlFetchOperationBase { | 164 class EntryActionOperation : public UrlFetchOperationBase { |
156 public: | 165 public: |
157 EntryActionOperation(GDataOperationRegistry* registry, | 166 EntryActionOperation(GDataOperationRegistry* registry, |
158 Profile* profile, | 167 Profile* profile, |
159 const EntryActionCallback& callback, | 168 const EntryActionCallback& callback, |
160 const GURL& document_url); | 169 const GURL& document_url); |
161 virtual ~EntryActionOperation(); | 170 virtual ~EntryActionOperation(); |
162 | 171 |
163 protected: | 172 protected: |
164 // Overridden from UrlFetchOperationBase. | 173 // Overridden from UrlFetchOperationBase. |
165 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 174 virtual void ProcessURLFetchResults( |
175 const net::URLFetcher* source, | |
176 const ProcessURLFetchResultsCallBack& callback) OVERRIDE; | |
166 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 177 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
167 | 178 |
168 const GURL& document_url() const { return document_url_; } | 179 const GURL& document_url() const { return document_url_; } |
169 | 180 |
170 private: | 181 private: |
171 EntryActionCallback callback_; | 182 EntryActionCallback callback_; |
172 GURL document_url_; | 183 GURL document_url_; |
173 | 184 |
174 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 185 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
175 }; | 186 }; |
176 | 187 |
177 //============================== GetDataOperation ============================== | 188 //============================== GetDataOperation ============================== |
178 | 189 |
179 // This class performs the operation for fetching and parsing JSON data content. | 190 // This class performs the operation for fetching and parsing JSON data content. |
180 class GetDataOperation : public UrlFetchOperationBase { | 191 class GetDataOperation : public UrlFetchOperationBase { |
181 public: | 192 public: |
182 GetDataOperation(GDataOperationRegistry* registry, | 193 GetDataOperation(GDataOperationRegistry* registry, |
183 Profile* profile, | 194 Profile* profile, |
184 const GetDataCallback& callback); | 195 const GetDataCallback& callback); |
185 virtual ~GetDataOperation(); | 196 virtual ~GetDataOperation(); |
186 | 197 |
187 // Parse GData JSON response. | 198 // Parse GData JSON response. |
188 virtual base::Value* ParseResponse(const std::string& data); | 199 virtual void ParseResponse( |
200 GDataErrorCode fetch_error_code, | |
201 const std::string& data, | |
202 const ProcessURLFetchResultsCallBack& result_callback); | |
189 | 203 |
190 protected: | 204 protected: |
191 // Overridden from UrlFetchOperationBase. | 205 // Overridden from UrlFetchOperationBase. |
192 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 206 virtual void ProcessURLFetchResults( |
193 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 207 const net::URLFetcher* source, |
208 const ProcessURLFetchResultsCallBack& callback) OVERRIDE; | |
209 virtual void RunCallbackOnPrematureFailure( | |
210 GDataErrorCode fetch_error_code) OVERRIDE; | |
211 void RunCallback(GDataErrorCode fetch_error_code, | |
212 scoped_ptr<base::Value> value); | |
194 | 213 |
195 private: | 214 private: |
196 GetDataCallback callback_; | 215 GetDataCallback callback_; |
216 | |
197 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 217 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
198 }; | 218 }; |
199 | 219 |
200 } // namespace gdata | 220 } // namespace gdata |
201 | 221 |
202 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 222 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
OLD | NEW |