| 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 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // override this method to specify any extra headers needed for the request. | 105 // override this method to specify any extra headers needed for the request. |
| 106 virtual std::vector<std::string> GetExtraRequestHeaders() const; | 106 virtual std::vector<std::string> GetExtraRequestHeaders() const; |
| 107 // Used by a derived class to add any content data to the request. | 107 // 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 | 108 // Returns true if |upload_content_type| and |upload_content| are updated |
| 109 // with the content type and data for the request. | 109 // with the content type and data for the request. |
| 110 virtual bool GetContentData(std::string* upload_content_type, | 110 virtual bool GetContentData(std::string* upload_content_type, |
| 111 std::string* upload_content); | 111 std::string* upload_content); |
| 112 | 112 |
| 113 // Invoked by OnURLFetchComplete when the operation completes without an | 113 // Invoked by OnURLFetchComplete when the operation completes without an |
| 114 // authentication error. Must be implemented by a derived class. | 114 // authentication error. Must be implemented by a derived class. |
| 115 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) = 0; | 115 virtual void ProcessURLFetchResults(const net::URLFetcher* source) = 0; |
| 116 | 116 |
| 117 // Invoked when it needs to notify the status. Chunked operations that | 117 // Invoked when it needs to notify the status. Chunked operations that |
| 118 // constructs a logically single operation from multiple physical operations | 118 // constructs a logically single operation from multiple physical operations |
| 119 // should notify resume/suspend instead of start/finish. | 119 // should notify resume/suspend instead of start/finish. |
| 120 virtual void NotifyStartToOperationRegistry(); | 120 virtual void NotifyStartToOperationRegistry(); |
| 121 virtual void NotifySuccessToOperationRegistry(); | 121 virtual void NotifySuccessToOperationRegistry(); |
| 122 | 122 |
| 123 // Invoked by this base class upon an authentication error or cancel by | 123 // Invoked by this base class upon an authentication error or cancel by |
| 124 // an user operation. Must be implemented by a derived class. | 124 // an user operation. Must be implemented by a derived class. |
| 125 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 125 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
| 126 | 126 |
| 127 // Implement GDataOperationRegistry::Operation | 127 // Implement GDataOperationRegistry::Operation |
| 128 virtual void DoCancel() OVERRIDE; | 128 virtual void DoCancel() OVERRIDE; |
| 129 | 129 |
| 130 // Overridden from URLFetcherDelegate. | 130 // Overridden from URLFetcherDelegate. |
| 131 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 131 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 132 | 132 |
| 133 // Invoked when ProcessURLFetchResults() is completed. |
| 134 virtual void OnProcessURLFetchResultsComplete(bool result) OVERRIDE; |
| 135 |
| 133 // Overridden from GDataOperationInterface. | 136 // Overridden from GDataOperationInterface. |
| 134 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 137 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
| 135 | 138 |
| 136 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 139 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
| 137 // the status of the URLFetcher. | 140 // the status of the URLFetcher. |
| 138 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; | 141 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; |
| 139 | 142 |
| 140 std::string GetResponseHeadersAsString( | 143 std::string GetResponseHeadersAsString( |
| 141 const net::URLFetcher* url_fetcher); | 144 const net::URLFetcher* url_fetcher); |
| 142 | 145 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 156 class EntryActionOperation : public UrlFetchOperationBase { | 159 class EntryActionOperation : public UrlFetchOperationBase { |
| 157 public: | 160 public: |
| 158 EntryActionOperation(GDataOperationRegistry* registry, | 161 EntryActionOperation(GDataOperationRegistry* registry, |
| 159 Profile* profile, | 162 Profile* profile, |
| 160 const EntryActionCallback& callback, | 163 const EntryActionCallback& callback, |
| 161 const GURL& document_url); | 164 const GURL& document_url); |
| 162 virtual ~EntryActionOperation(); | 165 virtual ~EntryActionOperation(); |
| 163 | 166 |
| 164 protected: | 167 protected: |
| 165 // Overridden from UrlFetchOperationBase. | 168 // Overridden from UrlFetchOperationBase. |
| 166 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 169 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 167 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 170 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
| 168 | 171 |
| 169 const GURL& document_url() const { return document_url_; } | 172 const GURL& document_url() const { return document_url_; } |
| 170 | 173 |
| 171 private: | 174 private: |
| 172 EntryActionCallback callback_; | 175 EntryActionCallback callback_; |
| 173 GURL document_url_; | 176 GURL document_url_; |
| 174 | 177 |
| 175 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 178 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
| 176 }; | 179 }; |
| 177 | 180 |
| 178 //============================== GetDataOperation ============================== | 181 //============================== GetDataOperation ============================== |
| 179 | 182 |
| 180 // This class performs the operation for fetching and parsing JSON data content. | 183 // This class performs the operation for fetching and parsing JSON data content. |
| 181 class GetDataOperation : public UrlFetchOperationBase { | 184 class GetDataOperation : public UrlFetchOperationBase { |
| 182 public: | 185 public: |
| 183 GetDataOperation(GDataOperationRegistry* registry, | 186 GetDataOperation(GDataOperationRegistry* registry, |
| 184 Profile* profile, | 187 Profile* profile, |
| 185 const GetDataCallback& callback); | 188 const GetDataCallback& callback); |
| 186 virtual ~GetDataOperation(); | 189 virtual ~GetDataOperation(); |
| 187 | 190 |
| 188 // Parse GData JSON response. | 191 // Parse GData JSON response. |
| 189 virtual base::Value* ParseResponse(const std::string& data); | 192 virtual void ParseResponse(GDataErrorCode fetch_error_code, |
| 193 const std::string& data); |
| 190 | 194 |
| 191 protected: | 195 protected: |
| 192 // Overridden from UrlFetchOperationBase. | 196 // Overridden from UrlFetchOperationBase. |
| 193 virtual bool ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 197 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 194 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 198 virtual void RunCallbackOnPrematureFailure( |
| 199 GDataErrorCode fetch_error_code) OVERRIDE; |
| 200 void RunCallback(GDataErrorCode fetch_error_code, |
| 201 scoped_ptr<base::Value> value); |
| 195 | 202 |
| 196 private: | 203 private: |
| 204 // Called when ParseJsonOnBlockingPool() is completed. |
| 205 void OnDataParsed(gdata::GDataErrorCode fetch_error_code, |
| 206 scoped_ptr<base::Value>* value, |
| 207 const gdata::GetDataCallback& callback); |
| 208 |
| 197 GetDataCallback callback_; | 209 GetDataCallback callback_; |
| 198 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 210 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
| 199 }; | 211 }; |
| 200 | 212 |
| 201 } // namespace gdata | 213 } // namespace gdata |
| 202 | 214 |
| 203 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 215 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
| OLD | NEW |