Chromium Code Reviews| 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/file_manager_installer .h" | 13 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_installer .h" |
| 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.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 auth_service_.reset(new google_apis::AuthService( | |
| 284 oauth_service, | |
| 285 url_request_context_getter, | |
| 286 scopes)); | |
| 287 auth_service_->StartAuthentication(base::Bind( | |
| 288 &FileBrowserPrivateRequestWebStoreAccessTokenFunction:: | |
| 289 OnAccessTokenFetched, | |
| 290 this)); | |
| 291 | |
| 292 return true; | |
| 293 } | |
| 294 | |
| 295 void FileBrowserPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched( | |
| 296 google_apis::GDataErrorCode code, | |
| 297 const std::string& access_token) { | |
| 298 if (code == google_apis::HTTP_SUCCESS) { | |
| 299 DCHECK(auth_service_->HasAccessToken()); | |
| 300 DCHECK(access_token == auth_service_->access_token()); | |
| 301 drive::util::Log(logging::LOG_INFO, | |
| 302 "CWS OAuth token fetch succeeded. (token: %s)", | |
| 303 access_token.c_str()); | |
| 304 SetResult(new base::StringValue(access_token)); | |
| 305 SendResponse(true); | |
| 306 } else { | |
| 307 drive::util::Log(logging::LOG_ERROR, | |
| 308 "CWS OAuth token fetch failed. (GDataErrorCode: %s)", | |
| 309 google_apis::GDataErrorCodeToString(code).c_str()); | |
| 310 SendResponse(false); | |
|
hidehiko
2013/09/04 05:45:08
FYI: for error handling, setting error_ may be val
yoshiki
2013/09/04 06:14:58
I think passing NULL is enough. Even if Files.app
| |
| 311 } | |
| 312 } | |
| 313 | |
| 257 } // namespace extensions | 314 } // namespace extensions |
| OLD | NEW |