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

Side by Side Diff: components/captive_portal/captive_portal_detector.cc

Issue 2906233005: Deprecate NonThreadSafe in components/captive_portal in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « components/captive_portal/captive_portal_detector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/captive_portal/captive_portal_detector.h" 5 #include "components/captive_portal/captive_portal_detector.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "components/data_use_measurement/core/data_use_user_data.h" 9 #include "components/data_use_measurement/core/data_use_user_data.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/http/http_response_headers.h" 11 #include "net/http/http_response_headers.h"
12 #include "net/http/http_util.h" 12 #include "net/http/http_util.h"
13 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
14 14
15 namespace captive_portal { 15 namespace captive_portal {
16 16
17 const char CaptivePortalDetector::kDefaultURL[] = 17 const char CaptivePortalDetector::kDefaultURL[] =
18 "http://www.gstatic.com/generate_204"; 18 "http://www.gstatic.com/generate_204";
19 19
20 CaptivePortalDetector::CaptivePortalDetector( 20 CaptivePortalDetector::CaptivePortalDetector(
21 const scoped_refptr<net::URLRequestContextGetter>& request_context) 21 const scoped_refptr<net::URLRequestContextGetter>& request_context)
22 : request_context_(request_context) { 22 : request_context_(request_context) {
23 } 23 }
24 24
25 CaptivePortalDetector::~CaptivePortalDetector() { 25 CaptivePortalDetector::~CaptivePortalDetector() {
26 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
26 } 27 }
27 28
28 void CaptivePortalDetector::DetectCaptivePortal( 29 void CaptivePortalDetector::DetectCaptivePortal(
29 const GURL& url, 30 const GURL& url,
30 const DetectionCallback& detection_callback, 31 const DetectionCallback& detection_callback,
31 const net::NetworkTrafficAnnotationTag& traffic_annotation) { 32 const net::NetworkTrafficAnnotationTag& traffic_annotation) {
32 DCHECK(CalledOnValidThread()); 33 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
33 DCHECK(!FetchingURL()); 34 DCHECK(!FetchingURL());
34 DCHECK(detection_callback_.is_null()); 35 DCHECK(detection_callback_.is_null());
35 36
36 detection_callback_ = detection_callback; 37 detection_callback_ = detection_callback;
37 38
38 // The first 0 means this can use a TestURLFetcherFactory in unit tests. 39 // The first 0 means this can use a TestURLFetcherFactory in unit tests.
39 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::GET, this, 40 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::GET, this,
40 traffic_annotation); 41 traffic_annotation);
41 url_fetcher_->SetAutomaticallyRetryOn5xx(false); 42 url_fetcher_->SetAutomaticallyRetryOn5xx(false);
42 url_fetcher_->SetRequestContext(request_context_.get()); 43 url_fetcher_->SetRequestContext(request_context_.get());
(...skipping 10 matching lines...) Expand all
53 net::LOAD_DO_NOT_SEND_AUTH_DATA); 54 net::LOAD_DO_NOT_SEND_AUTH_DATA);
54 url_fetcher_->Start(); 55 url_fetcher_->Start();
55 } 56 }
56 57
57 void CaptivePortalDetector::Cancel() { 58 void CaptivePortalDetector::Cancel() {
58 url_fetcher_.reset(); 59 url_fetcher_.reset();
59 detection_callback_.Reset(); 60 detection_callback_.Reset();
60 } 61 }
61 62
62 void CaptivePortalDetector::OnURLFetchComplete(const net::URLFetcher* source) { 63 void CaptivePortalDetector::OnURLFetchComplete(const net::URLFetcher* source) {
63 DCHECK(CalledOnValidThread()); 64 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
64 DCHECK(FetchingURL()); 65 DCHECK(FetchingURL());
65 DCHECK_EQ(url_fetcher_.get(), source); 66 DCHECK_EQ(url_fetcher_.get(), source);
66 DCHECK(!detection_callback_.is_null()); 67 DCHECK(!detection_callback_.is_null());
67 68
68 Results results; 69 Results results;
69 GetCaptivePortalResultFromResponse(url_fetcher_.get(), &results); 70 GetCaptivePortalResultFromResponse(url_fetcher_.get(), &results);
70 DetectionCallback callback = detection_callback_; 71 DetectionCallback callback = detection_callback_;
71 url_fetcher_.reset(); 72 url_fetcher_.reset();
72 detection_callback_.Reset(); 73 detection_callback_.Reset();
73 callback.Run(results); 74 callback.Run(results);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return base::Time::Now(); 144 return base::Time::Now();
144 else 145 else
145 return time_for_testing_; 146 return time_for_testing_;
146 } 147 }
147 148
148 bool CaptivePortalDetector::FetchingURL() const { 149 bool CaptivePortalDetector::FetchingURL() const {
149 return url_fetcher_.get() != NULL; 150 return url_fetcher_.get() != NULL;
150 } 151 }
151 152
152 } // namespace captive_portal 153 } // namespace captive_portal
OLDNEW
« no previous file with comments | « components/captive_portal/captive_portal_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698