| 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_GOOGLE_APIS_BASE_OPERATIONS_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_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 "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/google_apis/gdata_errorcode.h" | 13 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 14 #include "chrome/browser/google_apis/operation_registry.h" | 14 #include "chrome/browser/google_apis/operation_registry.h" |
| 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.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 base { | 22 namespace base { |
| 23 class Value; | 23 class Value; |
| 24 } // namespace base | 24 } // namespace base |
| 25 | 25 |
| 26 namespace google_apis { | 26 namespace google_apis { |
| 27 | 27 |
| 28 //================================ AuthOperation =============================== | |
| 29 | |
| 30 // Callback type for authentication related DriveServiceInterface calls. | |
| 31 typedef base::Callback<void(GDataErrorCode error, | |
| 32 const std::string& token)> AuthStatusCallback; | |
| 33 | |
| 34 // OAuth2 authorization token retrieval operation. | |
| 35 class AuthOperation : public OperationRegistry::Operation, | |
| 36 public OAuth2AccessTokenConsumer { | |
| 37 public: | |
| 38 AuthOperation(OperationRegistry* registry, | |
| 39 const AuthStatusCallback& callback, | |
| 40 const std::vector<std::string>& scopes, | |
| 41 const std::string& refresh_token); | |
| 42 virtual ~AuthOperation(); | |
| 43 void Start(); | |
| 44 | |
| 45 // Overridden from OAuth2AccessTokenConsumer: | |
| 46 virtual void OnGetTokenSuccess(const std::string& access_token, | |
| 47 const base::Time& expiration_time) OVERRIDE; | |
| 48 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | |
| 49 | |
| 50 // Overridden from OperationRegistry::Operation | |
| 51 virtual void DoCancel() OVERRIDE; | |
| 52 | |
| 53 private: | |
| 54 std::string refresh_token_; | |
| 55 AuthStatusCallback callback_; | |
| 56 std::vector<std::string> scopes_; | |
| 57 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(AuthOperation); | |
| 60 }; | |
| 61 | |
| 62 //======================= AuthenticatedOperationInterface ====================== | 28 //======================= AuthenticatedOperationInterface ====================== |
| 63 | 29 |
| 64 // An interface for implementing an operation used by DriveServiceInterface. | 30 // An interface for implementing an operation used by DriveServiceInterface. |
| 65 class AuthenticatedOperationInterface { | 31 class AuthenticatedOperationInterface { |
| 66 public: | 32 public: |
| 67 // Callback to DriveServiceInterface upon for re-authentication. | 33 // Callback to DriveServiceInterface upon for re-authentication. |
| 68 typedef base::Callback<void(AuthenticatedOperationInterface* operation)> | 34 typedef base::Callback<void(AuthenticatedOperationInterface* operation)> |
| 69 ReAuthenticateCallback; | 35 ReAuthenticateCallback; |
| 70 | 36 |
| 71 virtual ~AuthenticatedOperationInterface() {} | 37 virtual ~AuthenticatedOperationInterface() {} |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 208 |
| 243 // Note: This should remain the last member so it'll be destroyed and | 209 // Note: This should remain the last member so it'll be destroyed and |
| 244 // invalidate its weak pointers before any other members are destroyed. | 210 // invalidate its weak pointers before any other members are destroyed. |
| 245 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; | 211 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; |
| 246 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 212 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
| 247 }; | 213 }; |
| 248 | 214 |
| 249 } // namespace google_apis | 215 } // namespace google_apis |
| 250 | 216 |
| 251 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ | 217 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_OPERATIONS_H_ |
| OLD | NEW |