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; | |
19 class OAuth2AccessTokenFetcher; | 18 class OAuth2AccessTokenFetcher; |
20 | 19 |
21 namespace gdata { | 20 namespace gdata { |
22 | 21 |
23 //================================ AuthOperation =============================== | 22 //================================ AuthOperation =============================== |
24 | 23 |
25 // OAuth2 authorization token retrieval operation. | 24 // OAuth2 authorization token retrieval operation. |
26 class AuthOperation : public GDataOperationRegistry::Operation, | 25 class AuthOperation : public GDataOperationRegistry::Operation, |
27 public OAuth2AccessTokenConsumer { | 26 public OAuth2AccessTokenConsumer { |
28 public: | 27 public: |
29 AuthOperation(GDataOperationRegistry* registry, | 28 AuthOperation(GDataOperationRegistry* registry, |
30 Profile* profile, | |
31 const AuthStatusCallback& callback, | 29 const AuthStatusCallback& callback, |
32 const std::string& refresh_token); | 30 const std::string& refresh_token); |
33 virtual ~AuthOperation(); | 31 virtual ~AuthOperation(); |
34 void Start(); | 32 void Start(); |
35 | 33 |
36 // Overridden from OAuth2AccessTokenConsumer: | 34 // Overridden from OAuth2AccessTokenConsumer: |
37 virtual void OnGetTokenSuccess(const std::string& access_token, | 35 virtual void OnGetTokenSuccess(const std::string& access_token, |
38 const base::Time& expiration_time) OVERRIDE; | 36 const base::Time& expiration_time) OVERRIDE; |
39 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 37 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
40 | 38 |
41 // Overridden from GDataOpertionRegistry::Operation | 39 // Overridden from GDataOpertionRegistry::Operation |
42 virtual void DoCancel() OVERRIDE; | 40 virtual void DoCancel() OVERRIDE; |
43 | 41 |
44 private: | 42 private: |
45 Profile* profile_; | |
46 std::string refresh_token_; | 43 std::string refresh_token_; |
47 AuthStatusCallback callback_; | 44 AuthStatusCallback callback_; |
48 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 45 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
49 | 46 |
50 DISALLOW_COPY_AND_ASSIGN(AuthOperation); | 47 DISALLOW_COPY_AND_ASSIGN(AuthOperation); |
51 }; | 48 }; |
52 | 49 |
53 //=========================== GDataOperationInterface ========================== | 50 //=========================== GDataOperationInterface ========================== |
54 | 51 |
55 // An interface for implementing an operation used by DocumentsService. | 52 // An interface for implementing an operation used by DocumentsService. |
(...skipping 26 matching lines...) Expand all Loading... |
82 public net::URLFetcherDelegate { | 79 public net::URLFetcherDelegate { |
83 public: | 80 public: |
84 // Overridden from GDataOperationInterface. | 81 // Overridden from GDataOperationInterface. |
85 virtual void Start(const std::string& auth_token) OVERRIDE; | 82 virtual void Start(const std::string& auth_token) OVERRIDE; |
86 | 83 |
87 // Overridden from GDataOperationInterface. | 84 // Overridden from GDataOperationInterface. |
88 virtual void SetReAuthenticateCallback( | 85 virtual void SetReAuthenticateCallback( |
89 const ReAuthenticateCallback& callback) OVERRIDE; | 86 const ReAuthenticateCallback& callback) OVERRIDE; |
90 | 87 |
91 protected: | 88 protected: |
92 UrlFetchOperationBase(GDataOperationRegistry* registry, Profile* profile); | 89 UrlFetchOperationBase(GDataOperationRegistry* registry); |
93 UrlFetchOperationBase(GDataOperationRegistry* registry, | 90 UrlFetchOperationBase(GDataOperationRegistry* registry, |
94 GDataOperationRegistry::OperationType type, | 91 GDataOperationRegistry::OperationType type, |
95 const FilePath& path, | 92 const FilePath& path); |
96 Profile* profile); | |
97 virtual ~UrlFetchOperationBase(); | 93 virtual ~UrlFetchOperationBase(); |
98 | 94 |
99 // Gets URL for the request. | 95 // Gets URL for the request. |
100 virtual GURL GetURL() const = 0; | 96 virtual GURL GetURL() const = 0; |
101 // Returns the request type. A derived class should override this method | 97 // Returns the request type. A derived class should override this method |
102 // for a request type other than HTTP GET. | 98 // for a request type other than HTTP GET. |
103 virtual net::URLFetcher::RequestType GetRequestType() const; | 99 virtual net::URLFetcher::RequestType GetRequestType() const; |
104 // Returns the extra HTTP headers for the request. A derived class should | 100 // Returns the extra HTTP headers for the request. A derived class should |
105 // override this method to specify any extra headers needed for the request. | 101 // override this method to specify any extra headers needed for the request. |
106 virtual std::vector<std::string> GetExtraRequestHeaders() const; | 102 virtual std::vector<std::string> GetExtraRequestHeaders() const; |
(...skipping 29 matching lines...) Expand all Loading... |
136 // Invoked when ProcessURLFetchResults() is completed. | 132 // Invoked when ProcessURLFetchResults() is completed. |
137 void OnProcessURLFetchResultsComplete(bool result); | 133 void OnProcessURLFetchResultsComplete(bool result); |
138 | 134 |
139 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 135 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
140 // the status of the URLFetcher. | 136 // the status of the URLFetcher. |
141 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; | 137 GDataErrorCode GetErrorCode(const net::URLFetcher* source) const; |
142 | 138 |
143 std::string GetResponseHeadersAsString( | 139 std::string GetResponseHeadersAsString( |
144 const net::URLFetcher* url_fetcher); | 140 const net::URLFetcher* url_fetcher); |
145 | 141 |
146 Profile* profile_; | |
147 ReAuthenticateCallback re_authenticate_callback_; | 142 ReAuthenticateCallback re_authenticate_callback_; |
148 int re_authenticate_count_; | 143 int re_authenticate_count_; |
149 bool save_temp_file_; | 144 bool save_temp_file_; |
150 FilePath output_file_path_; | 145 FilePath output_file_path_; |
151 scoped_ptr<net::URLFetcher> url_fetcher_; | 146 scoped_ptr<net::URLFetcher> url_fetcher_; |
152 bool started_; | 147 bool started_; |
153 }; | 148 }; |
154 | 149 |
155 //============================ EntryActionOperation ============================ | 150 //============================ EntryActionOperation ============================ |
156 | 151 |
157 // This class performs a simple action over a given entry (document/file). | 152 // This class performs a simple action over a given entry (document/file). |
158 // It is meant to be used for operations that return no JSON blobs. | 153 // It is meant to be used for operations that return no JSON blobs. |
159 class EntryActionOperation : public UrlFetchOperationBase { | 154 class EntryActionOperation : public UrlFetchOperationBase { |
160 public: | 155 public: |
161 EntryActionOperation(GDataOperationRegistry* registry, | 156 EntryActionOperation(GDataOperationRegistry* registry, |
162 Profile* profile, | |
163 const EntryActionCallback& callback, | 157 const EntryActionCallback& callback, |
164 const GURL& document_url); | 158 const GURL& document_url); |
165 virtual ~EntryActionOperation(); | 159 virtual ~EntryActionOperation(); |
166 | 160 |
167 protected: | 161 protected: |
168 // Overridden from UrlFetchOperationBase. | 162 // Overridden from UrlFetchOperationBase. |
169 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 163 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
170 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 164 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
171 | 165 |
172 const GURL& document_url() const { return document_url_; } | 166 const GURL& document_url() const { return document_url_; } |
173 | 167 |
174 private: | 168 private: |
175 EntryActionCallback callback_; | 169 EntryActionCallback callback_; |
176 GURL document_url_; | 170 GURL document_url_; |
177 | 171 |
178 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 172 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
179 }; | 173 }; |
180 | 174 |
181 //============================== GetDataOperation ============================== | 175 //============================== GetDataOperation ============================== |
182 | 176 |
183 // This class performs the operation for fetching and parsing JSON data content. | 177 // This class performs the operation for fetching and parsing JSON data content. |
184 class GetDataOperation : public UrlFetchOperationBase { | 178 class GetDataOperation : public UrlFetchOperationBase { |
185 public: | 179 public: |
186 GetDataOperation(GDataOperationRegistry* registry, | 180 GetDataOperation(GDataOperationRegistry* registry, |
187 Profile* profile, | |
188 const GetDataCallback& callback); | 181 const GetDataCallback& callback); |
189 virtual ~GetDataOperation(); | 182 virtual ~GetDataOperation(); |
190 | 183 |
191 // Parse GData JSON response. | 184 // Parse GData JSON response. |
192 virtual void ParseResponse(GDataErrorCode fetch_error_code, | 185 virtual void ParseResponse(GDataErrorCode fetch_error_code, |
193 const std::string& data); | 186 const std::string& data); |
194 | 187 |
195 protected: | 188 protected: |
196 // Overridden from UrlFetchOperationBase. | 189 // Overridden from UrlFetchOperationBase. |
197 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 190 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
209 | 202 |
210 // Note: This should remain the last member so it'll be destroyed and | 203 // Note: This should remain the last member so it'll be destroyed and |
211 // invalidate its weak pointers before any other members are destroyed. | 204 // invalidate its weak pointers before any other members are destroyed. |
212 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; | 205 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; |
213 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 206 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
214 }; | 207 }; |
215 | 208 |
216 } // namespace gdata | 209 } // namespace gdata |
217 | 210 |
218 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 211 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
OLD | NEW |