OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" | 5 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/sync/managed_user_signin_manager_wrapper.h" | 17 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
20 #include "components/signin/core/browser/signin_manager.h" | 20 #include "components/signin/core/browser/signin_manager.h" |
21 #include "components/signin/core/browser/signin_manager_base.h" | 21 #include "components/signin/core/browser/signin_manager_base.h" |
22 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
26 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
28 | 28 |
29 using net::URLFetcher; | 29 using net::URLFetcher; |
30 | 30 |
31 const int kNumRetries = 1; | 31 const int kNumRetries = 1; |
32 const char kIdKey[] = "id"; | 32 const char kIdKey[] = "id"; |
33 const char kNamespace[] = "CHROME"; | 33 const char kNamespace[] = "CHROME"; |
34 const char kState[] = "PENDING"; | 34 const char kState[] = "PENDING"; |
35 | 35 |
36 static const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 36 static const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
37 | 37 |
38 PermissionRequestCreatorApiary::PermissionRequestCreatorApiary( | 38 PermissionRequestCreatorApiary::PermissionRequestCreatorApiary( |
39 OAuth2TokenService* oauth2_token_service, | 39 OAuth2TokenService* oauth2_token_service, |
40 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper, | 40 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, |
41 net::URLRequestContextGetter* context) | 41 net::URLRequestContextGetter* context) |
42 : OAuth2TokenService::Consumer("permissions_creator"), | 42 : OAuth2TokenService::Consumer("permissions_creator"), |
43 oauth2_token_service_(oauth2_token_service), | 43 oauth2_token_service_(oauth2_token_service), |
44 signin_wrapper_(signin_wrapper.Pass()), | 44 signin_wrapper_(signin_wrapper.Pass()), |
45 context_(context), | 45 context_(context), |
46 access_token_expired_(false) {} | 46 access_token_expired_(false) {} |
47 | 47 |
48 PermissionRequestCreatorApiary::~PermissionRequestCreatorApiary() {} | 48 PermissionRequestCreatorApiary::~PermissionRequestCreatorApiary() {} |
49 | 49 |
50 // static | 50 // static |
51 scoped_ptr<PermissionRequestCreator> | 51 scoped_ptr<PermissionRequestCreator> |
52 PermissionRequestCreatorApiary::CreateWithProfile(Profile* profile) { | 52 PermissionRequestCreatorApiary::CreateWithProfile(Profile* profile) { |
53 ProfileOAuth2TokenService* token_service = | 53 ProfileOAuth2TokenService* token_service = |
54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
55 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); | 55 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
56 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper( | 56 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper( |
57 new ManagedUserSigninManagerWrapper(profile, signin)); | 57 new SupervisedUserSigninManagerWrapper(profile, signin)); |
58 scoped_ptr<PermissionRequestCreator> creator( | 58 scoped_ptr<PermissionRequestCreator> creator( |
59 new PermissionRequestCreatorApiary( | 59 new PermissionRequestCreatorApiary( |
60 token_service, signin_wrapper.Pass(), profile->GetRequestContext())); | 60 token_service, signin_wrapper.Pass(), profile->GetRequestContext())); |
61 return creator.Pass(); | 61 return creator.Pass(); |
62 } | 62 } |
63 | 63 |
64 void PermissionRequestCreatorApiary::CreatePermissionRequest( | 64 void PermissionRequestCreatorApiary::CreatePermissionRequest( |
65 const std::string& url_requested, | 65 const std::string& url_requested, |
66 const base::Closure& callback) { | 66 const base::Closure& callback) { |
67 url_requested_ = url_requested; | 67 url_requested_ = url_requested; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void PermissionRequestCreatorApiary::DispatchNetworkError(int error_code) { | 160 void PermissionRequestCreatorApiary::DispatchNetworkError(int error_code) { |
161 DispatchGoogleServiceAuthError( | 161 DispatchGoogleServiceAuthError( |
162 GoogleServiceAuthError::FromConnectionError(error_code)); | 162 GoogleServiceAuthError::FromConnectionError(error_code)); |
163 } | 163 } |
164 | 164 |
165 void PermissionRequestCreatorApiary::DispatchGoogleServiceAuthError( | 165 void PermissionRequestCreatorApiary::DispatchGoogleServiceAuthError( |
166 const GoogleServiceAuthError& error) { | 166 const GoogleServiceAuthError& error) { |
167 callback_.Run(); | 167 callback_.Run(); |
168 callback_.Reset(); | 168 callback_.Reset(); |
169 } | 169 } |
OLD | NEW |