Chromium Code Reviews| Index: chrome/browser/chromeos/login/login_utils.cc |
| =================================================================== |
| --- chrome/browser/chromeos/login/login_utils.cc (revision 145957) |
| +++ chrome/browser/chromeos/login/login_utils.cc (working copy) |
| @@ -72,6 +72,7 @@ |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/session_manager_client.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_service.h" |
| #include "googleurl/src/gurl.h" |
| #include "media/base/media_switches.h" |
| @@ -226,6 +227,7 @@ |
| public OAuth1TokenFetcher::Delegate, |
| public OAuthLoginVerifier::Delegate, |
| public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| + public content::NotificationObserver, |
| public base::SupportsWeakPtr<LoginUtilsImpl> { |
| public: |
| LoginUtilsImpl() |
| @@ -234,8 +236,17 @@ |
| has_cookies_(false), |
| delegate_(NULL), |
| job_restart_request_(NULL), |
| - should_restore_auth_session_(false) { |
| + should_restore_auth_session_(false), |
| + url_request_context_getter_(NULL) { |
| net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| + // During tests, the browser_process may not be initialized yet causing |
| + // this to fail. |
| + if (g_browser_process) { |
|
Nikita (slow)
2012/07/13 12:08:12
What were those tests when this failed?
|
| + registrar_.Add( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| + content::Source<Profile>(ProfileManager::GetDefaultProfile())); |
| + } |
| } |
| virtual ~LoginUtilsImpl() { |
| @@ -286,6 +297,11 @@ |
| virtual void OnConnectionTypeChanged( |
| net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| + // content::NotificationObserver overrides. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| protected: |
| virtual std::string GetOffTheRecordCommandLine( |
| const GURL& start_url, |
| @@ -354,6 +370,12 @@ |
| // online state change. |
| bool should_restore_auth_session_; |
| + content::NotificationRegistrar registrar_; |
| + |
| + // This is set via a notification after the profile has initialized the |
| + // getter. |
| + net::URLRequestContextGetter* url_request_context_getter_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
| }; |
| @@ -862,11 +884,21 @@ |
| // We use a special class for this so that it can be safely leaked if we |
| // never connect. At shutdown the order is not well defined, and it's possible |
| // for the infrastructure needed to unregister might be unstable and crash. |
| -class WarmingObserver : public NetworkLibrary::NetworkManagerObserver { |
| +class WarmingObserver : public NetworkLibrary::NetworkManagerObserver, |
| + public content::NotificationObserver { |
| public: |
| - WarmingObserver() { |
| + WarmingObserver() |
| + : url_request_context_getter_(NULL) { |
| NetworkLibrary *netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
| netlib->AddNetworkManagerObserver(this); |
| + // During tests, the browser_process may not be initialized yet causing |
| + // this to fail. |
| + if (g_browser_process) { |
| + registrar_.Add( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| + content::Source<Profile>(ProfileManager::GetDefaultProfile())); |
| + } |
| } |
| virtual ~WarmingObserver() {} |
| @@ -879,11 +911,34 @@ |
| GURL(GaiaUrls::GetInstance()->client_login_url()), |
| chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
| kConnectionsNeeded, |
| - make_scoped_refptr(Profile::GetDefaultRequestContextDeprecated())); |
| + url_request_context_getter_); |
| netlib->RemoveNetworkManagerObserver(this); |
| delete this; |
| } |
| } |
| + |
| + // content::NotificationObserver overrides. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + url_request_context_getter_ = profile->GetRequestContext(); |
| + registrar_.Remove( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| + content::Source<Profile>(profile)); |
| + |
| + break; |
| + } |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + private: |
| + net::URLRequestContextGetter* url_request_context_getter_; |
| + content::NotificationRegistrar registrar_; |
| }; |
| void LoginUtilsImpl::PrewarmAuthentication() { |
| @@ -894,7 +949,7 @@ |
| GURL(GaiaUrls::GetInstance()->client_login_url()), |
| chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
| kConnectionsNeeded, |
| - make_scoped_refptr(Profile::GetDefaultRequestContextDeprecated())); |
| + url_request_context_getter_); |
| } else { |
| new WarmingObserver(); |
| } |
| @@ -1108,6 +1163,24 @@ |
| } |
| } |
| +void LoginUtilsImpl::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + url_request_context_getter_ = profile->GetRequestContext(); |
| + registrar_.Remove( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| + content::Source<Profile>(profile)); |
| + break; |
| + } |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| // static |
| LoginUtils* LoginUtils::Get() { |
| return LoginUtilsWrapper::GetInstance()->get(); |