OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 #include "chrome/common/chrome_switches.h" | 65 #include "chrome/common/chrome_switches.h" |
66 #include "chrome/common/logging_chrome.h" | 66 #include "chrome/common/logging_chrome.h" |
67 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 67 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
68 #include "chrome/common/net/gaia/gaia_urls.h" | 68 #include "chrome/common/net/gaia/gaia_urls.h" |
69 #include "chrome/common/pref_names.h" | 69 #include "chrome/common/pref_names.h" |
70 #include "chrome/common/url_constants.h" | 70 #include "chrome/common/url_constants.h" |
71 #include "chromeos/chromeos_switches.h" | 71 #include "chromeos/chromeos_switches.h" |
72 #include "chromeos/dbus/dbus_thread_manager.h" | 72 #include "chromeos/dbus/dbus_thread_manager.h" |
73 #include "chromeos/dbus/session_manager_client.h" | 73 #include "chromeos/dbus/session_manager_client.h" |
74 #include "content/public/browser/browser_thread.h" | 74 #include "content/public/browser/browser_thread.h" |
75 #include "content/public/browser/notification_observer.h" | |
75 #include "content/public/browser/notification_service.h" | 76 #include "content/public/browser/notification_service.h" |
76 #include "googleurl/src/gurl.h" | 77 #include "googleurl/src/gurl.h" |
77 #include "media/base/media_switches.h" | 78 #include "media/base/media_switches.h" |
78 #include "net/base/network_change_notifier.h" | 79 #include "net/base/network_change_notifier.h" |
79 #include "net/cookies/cookie_monster.h" | 80 #include "net/cookies/cookie_monster.h" |
80 #include "net/cookies/cookie_store.h" | 81 #include "net/cookies/cookie_store.h" |
81 #include "net/http/http_auth_cache.h" | 82 #include "net/http/http_auth_cache.h" |
82 #include "net/http/http_network_session.h" | 83 #include "net/http/http_network_session.h" |
83 #include "net/http/http_transaction_factory.h" | 84 #include "net/http/http_transaction_factory.h" |
84 #include "net/url_request/url_request_context.h" | 85 #include "net/url_request/url_request_context.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 std::string command_line_; | 220 std::string command_line_; |
220 PrefService* local_state_; | 221 PrefService* local_state_; |
221 base::OneShotTimer<JobRestartRequest> timer_; | 222 base::OneShotTimer<JobRestartRequest> timer_; |
222 }; | 223 }; |
223 | 224 |
224 class LoginUtilsImpl | 225 class LoginUtilsImpl |
225 : public LoginUtils, | 226 : public LoginUtils, |
226 public OAuth1TokenFetcher::Delegate, | 227 public OAuth1TokenFetcher::Delegate, |
227 public OAuthLoginVerifier::Delegate, | 228 public OAuthLoginVerifier::Delegate, |
228 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 229 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
230 public content::NotificationObserver, | |
229 public base::SupportsWeakPtr<LoginUtilsImpl> { | 231 public base::SupportsWeakPtr<LoginUtilsImpl> { |
230 public: | 232 public: |
231 LoginUtilsImpl() | 233 LoginUtilsImpl() |
232 : pending_requests_(false), | 234 : pending_requests_(false), |
233 using_oauth_(false), | 235 using_oauth_(false), |
234 has_cookies_(false), | 236 has_cookies_(false), |
235 delegate_(NULL), | 237 delegate_(NULL), |
236 job_restart_request_(NULL), | 238 job_restart_request_(NULL), |
237 should_restore_auth_session_(false) { | 239 should_restore_auth_session_(false), |
240 url_request_context_getter_(NULL) { | |
238 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 241 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
242 // During tests, the browser_process may not be initialized yet causing | |
243 // this to fail. | |
244 if (g_browser_process) { | |
Nikita (slow)
2012/07/13 12:08:12
What were those tests when this failed?
| |
245 registrar_.Add( | |
246 this, | |
247 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | |
248 content::Source<Profile>(ProfileManager::GetDefaultProfile())); | |
249 } | |
239 } | 250 } |
240 | 251 |
241 virtual ~LoginUtilsImpl() { | 252 virtual ~LoginUtilsImpl() { |
242 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 253 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
243 } | 254 } |
244 | 255 |
245 // LoginUtils implementation: | 256 // LoginUtils implementation: |
246 virtual void DoBrowserLaunch(Profile* profile, | 257 virtual void DoBrowserLaunch(Profile* profile, |
247 LoginDisplayHost* login_host) OVERRIDE; | 258 LoginDisplayHost* login_host) OVERRIDE; |
248 virtual void PrepareProfile( | 259 virtual void PrepareProfile( |
(...skipping 30 matching lines...) Expand all Loading... | |
279 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 290 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, |
280 const std::string& sid, | 291 const std::string& sid, |
281 const std::string& lsid, | 292 const std::string& lsid, |
282 const std::string& auth) OVERRIDE; | 293 const std::string& auth) OVERRIDE; |
283 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | 294 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; |
284 | 295 |
285 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 296 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
286 virtual void OnConnectionTypeChanged( | 297 virtual void OnConnectionTypeChanged( |
287 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 298 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
288 | 299 |
300 // content::NotificationObserver overrides. | |
301 virtual void Observe(int type, | |
302 const content::NotificationSource& source, | |
303 const content::NotificationDetails& details) OVERRIDE; | |
304 | |
289 protected: | 305 protected: |
290 virtual std::string GetOffTheRecordCommandLine( | 306 virtual std::string GetOffTheRecordCommandLine( |
291 const GURL& start_url, | 307 const GURL& start_url, |
292 const CommandLine& base_command_line, | 308 const CommandLine& base_command_line, |
293 CommandLine *command_line); | 309 CommandLine *command_line); |
294 | 310 |
295 private: | 311 private: |
296 // Restarts OAuth session authentication check. | 312 // Restarts OAuth session authentication check. |
297 void KickStartAuthentication(Profile* profile); | 313 void KickStartAuthentication(Profile* profile); |
298 | 314 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 // Delegate to be fired when the profile will be prepared. | 363 // Delegate to be fired when the profile will be prepared. |
348 LoginUtils::Delegate* delegate_; | 364 LoginUtils::Delegate* delegate_; |
349 | 365 |
350 // Used to restart Chrome to switch to the guest mode. | 366 // Used to restart Chrome to switch to the guest mode. |
351 JobRestartRequest* job_restart_request_; | 367 JobRestartRequest* job_restart_request_; |
352 | 368 |
353 // True if should restore authentication session when notified about | 369 // True if should restore authentication session when notified about |
354 // online state change. | 370 // online state change. |
355 bool should_restore_auth_session_; | 371 bool should_restore_auth_session_; |
356 | 372 |
373 content::NotificationRegistrar registrar_; | |
374 | |
375 // This is set via a notification after the profile has initialized the | |
376 // getter. | |
377 net::URLRequestContextGetter* url_request_context_getter_; | |
378 | |
357 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); | 379 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
358 }; | 380 }; |
359 | 381 |
360 class LoginUtilsWrapper { | 382 class LoginUtilsWrapper { |
361 public: | 383 public: |
362 static LoginUtilsWrapper* GetInstance() { | 384 static LoginUtilsWrapper* GetInstance() { |
363 return Singleton<LoginUtilsWrapper>::get(); | 385 return Singleton<LoginUtilsWrapper>::get(); |
364 } | 386 } |
365 | 387 |
366 LoginUtils* get() { | 388 LoginUtils* get() { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 authenticator_ = NULL; | 877 authenticator_ = NULL; |
856 | 878 |
857 if (authenticator_ == NULL) | 879 if (authenticator_ == NULL) |
858 authenticator_ = new ParallelAuthenticator(consumer); | 880 authenticator_ = new ParallelAuthenticator(consumer); |
859 return authenticator_; | 881 return authenticator_; |
860 } | 882 } |
861 | 883 |
862 // We use a special class for this so that it can be safely leaked if we | 884 // We use a special class for this so that it can be safely leaked if we |
863 // never connect. At shutdown the order is not well defined, and it's possible | 885 // never connect. At shutdown the order is not well defined, and it's possible |
864 // for the infrastructure needed to unregister might be unstable and crash. | 886 // for the infrastructure needed to unregister might be unstable and crash. |
865 class WarmingObserver : public NetworkLibrary::NetworkManagerObserver { | 887 class WarmingObserver : public NetworkLibrary::NetworkManagerObserver, |
888 public content::NotificationObserver { | |
866 public: | 889 public: |
867 WarmingObserver() { | 890 WarmingObserver() |
891 : url_request_context_getter_(NULL) { | |
868 NetworkLibrary *netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 892 NetworkLibrary *netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
869 netlib->AddNetworkManagerObserver(this); | 893 netlib->AddNetworkManagerObserver(this); |
894 // During tests, the browser_process may not be initialized yet causing | |
895 // this to fail. | |
896 if (g_browser_process) { | |
897 registrar_.Add( | |
898 this, | |
899 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | |
900 content::Source<Profile>(ProfileManager::GetDefaultProfile())); | |
901 } | |
870 } | 902 } |
871 | 903 |
872 virtual ~WarmingObserver() {} | 904 virtual ~WarmingObserver() {} |
873 | 905 |
874 // If we're now connected, prewarm the auth url. | 906 // If we're now connected, prewarm the auth url. |
875 virtual void OnNetworkManagerChanged(NetworkLibrary* netlib) { | 907 virtual void OnNetworkManagerChanged(NetworkLibrary* netlib) { |
876 if (netlib->Connected()) { | 908 if (netlib->Connected()) { |
877 const int kConnectionsNeeded = 1; | 909 const int kConnectionsNeeded = 1; |
878 chrome_browser_net::PreconnectOnUIThread( | 910 chrome_browser_net::PreconnectOnUIThread( |
879 GURL(GaiaUrls::GetInstance()->client_login_url()), | 911 GURL(GaiaUrls::GetInstance()->client_login_url()), |
880 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, | 912 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
881 kConnectionsNeeded, | 913 kConnectionsNeeded, |
882 make_scoped_refptr(Profile::GetDefaultRequestContextDeprecated())); | 914 url_request_context_getter_); |
883 netlib->RemoveNetworkManagerObserver(this); | 915 netlib->RemoveNetworkManagerObserver(this); |
884 delete this; | 916 delete this; |
885 } | 917 } |
886 } | 918 } |
919 | |
920 // content::NotificationObserver overrides. | |
921 virtual void Observe(int type, | |
922 const content::NotificationSource& source, | |
923 const content::NotificationDetails& details) { | |
924 switch (type) { | |
925 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { | |
926 Profile* profile = content::Source<Profile>(source).ptr(); | |
927 url_request_context_getter_ = profile->GetRequestContext(); | |
928 registrar_.Remove( | |
929 this, | |
930 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | |
931 content::Source<Profile>(profile)); | |
932 | |
933 break; | |
934 } | |
935 default: | |
936 NOTREACHED(); | |
937 } | |
938 } | |
939 private: | |
940 net::URLRequestContextGetter* url_request_context_getter_; | |
941 content::NotificationRegistrar registrar_; | |
887 }; | 942 }; |
888 | 943 |
889 void LoginUtilsImpl::PrewarmAuthentication() { | 944 void LoginUtilsImpl::PrewarmAuthentication() { |
890 NetworkLibrary *network = CrosLibrary::Get()->GetNetworkLibrary(); | 945 NetworkLibrary *network = CrosLibrary::Get()->GetNetworkLibrary(); |
891 if (network->Connected()) { | 946 if (network->Connected()) { |
892 const int kConnectionsNeeded = 1; | 947 const int kConnectionsNeeded = 1; |
893 chrome_browser_net::PreconnectOnUIThread( | 948 chrome_browser_net::PreconnectOnUIThread( |
894 GURL(GaiaUrls::GetInstance()->client_login_url()), | 949 GURL(GaiaUrls::GetInstance()->client_login_url()), |
895 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, | 950 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
896 kConnectionsNeeded, | 951 kConnectionsNeeded, |
897 make_scoped_refptr(Profile::GetDefaultRequestContextDeprecated())); | 952 url_request_context_getter_); |
898 } else { | 953 } else { |
899 new WarmingObserver(); | 954 new WarmingObserver(); |
900 } | 955 } |
901 } | 956 } |
902 | 957 |
903 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { | 958 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { |
904 // We don't need to restore session for demo/guest users. | 959 // We don't need to restore session for demo/guest users. |
905 if (!UserManager::Get()->IsUserLoggedIn() || | 960 if (!UserManager::Get()->IsUserLoggedIn() || |
906 UserManager::Get()->IsLoggedInAsGuest() || | 961 UserManager::Get()->IsLoggedInAsGuest() || |
907 UserManager::Get()->IsLoggedInAsDemoUser()) { | 962 UserManager::Get()->IsLoggedInAsDemoUser()) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 // we need to kick off OAuth token verification process again. | 1156 // we need to kick off OAuth token verification process again. |
1102 oauth_login_verifier_->ContinueVerification(); | 1157 oauth_login_verifier_->ContinueVerification(); |
1103 } else if (should_restore_auth_session_) { | 1158 } else if (should_restore_auth_session_) { |
1104 should_restore_auth_session_ = false; | 1159 should_restore_auth_session_ = false; |
1105 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1160 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
1106 KickStartAuthentication(user_profile); | 1161 KickStartAuthentication(user_profile); |
1107 } | 1162 } |
1108 } | 1163 } |
1109 } | 1164 } |
1110 | 1165 |
1166 void LoginUtilsImpl::Observe(int type, | |
1167 const content::NotificationSource& source, | |
1168 const content::NotificationDetails& details) { | |
1169 switch (type) { | |
1170 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { | |
1171 Profile* profile = content::Source<Profile>(source).ptr(); | |
1172 url_request_context_getter_ = profile->GetRequestContext(); | |
1173 registrar_.Remove( | |
1174 this, | |
1175 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | |
1176 content::Source<Profile>(profile)); | |
1177 break; | |
1178 } | |
1179 default: | |
1180 NOTREACHED(); | |
1181 } | |
1182 } | |
1183 | |
1111 // static | 1184 // static |
1112 LoginUtils* LoginUtils::Get() { | 1185 LoginUtils* LoginUtils::Get() { |
1113 return LoginUtilsWrapper::GetInstance()->get(); | 1186 return LoginUtilsWrapper::GetInstance()->get(); |
1114 } | 1187 } |
1115 | 1188 |
1116 // static | 1189 // static |
1117 void LoginUtils::Set(LoginUtils* mock) { | 1190 void LoginUtils::Set(LoginUtils* mock) { |
1118 LoginUtilsWrapper::GetInstance()->reset(mock); | 1191 LoginUtilsWrapper::GetInstance()->reset(mock); |
1119 } | 1192 } |
1120 | 1193 |
1121 // static | 1194 // static |
1122 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1195 bool LoginUtils::IsWhitelisted(const std::string& username) { |
1123 CrosSettings* cros_settings = CrosSettings::Get(); | 1196 CrosSettings* cros_settings = CrosSettings::Get(); |
1124 bool allow_new_user = false; | 1197 bool allow_new_user = false; |
1125 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1198 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
1126 if (allow_new_user) | 1199 if (allow_new_user) |
1127 return true; | 1200 return true; |
1128 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1201 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
1129 } | 1202 } |
1130 | 1203 |
1131 } // namespace chromeos | 1204 } // namespace chromeos |
OLD | NEW |