OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/browser_shutdown.h" | 25 #include "chrome/browser/browser_shutdown.h" |
26 #include "chrome/browser/chromeos/boot_times_loader.h" | 26 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 27 #include "chrome/browser/chromeos/cros/cert_library.h" |
27 #include "chrome/browser/chromeos/cros/network_library.h" | 28 #include "chrome/browser/chromeos/cros/network_library.h" |
28 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 29 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
29 #include "chrome/browser/chromeos/dbus/session_manager_client.h" | 30 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
30 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 31 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
31 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 32 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
32 #include "chrome/browser/chromeos/login/background_view.h" | 33 #include "chrome/browser/chromeos/login/background_view.h" |
33 #include "chrome/browser/chromeos/login/cookie_fetcher.h" | 34 #include "chrome/browser/chromeos/login/cookie_fetcher.h" |
34 #include "chrome/browser/chromeos/login/language_switch_menu.h" | 35 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
35 #include "chrome/browser/chromeos/login/login_display_host.h" | 36 #include "chrome/browser/chromeos/login/login_display_host.h" |
36 #include "chrome/browser/chromeos/login/ownership_service.h" | 37 #include "chrome/browser/chromeos/login/ownership_service.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 // The service scope of the OAuth v2 token that ChromeOS login will be | 99 // The service scope of the OAuth v2 token that ChromeOS login will be |
99 // requesting. | 100 // requesting. |
100 // TODO(zelidrag): Figure out if we need to add more services here. | 101 // TODO(zelidrag): Figure out if we need to add more services here. |
101 const char kServiceScopeChromeOS[] = | 102 const char kServiceScopeChromeOS[] = |
102 "https://www.googleapis.com/auth/chromesync"; | 103 "https://www.googleapis.com/auth/chromesync"; |
103 | 104 |
104 const char kServiceScopeChromeOSDeviceManagement[] = | 105 const char kServiceScopeChromeOSDeviceManagement[] = |
105 "https://www.googleapis.com/auth/chromeosdevicemanagement"; | 106 "https://www.googleapis.com/auth/chromeosdevicemanagement"; |
106 | 107 |
| 108 const char kServiceScopeChromeOSDocuments[] = |
| 109 "https://docs.google.com/feeds/ " |
| 110 "https://spreadsheets.google.com/feeds/ " |
| 111 "https://docs.googleusercontent.com/"; |
| 112 |
107 class InitializeCookieMonsterHelper { | 113 class InitializeCookieMonsterHelper { |
108 public: | 114 public: |
109 explicit InitializeCookieMonsterHelper( | 115 explicit InitializeCookieMonsterHelper( |
110 net::URLRequestContextGetter* new_context) | 116 net::URLRequestContextGetter* new_context) |
111 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(base::Bind( | 117 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(base::Bind( |
112 &InitializeCookieMonsterHelper::InitializeCookieMonster, | 118 &InitializeCookieMonsterHelper::InitializeCookieMonster, |
113 base::Unretained(this)))), | 119 base::Unretained(this)))), |
114 new_context_(new_context) { | 120 new_context_(new_context) { |
115 } | 121 } |
116 | 122 |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 } | 1113 } |
1108 } | 1114 } |
1109 | 1115 |
1110 void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username, | 1116 void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username, |
1111 Profile* user_profile) { | 1117 Profile* user_profile) { |
1112 username_ = username; | 1118 username_ = username; |
1113 KickStartAuthentication(user_profile); | 1119 KickStartAuthentication(user_profile); |
1114 } | 1120 } |
1115 | 1121 |
1116 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 1122 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { |
1117 if (!authenticator_.get()) | |
1118 CreateAuthenticator(NULL); | |
1119 std::string oauth1_token; | 1123 std::string oauth1_token; |
1120 std::string oauth1_secret; | 1124 std::string oauth1_secret; |
1121 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1125 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
1122 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 1126 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
1123 | |
1124 authenticator_ = NULL; | |
1125 } | 1127 } |
1126 | 1128 |
1127 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) { | 1129 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) { |
1128 background_view_ = background_view; | 1130 background_view_ = background_view; |
1129 } | 1131 } |
1130 | 1132 |
1131 BackgroundView* LoginUtilsImpl::GetBackgroundView() { | 1133 BackgroundView* LoginUtilsImpl::GetBackgroundView() { |
1132 return background_view_; | 1134 return background_view_; |
1133 } | 1135 } |
1134 | 1136 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 User::OAUTH_TOKEN_STATUS_VALID) { | 1196 User::OAUTH_TOKEN_STATUS_VALID) { |
1195 return false; | 1197 return false; |
1196 } | 1198 } |
1197 | 1199 |
1198 PrefService* pref_service = user_profile->GetPrefs(); | 1200 PrefService* pref_service = user_profile->GetPrefs(); |
1199 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); | 1201 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); |
1200 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); | 1202 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); |
1201 if (!encoded_token.length() || !encoded_secret.length()) | 1203 if (!encoded_token.length() || !encoded_secret.length()) |
1202 return false; | 1204 return false; |
1203 | 1205 |
1204 DCHECK(authenticator_.get()); | 1206 std::string decoded_token = |
1205 std::string decoded_token = authenticator_->DecryptToken(encoded_token); | 1207 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); |
1206 std::string decoded_secret = authenticator_->DecryptToken(encoded_secret); | 1208 std::string decoded_secret = |
| 1209 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); |
1207 if (!decoded_token.length() || !decoded_secret.length()) | 1210 if (!decoded_token.length() || !decoded_secret.length()) |
1208 return false; | 1211 return false; |
1209 | 1212 |
1210 *token = decoded_token; | 1213 *token = decoded_token; |
1211 *secret = decoded_secret; | 1214 *secret = decoded_secret; |
1212 return true; | 1215 return true; |
1213 } | 1216 } |
1214 | 1217 |
1215 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, | 1218 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, |
1216 const std::string& token, | 1219 const std::string& token, |
1217 const std::string& secret) { | 1220 const std::string& secret) { |
1218 // First store OAuth1 token + service for the current user profile... | 1221 // First store OAuth1 token + service for the current user profile... |
1219 PrefService* pref_service = user_profile->GetPrefs(); | 1222 PrefService* pref_service = user_profile->GetPrefs(); |
1220 pref_service->SetString(prefs::kOAuth1Token, | 1223 pref_service->SetString(prefs::kOAuth1Token, |
1221 authenticator_->EncryptToken(token)); | 1224 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token)); |
1222 pref_service->SetString(prefs::kOAuth1Secret, | 1225 pref_service->SetString(prefs::kOAuth1Secret, |
1223 authenticator_->EncryptToken(secret)); | 1226 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret)); |
1224 | 1227 |
1225 // ...then record the presence of valid OAuth token for this account in local | 1228 // ...then record the presence of valid OAuth token for this account in local |
1226 // state as well. | 1229 // state as well. |
1227 UserManager::Get()->SaveUserOAuthStatus(username_, | 1230 UserManager::Get()->SaveUserOAuthStatus(username_, |
1228 User::OAUTH_TOKEN_STATUS_VALID); | 1231 User::OAUTH_TOKEN_STATUS_VALID); |
1229 } | 1232 } |
1230 | 1233 |
1231 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, | 1234 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, |
1232 const std::string& token, | 1235 const std::string& token, |
1233 const std::string& secret) { | 1236 const std::string& secret) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 // Mark login host for deletion after browser starts. This | 1333 // Mark login host for deletion after browser starts. This |
1331 // guarantees that the message loop will be referenced by the | 1334 // guarantees that the message loop will be referenced by the |
1332 // browser before it is dereferenced by the login host. | 1335 // browser before it is dereferenced by the login host. |
1333 if (login_host) { | 1336 if (login_host) { |
1334 login_host->OnSessionStart(); | 1337 login_host->OnSessionStart(); |
1335 login_host = NULL; | 1338 login_host = NULL; |
1336 } | 1339 } |
1337 } | 1340 } |
1338 | 1341 |
1339 } // namespace chromeos | 1342 } // namespace chromeos |
OLD | NEW |