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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_
8 #include "chrome/browser/supervised_user/permission_request_creator.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "google_apis/gaia/oauth2_token_service.h"
12 #include "net/url_request/url_fetcher_delegate.h"
15 class SupervisedUserSigninManagerWrapper;
23 class URLRequestContextGetter;
26 class PermissionRequestCreatorApiary : public PermissionRequestCreator,
27 public OAuth2TokenService::Consumer,
28 public net::URLFetcherDelegate {
30 PermissionRequestCreatorApiary(
31 OAuth2TokenService* oauth2_token_service,
32 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
33 net::URLRequestContextGetter* context);
34 virtual ~PermissionRequestCreatorApiary();
36 static scoped_ptr<PermissionRequestCreator> CreateWithProfile(
39 // PermissionRequestCreator implementation:
40 virtual void CreatePermissionRequest(const std::string& url_requested,
41 const base::Closure& callback) OVERRIDE;
44 // OAuth2TokenService::Consumer implementation:
45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
46 const std::string& access_token,
47 const base::Time& expiration_time) OVERRIDE;
48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
49 const GoogleServiceAuthError& error) OVERRIDE;
51 // net::URLFetcherDelegate implementation.
52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
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.
58 void DispatchNetworkError(int error_code);
59 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error);
61 OAuth2TokenService* oauth2_token_service_;
62 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper_;
63 base::Closure callback_;
64 net::URLRequestContextGetter* context_;
65 std::string url_requested_;
66 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
67 std::string access_token_;
68 bool access_token_expired_;
69 scoped_ptr<net::URLFetcher> url_fetcher_;
72 #endif // CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_