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 "base/callback.h" | 11 #include "base/callback.h" |
12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
13 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 13 #include "chrome/browser/chromeos/gdata/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 DocumentService calls. | 26 // Callback type for authentication related DriveServiceInterface calls. |
27 typedef base::Callback<void(GDataErrorCode error, | 27 typedef base::Callback<void(GDataErrorCode 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 GDataOperationRegistry::Operation, | 31 class AuthOperation : public GDataOperationRegistry::Operation, |
32 public OAuth2AccessTokenConsumer { | 32 public OAuth2AccessTokenConsumer { |
33 public: | 33 public: |
34 AuthOperation(GDataOperationRegistry* registry, | 34 AuthOperation(GDataOperationRegistry* registry, |
35 const AuthStatusCallback& callback, | 35 const AuthStatusCallback& callback, |
36 const std::string& refresh_token); | 36 const std::string& refresh_token); |
(...skipping 11 matching lines...) Expand all Loading... |
48 private: | 48 private: |
49 std::string refresh_token_; | 49 std::string refresh_token_; |
50 AuthStatusCallback callback_; | 50 AuthStatusCallback callback_; |
51 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 51 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
52 | 52 |
53 DISALLOW_COPY_AND_ASSIGN(AuthOperation); | 53 DISALLOW_COPY_AND_ASSIGN(AuthOperation); |
54 }; | 54 }; |
55 | 55 |
56 //=========================== GDataOperationInterface ========================== | 56 //=========================== GDataOperationInterface ========================== |
57 | 57 |
58 // An interface for implementing an operation used by DocumentsService. | 58 // An interface for implementing an operation used by DriveServiceInterface. |
59 class GDataOperationInterface { | 59 class GDataOperationInterface { |
60 public: | 60 public: |
61 // Callback to DocumentsService upon for re-authentication. | 61 // Callback to DriveServiceInterface upon for re-authentication. |
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(GDataErrorCode code) = 0; |
73 | 73 |
74 // Sets the callback to DocumentsService when the operation restarts due to | 74 // Sets the callback to DriveServiceInterface when the operation restarts due |
75 // 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 GDataErrorCode error, |
85 scoped_ptr<std::string> content)> GetContentCallback; | 85 scoped_ptr<std::string> content)> GetContentCallback; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_ |
OLD | NEW |