OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/net/network_portal_detector_impl.h" | 5 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chromeos/dbus/shill_stub_helper.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_profile_client.h" |
14 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
15 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 using captive_portal::CaptivePortalDetector; | 23 using captive_portal::CaptivePortalDetector; |
23 | 24 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 captive_portal_detector_->Cancel(); | 356 captive_portal_detector_->Cancel(); |
356 detection_timeout_.Cancel(); | 357 detection_timeout_.Cancel(); |
357 state_ = STATE_IDLE; | 358 state_ = STATE_IDLE; |
358 } | 359 } |
359 | 360 |
360 void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( | 361 void NetworkPortalDetectorImpl::OnPortalDetectionCompleted( |
361 const CaptivePortalDetector::Results& results) { | 362 const CaptivePortalDetector::Results& results) { |
362 captive_portal::Result result = results.result; | 363 captive_portal::Result result = results.result; |
363 int response_code = results.response_code; | 364 int response_code = results.response_code; |
364 | 365 |
365 if (shill_stub_helper::IsStubPortalledWifiEnabled(default_service_path_)) { | |
366 result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL; | |
367 response_code = 200; | |
368 } | |
369 | |
370 DCHECK(CalledOnValidThread()); | 366 DCHECK(CalledOnValidThread()); |
371 DCHECK(IsCheckingForPortal()); | 367 DCHECK(IsCheckingForPortal()); |
372 | 368 |
373 VLOG(1) << "Portal detection completed: " | 369 VLOG(1) << "Portal detection completed: " |
374 << "name=" << default_network_name_ << ", " | 370 << "name=" << default_network_name_ << ", " |
375 << "id=" << default_network_id_ << ", " | 371 << "id=" << default_network_id_ << ", " |
376 << "result=" | 372 << "result=" |
377 << CaptivePortalDetector::CaptivePortalResultToString(results.result) | 373 << CaptivePortalDetector::CaptivePortalResultToString(results.result) |
378 << ", " | 374 << ", " |
379 << "response_code=" << results.response_code; | 375 << "response_code=" << results.response_code; |
380 | 376 |
381 state_ = STATE_IDLE; | 377 state_ = STATE_IDLE; |
382 detection_timeout_.Cancel(); | 378 detection_timeout_.Cancel(); |
383 | 379 |
384 const NetworkState* default_network = | 380 const NetworkState* default_network = |
385 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 381 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
386 | 382 |
| 383 // If using a fake profile client, also fake being behind a captive portal |
| 384 // if the default network is in portal state. |
| 385 if (result != captive_portal::RESULT_NO_RESPONSE && |
| 386 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface() && |
| 387 default_network && |
| 388 default_network->connection_state() == shill::kStatePortal) { |
| 389 result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL; |
| 390 response_code = 200; |
| 391 } |
| 392 |
387 CaptivePortalState state; | 393 CaptivePortalState state; |
388 state.response_code = response_code; | 394 state.response_code = response_code; |
389 switch (result) { | 395 switch (result) { |
390 case captive_portal::RESULT_NO_RESPONSE: | 396 case captive_portal::RESULT_NO_RESPONSE: |
391 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { | 397 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { |
392 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; | 398 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; |
393 SetCaptivePortalState(default_network, state); | 399 SetCaptivePortalState(default_network, state); |
394 } else if (attempt_count_ >= kMaxRequestAttempts) { | 400 } else if (attempt_count_ >= kMaxRequestAttempts) { |
395 if (default_network && | 401 if (default_network && |
396 (default_network->connection_state() == shill::kStatePortal)) { | 402 (default_network->connection_state() == shill::kStatePortal)) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 if (network->connection_state() != shill::kStateOnline) | 556 if (network->connection_state() != shill::kStateOnline) |
551 RecordDiscrepancyWithShill(network, status); | 557 RecordDiscrepancyWithShill(network, status); |
552 break; | 558 break; |
553 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: | 559 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: |
554 NOTREACHED(); | 560 NOTREACHED(); |
555 break; | 561 break; |
556 } | 562 } |
557 } | 563 } |
558 | 564 |
559 } // namespace chromeos | 565 } // namespace chromeos |
OLD | NEW |