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_CHILD_ACCOUNTS_PERMISSION_REQUEST_CREATOR_APIARY_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_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"
25 class URLRequestContextGetter
;
28 class PermissionRequestCreatorApiary
: public PermissionRequestCreator
,
29 public OAuth2TokenService::Consumer
,
30 public net::URLFetcherDelegate
{
32 PermissionRequestCreatorApiary(
33 OAuth2TokenService
* oauth2_token_service
,
34 const std::string
& account_id
,
35 net::URLRequestContextGetter
* context
);
36 ~PermissionRequestCreatorApiary() override
;
38 static scoped_ptr
<PermissionRequestCreator
> CreateWithProfile(
41 // PermissionRequestCreator implementation:
42 bool IsEnabled() const override
;
43 void CreateURLAccessRequest(const GURL
& url_requested
,
44 const SuccessCallback
& callback
) override
;
45 void CreateExtensionUpdateRequest(const std::string
& id
,
46 const SuccessCallback
& callback
) override
;
48 void set_url_fetcher_id_for_testing(int id
) { url_fetcher_id_
= id
; }
52 typedef ScopedVector
<Request
>::iterator RequestIterator
;
54 // OAuth2TokenService::Consumer implementation:
55 void OnGetTokenSuccess(const OAuth2TokenService::Request
* request
,
56 const std::string
& access_token
,
57 const base::Time
& expiration_time
) override
;
58 void OnGetTokenFailure(const OAuth2TokenService::Request
* request
,
59 const GoogleServiceAuthError
& error
) override
;
61 // net::URLFetcherDelegate implementation.
62 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
64 GURL
GetApiUrl() const;
65 std::string
GetApiScope() const;
67 void CreateRequest(const std::string
& request_type
,
68 const std::string
& object_ref
,
69 const SuccessCallback
& callback
);
71 // Requests an access token, which is the first thing we need. This is where
72 // we restart when the returned access token has expired.
73 void StartFetching(Request
* request
);
75 void DispatchNetworkError(RequestIterator it
, int error_code
);
76 void DispatchGoogleServiceAuthError(RequestIterator it
,
77 const GoogleServiceAuthError
& error
);
79 OAuth2TokenService
* oauth2_token_service_
;
80 std::string account_id_
;
81 net::URLRequestContextGetter
* context_
;
84 ScopedVector
<Request
> requests_
;
86 DISALLOW_COPY_AND_ASSIGN(PermissionRequestCreatorApiary
);
89 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_PERMISSION_REQUEST_CREATOR_APIARY_H_