Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / supervised_user / permission_request_creator_apiary.h
blobee1ecdb529cbb120527b4c0242a66429ebfee658
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 <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/supervised_user/permission_request_creator.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "url/gurl.h"
16 class Profile;
17 class SupervisedUserSigninManagerWrapper;
19 namespace base {
20 class Time;
23 namespace net {
24 class URLFetcher;
25 class URLRequestContextGetter;
28 class PermissionRequestCreatorApiary : public PermissionRequestCreator,
29 public OAuth2TokenService::Consumer,
30 public net::URLFetcherDelegate {
31 public:
32 PermissionRequestCreatorApiary(
33 OAuth2TokenService* oauth2_token_service,
34 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
35 net::URLRequestContextGetter* context);
36 virtual ~PermissionRequestCreatorApiary();
38 static scoped_ptr<PermissionRequestCreator> CreateWithProfile(
39 Profile* profile);
41 // PermissionRequestCreator implementation:
42 virtual void CreatePermissionRequest(const GURL& url_requested,
43 const base::Closure& callback) OVERRIDE;
45 private:
46 // OAuth2TokenService::Consumer implementation:
47 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
48 const std::string& access_token,
49 const base::Time& expiration_time) OVERRIDE;
50 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
51 const GoogleServiceAuthError& error) OVERRIDE;
53 // net::URLFetcherDelegate implementation.
54 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
56 std::string GetApiScopeToUse() const;
58 // Requests an access token, which is the first thing we need. This is where
59 // we restart when the returned access token has expired.
60 void StartFetching();
62 void DispatchNetworkError(int error_code);
63 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error);
65 OAuth2TokenService* oauth2_token_service_;
66 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper_;
67 base::Closure callback_;
68 net::URLRequestContextGetter* context_;
69 GURL url_requested_;
70 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
71 std::string access_token_;
72 bool access_token_expired_;
73 scoped_ptr<net::URLFetcher> url_fetcher_;
76 #endif // CHROME_BROWSER_SUPERVISED_USER_PERMISSION_REQUEST_CREATOR_APIARY_H_