Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: chrome/browser/chromeos/gdata/operations_base.h

Issue 10877006: Rename GDataErrorCode to DriveErrorCode, GDataFileError to DriveFileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/callback.h" 11 #include "base/callback.h"
12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" 12 #include "chrome/browser/chromeos/gdata/drive_errorcode.h"
13 #include "chrome/browser/chromeos/gdata/operation_registry.h" 13 #include "chrome/browser/chromeos/gdata/operation_registry.h"
14 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" 14 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_fetcher.h"
18 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
19 19
20 class OAuth2AccessTokenFetcher; 20 class OAuth2AccessTokenFetcher;
21 21
22 namespace gdata { 22 namespace gdata {
23 23
24 //================================ AuthOperation =============================== 24 //================================ AuthOperation ===============================
25 25
26 // Callback type for authentication related DriveServiceInterface calls. 26 // Callback type for authentication related DriveServiceInterface calls.
27 typedef base::Callback<void(GDataErrorCode error, 27 typedef base::Callback<void(DriveErrorCode error,
28 const std::string& token)> AuthStatusCallback; 28 const std::string& token)> AuthStatusCallback;
29 29
30 // OAuth2 authorization token retrieval operation. 30 // OAuth2 authorization token retrieval operation.
31 class AuthOperation : public OperationRegistry::Operation, 31 class AuthOperation : public OperationRegistry::Operation,
32 public OAuth2AccessTokenConsumer { 32 public OAuth2AccessTokenConsumer {
33 public: 33 public:
34 AuthOperation(OperationRegistry* registry, 34 AuthOperation(OperationRegistry* registry,
35 const AuthStatusCallback& callback, 35 const AuthStatusCallback& callback,
36 const std::string& refresh_token); 36 const std::string& refresh_token);
37 virtual ~AuthOperation(); 37 virtual ~AuthOperation();
(...skipping 24 matching lines...) Expand all
62 typedef base::Callback<void(GDataOperationInterface* operation)> 62 typedef base::Callback<void(GDataOperationInterface* operation)>
63 ReAuthenticateCallback; 63 ReAuthenticateCallback;
64 64
65 virtual ~GDataOperationInterface() {} 65 virtual ~GDataOperationInterface() {}
66 66
67 // Starts the actual operation after obtaining an authentication token 67 // Starts the actual operation after obtaining an authentication token
68 // |auth_token|. 68 // |auth_token|.
69 virtual void Start(const std::string& auth_token) = 0; 69 virtual void Start(const std::string& auth_token) = 0;
70 70
71 // Invoked when the authentication failed with an error code |code|. 71 // Invoked when the authentication failed with an error code |code|.
72 virtual void OnAuthFailed(GDataErrorCode code) = 0; 72 virtual void OnAuthFailed(DriveErrorCode code) = 0;
73 73
74 // Sets the callback to DriveServiceInterface when the operation restarts due 74 // Sets the callback to DriveServiceInterface when the operation restarts due
75 // to an authentication failure. 75 // to an authentication failure.
76 virtual void SetReAuthenticateCallback( 76 virtual void SetReAuthenticateCallback(
77 const ReAuthenticateCallback& callback) = 0; 77 const ReAuthenticateCallback& callback) = 0;
78 }; 78 };
79 79
80 //============================ UrlFetchOperationBase =========================== 80 //============================ UrlFetchOperationBase ===========================
81 81
82 // Callback type for getting the content from URLFetcher::GetResponseAsString(). 82 // Callback type for getting the content from URLFetcher::GetResponseAsString().
83 typedef base::Callback<void( 83 typedef base::Callback<void(
84 GDataErrorCode error, 84 DriveErrorCode error,
85 scoped_ptr<std::string> content)> GetContentCallback; 85 scoped_ptr<std::string> content)> GetContentCallback;
86 86
87 // Base class for operations that are fetching URLs. 87 // Base class for operations that are fetching URLs.
88 class UrlFetchOperationBase : public GDataOperationInterface, 88 class UrlFetchOperationBase : public GDataOperationInterface,
89 public OperationRegistry::Operation, 89 public OperationRegistry::Operation,
90 public net::URLFetcherDelegate { 90 public net::URLFetcherDelegate {
91 public: 91 public:
92 // Overridden from GDataOperationInterface. 92 // Overridden from GDataOperationInterface.
93 virtual void Start(const std::string& auth_token) OVERRIDE; 93 virtual void Start(const std::string& auth_token) OVERRIDE;
94 94
(...skipping 27 matching lines...) Expand all
122 virtual void ProcessURLFetchResults(const net::URLFetcher* source) = 0; 122 virtual void ProcessURLFetchResults(const net::URLFetcher* source) = 0;
123 123
124 // Invoked when it needs to notify the status. Chunked operations that 124 // Invoked when it needs to notify the status. Chunked operations that
125 // constructs a logically single operation from multiple physical operations 125 // constructs a logically single operation from multiple physical operations
126 // should notify resume/suspend instead of start/finish. 126 // should notify resume/suspend instead of start/finish.
127 virtual void NotifyStartToOperationRegistry(); 127 virtual void NotifyStartToOperationRegistry();
128 virtual void NotifySuccessToOperationRegistry(); 128 virtual void NotifySuccessToOperationRegistry();
129 129
130 // Invoked by this base class upon an authentication error or cancel by 130 // Invoked by this base class upon an authentication error or cancel by
131 // an user operation. Must be implemented by a derived class. 131 // an user operation. Must be implemented by a derived class.
132 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; 132 virtual void RunCallbackOnPrematureFailure(DriveErrorCode code) = 0;
133 133
134 // Implement OperationRegistry::Operation 134 // Implement OperationRegistry::Operation
135 virtual void DoCancel() OVERRIDE; 135 virtual void DoCancel() OVERRIDE;
136 136
137 // Overridden from URLFetcherDelegate. 137 // Overridden from URLFetcherDelegate.
138 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 138 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
139 139
140 // Overridden from GDataOperationInterface. 140 // Overridden from GDataOperationInterface.
141 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; 141 virtual void OnAuthFailed(DriveErrorCode code) OVERRIDE;
142 142
143 // Invoked when ProcessURLFetchResults() is completed. 143 // Invoked when ProcessURLFetchResults() is completed.
144 void OnProcessURLFetchResultsComplete(bool result); 144 void OnProcessURLFetchResultsComplete(bool result);
145 145
146 // Returns an appropriate GDataErrorCode based on the HTTP response code and 146 // Returns an appropriate DriveErrorCode based on the HTTP response code and
147 // the status of the URLFetcher. 147 // the status of the URLFetcher.
148 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; 148 DriveErrorCode GetErrorCode(const net::URLFetcher* source) const;
149 149
150 std::string GetResponseHeadersAsString( 150 std::string GetResponseHeadersAsString(
151 const net::URLFetcher* url_fetcher); 151 const net::URLFetcher* url_fetcher);
152 152
153 ReAuthenticateCallback re_authenticate_callback_; 153 ReAuthenticateCallback re_authenticate_callback_;
154 int re_authenticate_count_; 154 int re_authenticate_count_;
155 bool save_temp_file_; 155 bool save_temp_file_;
156 FilePath output_file_path_; 156 FilePath output_file_path_;
157 scoped_ptr<net::URLFetcher> url_fetcher_; 157 scoped_ptr<net::URLFetcher> url_fetcher_;
158 bool started_; 158 bool started_;
159 }; 159 };
160 160
161 //============================ EntryActionOperation ============================ 161 //============================ EntryActionOperation ============================
162 162
163 // Callback type for Delete/Move DocumentServiceInterface calls. 163 // Callback type for Delete/Move DocumentServiceInterface calls.
164 typedef base::Callback<void(GDataErrorCode error, 164 typedef base::Callback<void(DriveErrorCode error,
165 const GURL& document_url)> EntryActionCallback; 165 const GURL& document_url)> EntryActionCallback;
166 166
167 // This class performs a simple action over a given entry (document/file). 167 // This class performs a simple action over a given entry (document/file).
168 // It is meant to be used for operations that return no JSON blobs. 168 // It is meant to be used for operations that return no JSON blobs.
169 class EntryActionOperation : public UrlFetchOperationBase { 169 class EntryActionOperation : public UrlFetchOperationBase {
170 public: 170 public:
171 EntryActionOperation(OperationRegistry* registry, 171 EntryActionOperation(OperationRegistry* registry,
172 const EntryActionCallback& callback, 172 const EntryActionCallback& callback,
173 const GURL& document_url); 173 const GURL& document_url);
174 virtual ~EntryActionOperation(); 174 virtual ~EntryActionOperation();
175 175
176 protected: 176 protected:
177 // Overridden from UrlFetchOperationBase. 177 // Overridden from UrlFetchOperationBase.
178 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 178 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
179 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; 179 virtual void RunCallbackOnPrematureFailure(DriveErrorCode code) OVERRIDE;
180 180
181 const GURL& document_url() const { return document_url_; } 181 const GURL& document_url() const { return document_url_; }
182 182
183 private: 183 private:
184 EntryActionCallback callback_; 184 EntryActionCallback callback_;
185 GURL document_url_; 185 GURL document_url_;
186 186
187 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); 187 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation);
188 }; 188 };
189 189
190 //============================== GetDataOperation ============================== 190 //============================== GetDataOperation ==============================
191 191
192 // Callback type for DocumentServiceInterface::GetDocuments. 192 // Callback type for DocumentServiceInterface::GetDocuments.
193 // Note: feed_data argument should be passed using base::Passed(&feed_data), not 193 // Note: feed_data argument should be passed using base::Passed(&feed_data), not
194 // feed_data.Pass(). 194 // feed_data.Pass().
195 typedef base::Callback<void(GDataErrorCode error, 195 typedef base::Callback<void(DriveErrorCode error,
196 scoped_ptr<base::Value> feed_data)> GetDataCallback; 196 scoped_ptr<base::Value> feed_data)> GetDataCallback;
197 197
198 // This class performs the operation for fetching and parsing JSON data content. 198 // This class performs the operation for fetching and parsing JSON data content.
199 class GetDataOperation : public UrlFetchOperationBase { 199 class GetDataOperation : public UrlFetchOperationBase {
200 public: 200 public:
201 GetDataOperation(OperationRegistry* registry, 201 GetDataOperation(OperationRegistry* registry,
202 const GetDataCallback& callback); 202 const GetDataCallback& callback);
203 virtual ~GetDataOperation(); 203 virtual ~GetDataOperation();
204 204
205 // Parse GData JSON response. 205 // Parse GData JSON response.
206 virtual void ParseResponse(GDataErrorCode fetch_error_code, 206 virtual void ParseResponse(DriveErrorCode fetch_error_code,
207 const std::string& data); 207 const std::string& data);
208 208
209 protected: 209 protected:
210 // Overridden from UrlFetchOperationBase. 210 // Overridden from UrlFetchOperationBase.
211 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; 211 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
212 virtual void RunCallbackOnPrematureFailure( 212 virtual void RunCallbackOnPrematureFailure(
213 GDataErrorCode fetch_error_code) OVERRIDE; 213 DriveErrorCode fetch_error_code) OVERRIDE;
214 void RunCallback(GDataErrorCode fetch_error_code, 214 void RunCallback(DriveErrorCode fetch_error_code,
215 scoped_ptr<base::Value> value); 215 scoped_ptr<base::Value> value);
216 216
217 private: 217 private:
218 // Called when ParseJsonOnBlockingPool() is completed. 218 // Called when ParseJsonOnBlockingPool() is completed.
219 void OnDataParsed(gdata::GDataErrorCode fetch_error_code, 219 void OnDataParsed(gdata::DriveErrorCode fetch_error_code,
220 scoped_ptr<base::Value>* value); 220 scoped_ptr<base::Value>* value);
221 221
222 GetDataCallback callback_; 222 GetDataCallback callback_;
223 223
224 // Note: This should remain the last member so it'll be destroyed and 224 // Note: This should remain the last member so it'll be destroyed and
225 // invalidate its weak pointers before any other members are destroyed. 225 // invalidate its weak pointers before any other members are destroyed.
226 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; 226 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_;
227 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); 227 DISALLOW_COPY_AND_ASSIGN(GetDataOperation);
228 }; 228 };
229 229
230 } // namespace gdata 230 } // namespace gdata
231 231
232 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ 232 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698