| 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/login/auth_prewarmer.h" | 5 #include "chrome/browser/chromeos/login/auth_prewarmer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 #include "chrome/browser/net/chrome_url_request_context.h" | 9 #include "chrome/browser/net/chrome_url_request_context.h" |
| 11 #include "chrome/browser/net/preconnect.h" | 10 #include "chrome/browser/net/preconnect.h" |
| 11 #include "chromeos/network/network_handler.h" |
| 12 #include "chromeos/network/network_state_handler.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 | 18 |
| 18 AuthPrewarmer::AuthPrewarmer() | 19 AuthPrewarmer::AuthPrewarmer() |
| 19 : doing_prewarm_(false) { | 20 : doing_prewarm_(false) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 AuthPrewarmer::~AuthPrewarmer() { | 23 AuthPrewarmer::~AuthPrewarmer() { |
| 23 if (registrar_.IsRegistered( | 24 if (registrar_.IsRegistered( |
| 24 this, | 25 this, |
| 25 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 26 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 26 content::Source<Profile>(ProfileHelper::GetSigninProfile()))) { | 27 content::Source<Profile>(ProfileHelper::GetSigninProfile()))) { |
| 27 registrar_.Remove( | 28 registrar_.Remove( |
| 28 this, | 29 this, |
| 29 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 30 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 30 content::Source<Profile>(ProfileHelper::GetSigninProfile())); | 31 content::Source<Profile>(ProfileHelper::GetSigninProfile())); |
| 31 } | 32 } |
| 32 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this); | 33 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 34 FROM_HERE); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void AuthPrewarmer::PrewarmAuthentication( | 37 void AuthPrewarmer::PrewarmAuthentication( |
| 36 const base::Closure& completion_callback) { | 38 const base::Closure& completion_callback) { |
| 37 if (doing_prewarm_) { | 39 if (doing_prewarm_) { |
| 38 LOG(ERROR) << "PrewarmAuthentication called twice."; | 40 LOG(ERROR) << "PrewarmAuthentication called twice."; |
| 39 return; | 41 return; |
| 40 } | 42 } |
| 41 doing_prewarm_ = true; | 43 doing_prewarm_ = true; |
| 42 completion_callback_ = completion_callback; | 44 completion_callback_ = completion_callback; |
| 43 if (GetRequestContext() && IsNetworkConnected()) { | 45 if (GetRequestContext() && IsNetworkConnected()) { |
| 44 DoPrewarm(); | 46 DoPrewarm(); |
| 45 return; | 47 return; |
| 46 } | 48 } |
| 47 if (!IsNetworkConnected()) | 49 if (!IsNetworkConnected()) |
| 48 ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this); | 50 NetworkHandler::Get()->network_state_handler()->AddObserver(this, |
| 51 FROM_HERE); |
| 49 if (!GetRequestContext()) { | 52 if (!GetRequestContext()) { |
| 50 registrar_.Add( | 53 registrar_.Add( |
| 51 this, | 54 this, |
| 52 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 55 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 53 content::Source<Profile>(ProfileHelper::GetSigninProfile())); | 56 content::Source<Profile>(ProfileHelper::GetSigninProfile())); |
| 54 } | 57 } |
| 55 } | 58 } |
| 56 | 59 |
| 57 void AuthPrewarmer::NetworkManagerChanged() { | 60 void AuthPrewarmer::NetworkManagerChanged() { |
| 58 if (IsNetworkConnected()) { | 61 if (IsNetworkConnected()) { |
| 59 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this); | 62 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 63 FROM_HERE); |
| 60 if (GetRequestContext()) | 64 if (GetRequestContext()) |
| 61 DoPrewarm(); | 65 DoPrewarm(); |
| 62 } | 66 } |
| 63 } | 67 } |
| 64 | 68 |
| 65 void AuthPrewarmer::DefaultNetworkChanged() { | 69 void AuthPrewarmer::DefaultNetworkChanged() { |
| 66 NetworkManagerChanged(); | 70 NetworkManagerChanged(); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void AuthPrewarmer::Observe(int type, | 73 void AuthPrewarmer::Observe(int type, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 99 GetRequestContext()); | 103 GetRequestContext()); |
| 100 } | 104 } |
| 101 if (!completion_callback_.is_null()) { | 105 if (!completion_callback_.is_null()) { |
| 102 content::BrowserThread::PostTask(content::BrowserThread::UI, | 106 content::BrowserThread::PostTask(content::BrowserThread::UI, |
| 103 FROM_HERE, | 107 FROM_HERE, |
| 104 completion_callback_); | 108 completion_callback_); |
| 105 } | 109 } |
| 106 } | 110 } |
| 107 | 111 |
| 108 bool AuthPrewarmer::IsNetworkConnected() const { | 112 bool AuthPrewarmer::IsNetworkConnected() const { |
| 109 return ConnectivityStateHelper::Get()->IsConnected(); | 113 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
| 114 return (nsh->ConnectedNetworkByType(NetworkStateHandler::kMatchTypeDefault) != |
| 115 NULL); |
| 110 } | 116 } |
| 111 | 117 |
| 112 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { | 118 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { |
| 113 return ProfileHelper::GetSigninProfile()->GetRequestContext(); | 119 return ProfileHelper::GetSigninProfile()->GetRequestContext(); |
| 114 } | 120 } |
| 115 | 121 |
| 116 } // namespace chromeos | 122 } // namespace chromeos |
| 117 | 123 |
| OLD | NEW |