| 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/profiles/profile_helper.h" | 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 9 #include "chrome/browser/net/chrome_url_request_context.h" | 9 #include "chrome/browser/net/chrome_url_request_context.h" |
| 10 #include "chrome/browser/net/preconnect.h" | 10 #include "chrome/browser/net/preconnect.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 if (doing_prewarm_) { | 41 if (doing_prewarm_) { |
| 42 LOG(ERROR) << "PrewarmAuthentication called twice."; | 42 LOG(ERROR) << "PrewarmAuthentication called twice."; |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 doing_prewarm_ = true; | 45 doing_prewarm_ = true; |
| 46 completion_callback_ = completion_callback; | 46 completion_callback_ = completion_callback; |
| 47 if (GetRequestContext() && IsNetworkConnected()) { | 47 if (GetRequestContext() && IsNetworkConnected()) { |
| 48 DoPrewarm(); | 48 DoPrewarm(); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 if (!IsNetworkConnected()) | 51 if (!IsNetworkConnected()) { |
| 52 NetworkHandler::Get()->network_state_handler()->AddObserver(this, | 52 // DefaultNetworkChanged will get called when a network becomes connected. |
| 53 FROM_HERE); | 53 NetworkHandler::Get()->network_state_handler() |
| 54 ->AddObserver(this, FROM_HERE); |
| 55 } |
| 54 if (!GetRequestContext()) { | 56 if (!GetRequestContext()) { |
| 55 registrar_.Add( | 57 registrar_.Add( |
| 56 this, | 58 this, |
| 57 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 59 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 58 content::Source<Profile>(ProfileHelper::GetSigninProfile())); | 60 content::Source<Profile>(ProfileHelper::GetSigninProfile())); |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 void AuthPrewarmer::NetworkManagerChanged() { | |
| 63 if (IsNetworkConnected()) { | |
| 64 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | |
| 65 FROM_HERE); | |
| 66 if (GetRequestContext()) | |
| 67 DoPrewarm(); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 void AuthPrewarmer::DefaultNetworkChanged(const NetworkState* network) { | 64 void AuthPrewarmer::DefaultNetworkChanged(const NetworkState* network) { |
| 72 NetworkManagerChanged(); | 65 if (!network) |
| 66 return; // Still no default (connected) network. |
| 67 |
| 68 NetworkHandler::Get()->network_state_handler() |
| 69 ->RemoveObserver(this, FROM_HERE); |
| 70 if (GetRequestContext()) |
| 71 DoPrewarm(); |
| 73 } | 72 } |
| 74 | 73 |
| 75 void AuthPrewarmer::Observe(int type, | 74 void AuthPrewarmer::Observe(int type, |
| 76 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
| 77 const content::NotificationDetails& details) { | 76 const content::NotificationDetails& details) { |
| 78 switch (type) { | 77 switch (type) { |
| 79 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: | 78 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: |
| 80 registrar_.Remove( | 79 registrar_.Remove( |
| 81 this, | 80 this, |
| 82 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 81 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool AuthPrewarmer::IsNetworkConnected() const { | 113 bool AuthPrewarmer::IsNetworkConnected() const { |
| 115 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); | 114 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
| 116 return (nsh->ConnectedNetworkByType(NetworkTypePattern::Default()) != NULL); | 115 return (nsh->ConnectedNetworkByType(NetworkTypePattern::Default()) != NULL); |
| 117 } | 116 } |
| 118 | 117 |
| 119 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { | 118 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { |
| 120 return ProfileHelper::GetSigninProfile()->GetRequestContext(); | 119 return ProfileHelper::GetSigninProfile()->GetRequestContext(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 } // namespace chromeos | 122 } // namespace chromeos |
| 124 | |
| OLD | NEW |