OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_MANAGED_MODE_PERMISSION_REQUEST_CREATOR_APIARY_H_ | |
6 #define CHROME_BROWSER_MANAGED_MODE_PERMISSION_REQUEST_CREATOR_APIARY_H_ | |
7 | |
8 #include "chrome/browser/managed_mode/permission_request_creator.h" | |
9 | |
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" | |
13 | |
14 class ManagedUserSigninManagerWrapper; | |
15 class Profile; | |
16 | |
17 namespace base { | |
18 class Time; | |
19 } | |
20 | |
21 namespace net { | |
22 class URLFetcher; | |
23 class URLRequestContextGetter; | |
24 } | |
25 | |
26 class PermissionRequestCreatorApiary : public PermissionRequestCreator, | |
27 public OAuth2TokenService::Consumer, | |
28 public net::URLFetcherDelegate { | |
29 public: | |
30 PermissionRequestCreatorApiary( | |
31 OAuth2TokenService* oauth2_token_service, | |
32 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper, | |
33 net::URLRequestContextGetter* context); | |
34 virtual ~PermissionRequestCreatorApiary(); | |
35 | |
36 static scoped_ptr<PermissionRequestCreator> CreateWithProfile( | |
37 Profile* profile); | |
38 | |
39 // PermissionRequestCreator implementation: | |
40 virtual void CreatePermissionRequest(const std::string& url_requested, | |
41 const base::Closure& callback) OVERRIDE; | |
42 | |
43 private: | |
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; | |
50 | |
51 // net::URLFetcherDelegate implementation. | |
52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
53 | |
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. | |
56 void StartFetching(); | |
57 | |
58 void DispatchNetworkError(int error_code); | |
59 void DispatchGoogleServiceAuthError(const GoogleServiceAuthError& error); | |
60 | |
61 OAuth2TokenService* oauth2_token_service_; | |
62 scoped_ptr<ManagedUserSigninManagerWrapper> 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_; | |
70 }; | |
71 | |
72 #endif // CHROME_BROWSER_MANAGED_MODE_PERMISSION_REQUEST_CREATOR_APIARY_H_ | |
OLD | NEW |