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_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/supervised_user/permission_request_creator.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
14 #include "net/url_request/url_fetcher_delegate.h"
18 class SupervisedUserSigninManagerWrapper;
26 class URLRequestContextGetter;
29 class PermissionRequestCreatorApiary : public PermissionRequestCreator,
30 public OAuth2TokenService::Consumer,
31 public net::URLFetcherDelegate {
33 PermissionRequestCreatorApiary(
34 OAuth2TokenService* oauth2_token_service,
35 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
36 net::URLRequestContextGetter* context);
37 virtual ~PermissionRequestCreatorApiary();
39 static scoped_ptr<PermissionRequestCreator> CreateWithProfile(
42 // PermissionRequestCreator implementation:
43 virtual void CreatePermissionRequest(const GURL& url_requested,
44 const base::Closure& callback) OVERRIDE;
48 typedef ScopedVector<Request>::iterator RequestIterator;
50 // OAuth2TokenService::Consumer implementation:
51 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
52 const std::string& access_token,
53 const base::Time& expiration_time) OVERRIDE;
54 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
55 const GoogleServiceAuthError& error) OVERRIDE;
57 // net::URLFetcherDelegate implementation.
58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
60 std::string GetApiScopeToUse() const;
62 // Requests an access token, which is the first thing we need. This is where
63 // we restart when the returned access token has expired.
64 void StartFetching(Request* request);
66 void DispatchNetworkError(RequestIterator it, int error_code);
67 void DispatchGoogleServiceAuthError(RequestIterator it,
68 const GoogleServiceAuthError& error);
70 OAuth2TokenService* oauth2_token_service_;
71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper_;
72 net::URLRequestContextGetter* context_;
74 ScopedVector<Request> requests_;
77 #endif // CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_