| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/offline/offline_load_page.h" | 5 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 namespace chromeos { | 47 namespace chromeos { |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 void OfflineLoadPage::Show(int process_host_id, int render_view_id, | 50 void OfflineLoadPage::Show(int process_host_id, int render_view_id, |
| 51 const GURL& url, Delegate* delegate) { | 51 const GURL& url, Delegate* delegate) { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 53 if (NetworkStateNotifier::is_connected()) { | 53 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 54 // Check again in UI thread and proceed if it's connected. | 54 // Check again in UI thread and proceed if it's connected. |
| 55 delegate->OnBlockingPageComplete(true); | 55 delegate->OnBlockingPageComplete(true); |
| 56 } else { | 56 } else { |
| 57 TabContents* tab_contents = | 57 TabContents* tab_contents = |
| 58 tab_util::GetTabContentsByID(process_host_id, render_view_id); | 58 tab_util::GetTabContentsByID(process_host_id, render_view_id); |
| 59 // There is a chance that the tab is closed after we decided to show | 59 // There is a chance that the tab is closed after we decided to show |
| 60 // offline and before we actually show the offline page. | 60 // offline and before we actually show the offline page. |
| 61 if (!tab_contents) | 61 if (!tab_contents) |
| 62 return; | 62 return; |
| 63 (new OfflineLoadPage(tab_contents, url, delegate))->Show(); | 63 (new OfflineLoadPage(tab_contents, url, delegate))->Show(); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents, | 67 OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents, |
| 68 const GURL& url, | 68 const GURL& url, |
| 69 Delegate* delegate) | 69 Delegate* delegate) |
| 70 : ChromeInterstitialPage(tab_contents, true, url), | 70 : ChromeInterstitialPage(tab_contents, true, url), |
| 71 delegate_(delegate), | 71 delegate_(delegate), |
| 72 proceeded_(false), | 72 proceeded_(false), |
| 73 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 73 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 74 in_test_(false) { | 74 in_test_(false) { |
| 75 registrar_.Add(this, chrome::NOTIFICATION_NETWORK_STATE_CHANGED, | 75 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 76 NotificationService::AllSources()); | |
| 77 } | 76 } |
| 78 | 77 |
| 79 OfflineLoadPage::~OfflineLoadPage() {} | 78 OfflineLoadPage::~OfflineLoadPage() { |
| 79 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 80 } |
| 80 | 81 |
| 81 std::string OfflineLoadPage::GetHTMLContents() { | 82 std::string OfflineLoadPage::GetHTMLContents() { |
| 82 DictionaryValue strings; | 83 DictionaryValue strings; |
| 83 int64 time_to_wait = std::max( | 84 int64 time_to_wait = 0; // kMaxBlankPeriod |
| 84 static_cast<int64>(0), | |
| 85 kMaxBlankPeriod - | |
| 86 NetworkStateNotifier::GetOfflineDuration().InMilliseconds()); | |
| 87 // Set the timeout to show the page. | 85 // Set the timeout to show the page. |
| 88 strings.SetInteger("time_to_wait", static_cast<int>(time_to_wait)); | 86 strings.SetInteger("time_to_wait", static_cast<int>(time_to_wait)); |
| 89 // Button labels | 87 // Button labels |
| 90 SetString(&strings, "heading", IDS_OFFLINE_LOAD_HEADLINE); | 88 SetString(&strings, "heading", IDS_OFFLINE_LOAD_HEADLINE); |
| 91 SetString(&strings, "try_loading", IDS_OFFLINE_TRY_LOADING); | 89 SetString(&strings, "try_loading", IDS_OFFLINE_TRY_LOADING); |
| 92 SetString(&strings, "network_settings", IDS_OFFLINE_NETWORK_SETTINGS); | 90 SetString(&strings, "network_settings", IDS_OFFLINE_NETWORK_SETTINGS); |
| 93 | 91 |
| 94 // Activation | 92 // Activation |
| 95 strings.SetBoolean("show_activation", ShowActivationMessage()); | 93 strings.SetBoolean("show_activation", ShowActivationMessage()); |
| 96 | 94 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 190 } |
| 193 | 191 |
| 194 void OfflineLoadPage::DontProceed() { | 192 void OfflineLoadPage::DontProceed() { |
| 195 // Inogre if it's already proceeded. | 193 // Inogre if it's already proceeded. |
| 196 if (proceeded_) | 194 if (proceeded_) |
| 197 return; | 195 return; |
| 198 delegate_->OnBlockingPageComplete(false); | 196 delegate_->OnBlockingPageComplete(false); |
| 199 InterstitialPage::DontProceed(); | 197 InterstitialPage::DontProceed(); |
| 200 } | 198 } |
| 201 | 199 |
| 202 void OfflineLoadPage::Observe(int type, | 200 void OfflineLoadPage::OnOnlineStateChanged(bool online) { |
| 203 const NotificationSource& source, | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 204 const NotificationDetails& details) { | 202 DVLOG(1) << "OnlineStateObserver notification received: state=" |
| 205 if (type == chrome::NOTIFICATION_NETWORK_STATE_CHANGED) { | 203 << (online ? "online" : "offline"); |
| 206 chromeos::NetworkStateDetails* state_details = | 204 if (online) { |
| 207 Details<chromeos::NetworkStateDetails>(details).ptr(); | 205 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 208 DVLOG(1) << "NetworkStateChanaged notification received: state=" | 206 Proceed(); |
| 209 << state_details->state(); | |
| 210 if (state_details->state() == | |
| 211 chromeos::NetworkStateDetails::CONNECTED) { | |
| 212 registrar_.Remove(this, chrome::NOTIFICATION_NETWORK_STATE_CHANGED, | |
| 213 NotificationService::AllSources()); | |
| 214 Proceed(); | |
| 215 } | |
| 216 } else { | |
| 217 ChromeInterstitialPage::Observe(type, source, details); | |
| 218 } | 207 } |
| 219 } | 208 } |
| 220 | 209 |
| 221 bool OfflineLoadPage::ShowActivationMessage() { | 210 bool OfflineLoadPage::ShowActivationMessage() { |
| 222 CrosLibrary* cros = CrosLibrary::Get(); | 211 CrosLibrary* cros = CrosLibrary::Get(); |
| 223 if (!cros || !cros->GetNetworkLibrary()->cellular_available()) | 212 if (!cros || !cros->GetNetworkLibrary()->cellular_available()) |
| 224 return false; | 213 return false; |
| 225 | 214 |
| 226 const CellularNetworkVector& cell_networks = | 215 const CellularNetworkVector& cell_networks = |
| 227 cros->GetNetworkLibrary()->cellular_networks(); | 216 cros->GetNetworkLibrary()->cellular_networks(); |
| 228 for (size_t i = 0; i < cell_networks.size(); ++i) { | 217 for (size_t i = 0; i < cell_networks.size(); ++i) { |
| 229 chromeos::ActivationState activation_state = | 218 chromeos::ActivationState activation_state = |
| 230 cell_networks[i]->activation_state(); | 219 cell_networks[i]->activation_state(); |
| 231 if (activation_state == ACTIVATION_STATE_ACTIVATED) | 220 if (activation_state == ACTIVATION_STATE_ACTIVATED) |
| 232 return false; | 221 return false; |
| 233 } | 222 } |
| 234 return true; | 223 return true; |
| 235 } | 224 } |
| 236 | 225 |
| 237 } // namespace chromeos | 226 } // namespace chromeos |
| OLD | NEW |