| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/supervised_user/permission_request_creator.h" | 8 #include "chrome/browser/supervised_user/permission_request_creator.h" |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "google_apis/gaia/oauth2_token_service.h" | 11 #include "google_apis/gaia/oauth2_token_service.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" | 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 | 13 |
| 14 class ManagedUserSigninManagerWrapper; | |
| 15 class Profile; | 14 class Profile; |
| 15 class SupervisedUserSigninManagerWrapper; |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class Time; | 18 class Time; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 class URLFetcher; | 22 class URLFetcher; |
| 23 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class PermissionRequestCreatorApiary : public PermissionRequestCreator, | 26 class PermissionRequestCreatorApiary : public PermissionRequestCreator, |
| 27 public OAuth2TokenService::Consumer, | 27 public OAuth2TokenService::Consumer, |
| 28 public net::URLFetcherDelegate { | 28 public net::URLFetcherDelegate { |
| 29 public: | 29 public: |
| 30 PermissionRequestCreatorApiary( | 30 PermissionRequestCreatorApiary( |
| 31 OAuth2TokenService* oauth2_token_service, | 31 OAuth2TokenService* oauth2_token_service, |
| 32 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper, | 32 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, |
| 33 net::URLRequestContextGetter* context); | 33 net::URLRequestContextGetter* context); |
| 34 virtual ~PermissionRequestCreatorApiary(); | 34 virtual ~PermissionRequestCreatorApiary(); |
| 35 | 35 |
| 36 static scoped_ptr<PermissionRequestCreator> CreateWithProfile( | 36 static scoped_ptr<PermissionRequestCreator> CreateWithProfile( |
| 37 Profile* profile); | 37 Profile* profile); |
| 38 | 38 |
| 39 // PermissionRequestCreator implementation: | 39 // PermissionRequestCreator implementation: |
| 40 virtual void CreatePermissionRequest(const std::string& url_requested, | 40 virtual void CreatePermissionRequest(const std::string& url_requested, |
| 41 const base::Closure& callback) OVERRIDE; | 41 const base::Closure& callback) OVERRIDE; |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 // OAuth2TokenService::Consumer implementation: | 44 // OAuth2TokenService::Consumer implementation: |
| 45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 46 const std::string& access_token, | 46 const std::string& access_token, |
| 47 const base::Time& expiration_time) OVERRIDE; | 47 const base::Time& expiration_time) OVERRIDE; |
| 48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 49 const GoogleServiceAuthError& error) OVERRIDE; | 49 const GoogleServiceAuthError& error) OVERRIDE; |
| 50 | 50 |
| 51 // net::URLFetcherDelegate implementation. | 51 // net::URLFetcherDelegate implementation. |
| 52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 53 | 53 |
| 54 // Requests an access token, which is the first thing we need. This is where | 54 // Requests an access token, which is the first thing we need. This is where |
| 55 // we restart when the returned access token has expired. | 55 // we restart when the returned access token has expired. |
| 56 void StartFetching(); | 56 void StartFetching(); |
| 57 | 57 |
| 58 void DispatchNetworkError(int error_code); | 58 void DispatchNetworkError(int error_code); |
| 59 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error); | 59 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error); |
| 60 | 60 |
| 61 OAuth2TokenService* oauth2_token_service_; | 61 OAuth2TokenService* oauth2_token_service_; |
| 62 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper_; | 62 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper_; |
| 63 base::Closure callback_; | 63 base::Closure callback_; |
| 64 net::URLRequestContextGetter* context_; | 64 net::URLRequestContextGetter* context_; |
| 65 std::string url_requested_; | 65 std::string url_requested_; |
| 66 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 66 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 67 std::string access_token_; | 67 std::string access_token_; |
| 68 bool access_token_expired_; | 68 bool access_token_expired_; |
| 69 scoped_ptr<net::URLFetcher> url_fetcher_; | 69 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 #endif // CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ | 72 #endif // CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_ |
| OLD | NEW |