Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_impl.cc

Issue 1346843003: Refactor NetworkPortalDetector and NetworkPortalNotificationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stub Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/shill_profile_client.h" 18 #include "chromeos/dbus/shill_profile_client.h"
18 #include "chromeos/login/login_state.h" 19 #include "chromeos/login/login_state.h"
19 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 21 #include "chromeos/network/network_state_handler.h"
22 #include "chromeos/network/portal_detector/network_portal_detector_stub.h"
21 #include "components/device_event_log/device_event_log.h" 23 #include "components/device_event_log/device_event_log.h"
22 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
23 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
24 #include "net/http/http_status_code.h" 26 #include "net/http/http_status_code.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 27 #include "third_party/cros_system_api/dbus/service_constants.h"
26 28
27 using base::StringPrintf; 29 using base::StringPrintf;
28 using captive_portal::CaptivePortalDetector; 30 using captive_portal::CaptivePortalDetector;
29 31
30 namespace chromeos { 32 namespace chromeos {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const char NetworkPortalDetectorImpl::kSessionShillPortalHistogram[] = 204 const char NetworkPortalDetectorImpl::kSessionShillPortalHistogram[] =
203 "CaptivePortal.Session.DiscrepancyWithShill_RestrictedPool"; 205 "CaptivePortal.Session.DiscrepancyWithShill_RestrictedPool";
204 const char NetworkPortalDetectorImpl::kSessionShillOfflineHistogram[] = 206 const char NetworkPortalDetectorImpl::kSessionShillOfflineHistogram[] =
205 "CaptivePortal.Session.DiscrepancyWithShill_Offline"; 207 "CaptivePortal.Session.DiscrepancyWithShill_Offline";
206 const char NetworkPortalDetectorImpl::kSessionPortalToOnlineHistogram[] = 208 const char NetworkPortalDetectorImpl::kSessionPortalToOnlineHistogram[] =
207 "CaptivePortal.Session.PortalToOnlineTransition"; 209 "CaptivePortal.Session.PortalToOnlineTransition";
208 210
209 // static 211 // static
210 void NetworkPortalDetectorImpl::Initialize( 212 void NetworkPortalDetectorImpl::Initialize(
211 net::URLRequestContextGetter* url_context) { 213 net::URLRequestContextGetter* url_context) {
212 if (NetworkPortalDetector::set_for_testing()) 214 if (set_for_testing())
213 return; 215 return;
214 CHECK(!NetworkPortalDetector::network_portal_detector()) 216 CHECK(!network_portal_detector())
215 << "NetworkPortalDetector was initialized twice."; 217 << "NetworkPortalDetector was initialized twice.";
216 NET_LOG(EVENT) << "NetworkPortalDetectorImpl::Initialize()"; 218 NET_LOG(EVENT) << "NetworkPortalDetectorImpl::Initialize";
217 if (base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType)) 219 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
218 set_network_portal_detector(new NetworkPortalDetectorStubImpl()); 220 ::switches::kTestType)) {
219 else 221 set_network_portal_detector(new NetworkPortalDetectorStub());
220 set_network_portal_detector(new NetworkPortalDetectorImpl(url_context)); 222 } else {
223 set_network_portal_detector(
224 new NetworkPortalDetectorImpl(url_context, true));
225 }
221 } 226 }
222 227
223 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( 228 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl(
224 const scoped_refptr<net::URLRequestContextGetter>& request_context) 229 const scoped_refptr<net::URLRequestContextGetter>& request_context,
225 : state_(STATE_IDLE), 230 bool create_notification_controller)
226 test_url_(CaptivePortalDetector::kDefaultURL), 231 : test_url_(CaptivePortalDetector::kDefaultURL),
227 enabled_(false),
228 strategy_(PortalDetectorStrategy::CreateById( 232 strategy_(PortalDetectorStrategy::CreateById(
229 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN, 233 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN,
230 this)), 234 this)),
231 last_detection_result_(CAPTIVE_PORTAL_STATUS_UNKNOWN),
232 same_detection_result_count_(0),
233 no_response_result_count_(0),
234 weak_factory_(this) { 235 weak_factory_(this) {
235 NET_LOG(EVENT) << "NetworkPortalDetectorImpl::NetworkPortalDetectorImpl()"; 236 NET_LOG(EVENT) << "NetworkPortalDetectorImpl::NetworkPortalDetectorImpl()";
236 captive_portal_detector_.reset(new CaptivePortalDetector(request_context)); 237 captive_portal_detector_.reset(new CaptivePortalDetector(request_context));
237 238
238 notification_controller_.set_retry_detection_callback(base::Bind( 239 if (create_notification_controller) {
239 &NetworkPortalDetectorImpl::RetryDetection, base::Unretained(this))); 240 notification_controller_.reset(
241 new NetworkPortalNotificationController(this));
242 notification_controller_->set_retry_detection_callback(
243 base::Bind(&NetworkPortalDetectorImpl::RetryDetection,
244 weak_factory_.GetWeakPtr()));
245 }
240 246
241 registrar_.Add(this, 247 registrar_.Add(this,
242 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, 248 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED,
243 content::NotificationService::AllSources()); 249 content::NotificationService::AllSources());
244 registrar_.Add(this, 250 registrar_.Add(this,
245 chrome::NOTIFICATION_AUTH_SUPPLIED, 251 chrome::NOTIFICATION_AUTH_SUPPLIED,
246 content::NotificationService::AllSources()); 252 content::NotificationService::AllSources());
247 registrar_.Add(this, 253 registrar_.Add(this,
248 chrome::NOTIFICATION_AUTH_CANCELLED, 254 chrome::NOTIFICATION_AUTH_CANCELLED,
249 content::NotificationService::AllSources()); 255 content::NotificationService::AllSources());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 void NetworkPortalDetectorImpl::SetStrategy( 336 void NetworkPortalDetectorImpl::SetStrategy(
331 PortalDetectorStrategy::StrategyId id) { 337 PortalDetectorStrategy::StrategyId id) {
332 if (id == strategy_->Id()) 338 if (id == strategy_->Id())
333 return; 339 return;
334 strategy_ = PortalDetectorStrategy::CreateById(id, this).Pass(); 340 strategy_ = PortalDetectorStrategy::CreateById(id, this).Pass();
335 StopDetection(); 341 StopDetection();
336 StartDetectionIfIdle(); 342 StartDetectionIfIdle();
337 } 343 }
338 344
339 void NetworkPortalDetectorImpl::OnLockScreenRequest() { 345 void NetworkPortalDetectorImpl::OnLockScreenRequest() {
340 notification_controller_.CloseDialog(); 346 if (notification_controller_)
347 notification_controller_->CloseDialog();
341 } 348 }
342 349
343 void NetworkPortalDetectorImpl::DefaultNetworkChanged( 350 void NetworkPortalDetectorImpl::DefaultNetworkChanged(
344 const NetworkState* default_network) { 351 const NetworkState* default_network) {
345 DCHECK(CalledOnValidThread()); 352 DCHECK(CalledOnValidThread());
346 353
347 notification_controller_.DefaultNetworkChanged(default_network);
348 if (!default_network) { 354 if (!default_network) {
349 NET_LOG(EVENT) << "Default network changed: None"; 355 NET_LOG(EVENT) << "Default network changed: None";
350 356
351 default_network_name_.clear(); 357 default_network_name_.clear();
352 358
353 StopDetection(); 359 StopDetection();
354 360
355 CaptivePortalState state; 361 CaptivePortalState state;
356 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE; 362 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE;
357 OnDetectionCompleted(NULL, state); 363 OnDetectionCompleted(nullptr, state);
358 return; 364 return;
359 } 365 }
360 366
361 default_network_name_ = default_network->name(); 367 default_network_name_ = default_network->name();
362 368
363 bool network_changed = (default_network_id_ != default_network->guid()); 369 bool network_changed = (default_network_id_ != default_network->guid());
364 default_network_id_ = default_network->guid(); 370 default_network_id_ = default_network->guid();
365 371
366 bool connection_state_changed = 372 bool connection_state_changed =
367 (default_connection_state_ != default_network->connection_state()); 373 (default_connection_state_ != default_network->connection_state());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 portal_state_map_[network->guid()] = state; 607 portal_state_map_[network->guid()] = state;
602 } 608 }
603 NotifyDetectionCompleted(network, state); 609 NotifyDetectionCompleted(network, state);
604 } 610 }
605 611
606 void NetworkPortalDetectorImpl::NotifyDetectionCompleted( 612 void NetworkPortalDetectorImpl::NotifyDetectionCompleted(
607 const NetworkState* network, 613 const NetworkState* network,
608 const CaptivePortalState& state) { 614 const CaptivePortalState& state) {
609 FOR_EACH_OBSERVER( 615 FOR_EACH_OBSERVER(
610 Observer, observers_, OnPortalDetectionCompleted(network, state)); 616 Observer, observers_, OnPortalDetectionCompleted(network, state));
611 notification_controller_.OnPortalDetectionCompleted(network, state);
612 } 617 }
613 618
614 bool NetworkPortalDetectorImpl::AttemptTimeoutIsCancelledForTesting() const { 619 bool NetworkPortalDetectorImpl::AttemptTimeoutIsCancelledForTesting() const {
615 return attempt_timeout_.IsCancelled(); 620 return attempt_timeout_.IsCancelled();
616 } 621 }
617 622
618 void NetworkPortalDetectorImpl::RecordDetectionStats( 623 void NetworkPortalDetectorImpl::RecordDetectionStats(
619 const NetworkState* network, 624 const NetworkState* network,
620 CaptivePortalStatus status) { 625 CaptivePortalStatus status) {
621 // Don't record stats for offline state. 626 // Don't record stats for offline state.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 658 }
654 659
655 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { 660 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() {
656 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; 661 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN;
657 same_detection_result_count_ = 0; 662 same_detection_result_count_ = 0;
658 no_response_result_count_ = 0; 663 no_response_result_count_ = 0;
659 strategy_->Reset(); 664 strategy_->Reset();
660 } 665 }
661 666
662 } // namespace chromeos 667 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698