Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / chromeos / net / delay_network_call.cc
blob76768ebf4a9bfd60958a5407647023d680202802
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/net/delay_network_call.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "chromeos/network/network_handler.h"
10 #include "chromeos/network/network_state.h"
11 #include "chromeos/network/network_state_handler.h"
12 #include "chromeos/network/portal_detector/network_portal_detector.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
16 const unsigned chromeos::kDefaultNetworkRetryDelayMS = 3000;
18 void chromeos::DelayNetworkCall(base::TimeDelta retry,
19 const base::Closure& callback) {
20 bool delay_network_call = false;
21 const NetworkState* default_network =
22 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
23 if (!default_network) {
24 delay_network_call = true;
25 DVLOG(1) << "DelayNetworkCall: No default network.";
26 } else {
27 std:: string default_connection_state = default_network->connection_state();
28 if (!NetworkState::StateIsConnected(default_connection_state)) {
29 delay_network_call = true;
30 DVLOG(1) << "DelayNetworkCall: "
31 << "Default network: " << default_network->name()
32 << " State: " << default_connection_state;
35 if (!delay_network_call && NetworkPortalDetector::IsInitialized()) {
36 NetworkPortalDetector* detector = NetworkPortalDetector::Get();
37 NetworkPortalDetector::CaptivePortalStatus status =
38 detector->GetCaptivePortalState(default_network->guid()).status;
39 if (status != NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) {
40 delay_network_call = true;
41 DVLOG(1) << "DelayNetworkCall: Captive portal status for "
42 << default_network->name() << ": "
43 << NetworkPortalDetector::CaptivePortalStatusString(status);
46 if (delay_network_call) {
47 content::BrowserThread::PostDelayedTask(
48 content::BrowserThread::UI, FROM_HERE,
49 base::Bind(&chromeos::DelayNetworkCall, retry, callback), retry);
50 } else {
51 callback.Run();