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_GDATA_OPERATIONS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATIONS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATIONS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATIONS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // 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. |
109 virtual std::vector<std::string> GetExtraRequestHeaders() const; | 109 virtual std::vector<std::string> GetExtraRequestHeaders() const; |
110 // 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. |
111 // Returns true if |upload_content_type| and |upload_content| are updated | 111 // Returns true if |upload_content_type| and |upload_content| are updated |
112 // with the content type and data for the request. | 112 // with the content type and data for the request. |
113 virtual bool GetContentData(std::string* upload_content_type, | 113 virtual bool GetContentData(std::string* upload_content_type, |
114 std::string* upload_content); | 114 std::string* upload_content); |
115 | 115 |
116 // Invoked by OnURLFetchComplete when the operation completes without an | 116 // Invoked by OnURLFetchComplete when the operation completes without an |
117 // authentication error. Must be implemented by a derived class. | 117 // authentication error. Must be implemented by a derived class. |
118 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) = 0; | 118 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) = 0; |
119 | 119 |
120 // Invoked when it needs to notify the status. Chunked operations that | 120 // Invoked when it needs to notify the status. Chunked operations that |
121 // constructs a logically single operation from multiple physical operations | 121 // constructs a logically single operation from multiple physical operations |
122 // should notify resume/suspend instead of start/finish. | 122 // should notify resume/suspend instead of start/finish. |
123 virtual void NotifyStartToOperationRegistry(); | 123 virtual void NotifyStartToOperationRegistry(); |
124 virtual void NotifySuccessToOperationRegistry(); | 124 virtual void NotifySuccessToOperationRegistry(); |
125 | 125 |
126 // Invoked by this base class upon an authentication error or cancel by | 126 // Invoked by this base class upon an authentication error or cancel by |
127 // an user operation. Must be implemented by a derived class. | 127 // an user operation. Must be implemented by a derived class. |
128 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 128 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
129 | 129 |
130 // Implement GDataOperationRegistry::Operation | 130 // Implement GDataOperationRegistry::Operation |
131 virtual void DoCancel() OVERRIDE; | 131 virtual void DoCancel() OVERRIDE; |
132 | 132 |
133 // Overridden from URLFetcherDelegate. | 133 // Overridden from URLFetcherDelegate. |
134 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 134 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
135 | 135 |
136 // Overridden from GDataOperationInterface. | 136 // Overridden from GDataOperationInterface. |
137 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 137 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
138 | 138 |
139 std::string GetResponseHeadersAsString( | 139 std::string GetResponseHeadersAsString( |
140 const content::URLFetcher* url_fetcher); | 140 const net::URLFetcher* url_fetcher); |
141 | 141 |
142 Profile* profile_; | 142 Profile* profile_; |
143 ReAuthenticateCallback re_authenticate_callback_; | 143 ReAuthenticateCallback re_authenticate_callback_; |
144 int re_authenticate_count_; | 144 int re_authenticate_count_; |
145 bool save_temp_file_; | 145 bool save_temp_file_; |
146 FilePath output_file_path_; | 146 FilePath output_file_path_; |
147 scoped_ptr<content::URLFetcher> url_fetcher_; | 147 scoped_ptr<content::URLFetcher> url_fetcher_; |
148 bool started_; | 148 bool started_; |
149 }; | 149 }; |
150 | 150 |
151 //============================ EntryActionOperation ============================ | 151 //============================ EntryActionOperation ============================ |
152 | 152 |
153 // This class performs a simple action over a given entry (document/file). | 153 // 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. | 154 // It is meant to be used for operations that return no JSON blobs. |
155 class EntryActionOperation : public UrlFetchOperationBase { | 155 class EntryActionOperation : public UrlFetchOperationBase { |
156 public: | 156 public: |
157 EntryActionOperation(GDataOperationRegistry* registry, | 157 EntryActionOperation(GDataOperationRegistry* registry, |
158 Profile* profile, | 158 Profile* profile, |
159 const EntryActionCallback& callback, | 159 const EntryActionCallback& callback, |
160 const GURL& document_url); | 160 const GURL& document_url); |
161 virtual ~EntryActionOperation(); | 161 virtual ~EntryActionOperation(); |
162 | 162 |
163 protected: | 163 protected: |
164 // Overridden from UrlFetchOperationBase. | 164 // Overridden from UrlFetchOperationBase. |
165 virtual GURL GetURL() const OVERRIDE; | 165 virtual GURL GetURL() const OVERRIDE; |
166 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) | 166 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) |
167 OVERRIDE; | 167 OVERRIDE; |
168 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 168 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
169 | 169 |
170 const GURL& document_url() const { return document_url_; } | 170 const GURL& document_url() const { return document_url_; } |
171 | 171 |
172 private: | 172 private: |
173 EntryActionCallback callback_; | 173 EntryActionCallback callback_; |
174 GURL document_url_; | 174 GURL document_url_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 176 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
177 }; | 177 }; |
178 | 178 |
179 //============================== GetDataOperation ============================== | 179 //============================== GetDataOperation ============================== |
180 | 180 |
181 // This class performs the operation for fetching and parsing JSON data content. | 181 // This class performs the operation for fetching and parsing JSON data content. |
182 class GetDataOperation : public UrlFetchOperationBase { | 182 class GetDataOperation : public UrlFetchOperationBase { |
183 public: | 183 public: |
184 GetDataOperation(GDataOperationRegistry* registry, | 184 GetDataOperation(GDataOperationRegistry* registry, |
185 Profile* profile, | 185 Profile* profile, |
186 const GetDataCallback& callback); | 186 const GetDataCallback& callback); |
187 virtual ~GetDataOperation(); | 187 virtual ~GetDataOperation(); |
188 | 188 |
189 // Parse GData JSON response. | 189 // Parse GData JSON response. |
190 static base::Value* ParseResponse(const std::string& data); | 190 static base::Value* ParseResponse(const std::string& data); |
191 | 191 |
192 protected: | 192 protected: |
193 // Overridden from UrlFetchOperationBase. | 193 // Overridden from UrlFetchOperationBase. |
194 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) | 194 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) |
195 OVERRIDE; | 195 OVERRIDE; |
196 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 196 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
197 | 197 |
198 private: | 198 private: |
199 GetDataCallback callback_; | 199 GetDataCallback callback_; |
200 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 200 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
201 }; | 201 }; |
202 | 202 |
203 //============================ GetDocumentsOperation =========================== | 203 //============================ GetDocumentsOperation =========================== |
204 | 204 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 const DownloadActionCallback& download_action_callback, | 257 const DownloadActionCallback& download_action_callback, |
258 const GetDownloadDataCallback& get_download_data_callback, | 258 const GetDownloadDataCallback& get_download_data_callback, |
259 const GURL& document_url, | 259 const GURL& document_url, |
260 const FilePath& virtual_path, | 260 const FilePath& virtual_path, |
261 const FilePath& output_file_path); | 261 const FilePath& output_file_path); |
262 virtual ~DownloadFileOperation(); | 262 virtual ~DownloadFileOperation(); |
263 | 263 |
264 protected: | 264 protected: |
265 // Overridden from UrlFetchOperationBase. | 265 // Overridden from UrlFetchOperationBase. |
266 virtual GURL GetURL() const OVERRIDE; | 266 virtual GURL GetURL() const OVERRIDE; |
267 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) | 267 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) |
268 OVERRIDE; | 268 OVERRIDE; |
269 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 269 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
270 | 270 |
271 // Overridden from content::URLFetcherDelegate. | 271 // Overridden from content::URLFetcherDelegate. |
272 virtual void OnURLFetchDownloadProgress(const content::URLFetcher* source, | 272 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
273 int64 current, int64 total) OVERRIDE; | 273 int64 current, int64 total) OVERRIDE; |
274 virtual bool ShouldSendDownloadData() OVERRIDE; | 274 virtual bool ShouldSendDownloadData() OVERRIDE; |
275 virtual void OnURLFetchDownloadData( | 275 virtual void OnURLFetchDownloadData( |
276 const content::URLFetcher* source, | 276 const net::URLFetcher* source, |
277 scoped_ptr<std::string> download_data) OVERRIDE; | 277 scoped_ptr<std::string> download_data) OVERRIDE; |
278 | 278 |
279 private: | 279 private: |
280 DownloadActionCallback download_action_callback_; | 280 DownloadActionCallback download_action_callback_; |
281 GetDownloadDataCallback get_download_data_callback_; | 281 GetDownloadDataCallback get_download_data_callback_; |
282 GURL document_url_; | 282 GURL document_url_; |
283 | 283 |
284 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); | 284 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); |
285 }; | 285 }; |
286 | 286 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 public: | 452 public: |
453 InitiateUploadOperation(GDataOperationRegistry* registry, | 453 InitiateUploadOperation(GDataOperationRegistry* registry, |
454 Profile* profile, | 454 Profile* profile, |
455 const InitiateUploadCallback& callback, | 455 const InitiateUploadCallback& callback, |
456 const InitiateUploadParams& params); | 456 const InitiateUploadParams& params); |
457 virtual ~InitiateUploadOperation(); | 457 virtual ~InitiateUploadOperation(); |
458 | 458 |
459 protected: | 459 protected: |
460 // Overridden from UrlFetchOperationBase. | 460 // Overridden from UrlFetchOperationBase. |
461 virtual GURL GetURL() const OVERRIDE; | 461 virtual GURL GetURL() const OVERRIDE; |
462 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) | 462 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) |
463 OVERRIDE; | 463 OVERRIDE; |
464 virtual void NotifySuccessToOperationRegistry() OVERRIDE; | 464 virtual void NotifySuccessToOperationRegistry() OVERRIDE; |
465 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 465 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
466 | 466 |
467 // Overridden from UrlFetchOperationBase. | 467 // Overridden from UrlFetchOperationBase. |
468 virtual content::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 468 virtual content::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
469 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 469 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
470 virtual bool GetContentData(std::string* upload_content_type, | 470 virtual bool GetContentData(std::string* upload_content_type, |
471 std::string* upload_content) OVERRIDE; | 471 std::string* upload_content) OVERRIDE; |
472 | 472 |
(...skipping 12 matching lines...) Expand all Loading... |
485 public: | 485 public: |
486 ResumeUploadOperation(GDataOperationRegistry* registry, | 486 ResumeUploadOperation(GDataOperationRegistry* registry, |
487 Profile* profile, | 487 Profile* profile, |
488 const ResumeUploadCallback& callback, | 488 const ResumeUploadCallback& callback, |
489 const ResumeUploadParams& params); | 489 const ResumeUploadParams& params); |
490 virtual ~ResumeUploadOperation(); | 490 virtual ~ResumeUploadOperation(); |
491 | 491 |
492 protected: | 492 protected: |
493 // Overridden from UrlFetchOperationBase. | 493 // Overridden from UrlFetchOperationBase. |
494 virtual GURL GetURL() const OVERRIDE; | 494 virtual GURL GetURL() const OVERRIDE; |
495 virtual bool ProcessURLFetchResults(const content::URLFetcher* source) | 495 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) |
496 OVERRIDE; | 496 OVERRIDE; |
497 virtual void NotifyStartToOperationRegistry() OVERRIDE; | 497 virtual void NotifyStartToOperationRegistry() OVERRIDE; |
498 virtual void NotifySuccessToOperationRegistry() OVERRIDE; | 498 virtual void NotifySuccessToOperationRegistry() OVERRIDE; |
499 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 499 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
500 | 500 |
501 // Overridden from UrlFetchOperationBase. | 501 // Overridden from UrlFetchOperationBase. |
502 virtual content::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 502 virtual content::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
503 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 503 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
504 virtual bool GetContentData(std::string* upload_content_type, | 504 virtual bool GetContentData(std::string* upload_content_type, |
505 std::string* upload_content) OVERRIDE; | 505 std::string* upload_content) OVERRIDE; |
506 | 506 |
507 // Overridden from content::UrlFetcherDelegate | 507 // Overridden from content::UrlFetcherDelegate |
508 virtual void OnURLFetchUploadProgress(const content::URLFetcher* source, | 508 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
509 int64 current, int64 total) OVERRIDE; | 509 int64 current, int64 total) OVERRIDE; |
510 | 510 |
511 private: | 511 private: |
512 ResumeUploadCallback callback_; | 512 ResumeUploadCallback callback_; |
513 ResumeUploadParams params_; | 513 ResumeUploadParams params_; |
514 bool last_chunk_completed_; | 514 bool last_chunk_completed_; |
515 | 515 |
516 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); | 516 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); |
517 }; | 517 }; |
518 | 518 |
519 } // namespace gdata | 519 } // namespace gdata |
520 | 520 |
521 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATIONS_H_ | 521 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATIONS_H_ |
OLD | NEW |