OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/file_manager/private_api_misc.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 11 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
11 #include "chrome/browser/chromeos/drive/logging.h" | 12 #include "chrome/browser/chromeos/drive/logging.h" |
12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
13 #include "chrome/browser/chromeos/file_manager/file_manager_installer.h" | 14 #include "chrome/browser/chromeos/file_manager/file_manager_installer.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/google_apis/auth_service.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/common/page_zoom.h" | 23 #include "content/public/common/page_zoom.h" |
| 24 #include "google_apis/gaia/oauth2_token_service.h" |
20 #include "url/gurl.h" | 25 #include "url/gurl.h" |
21 | 26 |
22 namespace extensions { | 27 namespace extensions { |
23 | 28 |
| 29 namespace { |
| 30 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; |
| 31 } |
| 32 |
24 FileBrowserPrivateLogoutUserFunction::FileBrowserPrivateLogoutUserFunction() { | 33 FileBrowserPrivateLogoutUserFunction::FileBrowserPrivateLogoutUserFunction() { |
25 } | 34 } |
26 | 35 |
27 FileBrowserPrivateLogoutUserFunction::~FileBrowserPrivateLogoutUserFunction() { | 36 FileBrowserPrivateLogoutUserFunction::~FileBrowserPrivateLogoutUserFunction() { |
28 } | 37 } |
29 | 38 |
30 bool FileBrowserPrivateLogoutUserFunction::RunImpl() { | 39 bool FileBrowserPrivateLogoutUserFunction::RunImpl() { |
31 chrome::AttemptUserExit(); | 40 chrome::AttemptUserExit(); |
32 return true; | 41 return true; |
33 } | 42 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 drive::util::Log(logging::LOG_ERROR, | 256 drive::util::Log(logging::LOG_ERROR, |
248 "App install failed. (item id: %s, reason: %s)", | 257 "App install failed. (item id: %s, reason: %s)", |
249 webstore_item_id_.c_str(), | 258 webstore_item_id_.c_str(), |
250 error.c_str()); | 259 error.c_str()); |
251 error_ = error; | 260 error_ = error; |
252 } | 261 } |
253 | 262 |
254 SendResponse(success); | 263 SendResponse(success); |
255 } | 264 } |
256 | 265 |
| 266 FileBrowserPrivateRequestWebStoreAccessTokenFunction:: |
| 267 FileBrowserPrivateRequestWebStoreAccessTokenFunction() { |
| 268 } |
| 269 |
| 270 FileBrowserPrivateRequestWebStoreAccessTokenFunction:: |
| 271 ~FileBrowserPrivateRequestWebStoreAccessTokenFunction() { |
| 272 } |
| 273 |
| 274 bool FileBrowserPrivateRequestWebStoreAccessTokenFunction::RunImpl() { |
| 275 std::vector<std::string> scopes; |
| 276 scopes.push_back(kCWSScope); |
| 277 |
| 278 OAuth2TokenService* oauth_service = |
| 279 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
| 280 net::URLRequestContextGetter* url_request_context_getter = |
| 281 g_browser_process->system_request_context(); |
| 282 |
| 283 if (!oauth_service) { |
| 284 drive::util::Log(logging::LOG_ERROR, |
| 285 "CWS OAuth token fetch failed. OAuth2TokenService can't " |
| 286 "be retrived."); |
| 287 SetResult(base::Value::CreateNullValue()); |
| 288 return false; |
| 289 } |
| 290 |
| 291 auth_service_.reset(new google_apis::AuthService( |
| 292 oauth_service, |
| 293 url_request_context_getter, |
| 294 scopes)); |
| 295 auth_service_->StartAuthentication(base::Bind( |
| 296 &FileBrowserPrivateRequestWebStoreAccessTokenFunction:: |
| 297 OnAccessTokenFetched, |
| 298 this)); |
| 299 |
| 300 return true; |
| 301 } |
| 302 |
| 303 void FileBrowserPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched( |
| 304 google_apis::GDataErrorCode code, |
| 305 const std::string& access_token) { |
| 306 if (code == google_apis::HTTP_SUCCESS) { |
| 307 DCHECK(auth_service_->HasAccessToken()); |
| 308 DCHECK(access_token == auth_service_->access_token()); |
| 309 drive::util::Log(logging::LOG_INFO, |
| 310 "CWS OAuth token fetch succeeded. (token: %s)", |
| 311 access_token.c_str()); |
| 312 SetResult(new base::StringValue(access_token)); |
| 313 SendResponse(true); |
| 314 } else { |
| 315 drive::util::Log(logging::LOG_ERROR, |
| 316 "CWS OAuth token fetch failed. (GDataErrorCode: %s)", |
| 317 google_apis::GDataErrorCodeToString(code).c_str()); |
| 318 SetResult(base::Value::CreateNullValue()); |
| 319 SendResponse(false); |
| 320 } |
| 321 } |
| 322 |
257 } // namespace extensions | 323 } // namespace extensions |
OLD | NEW |