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