Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "remoting/host/dns_blackhole_checker.h" | 5 #include "remoting/host/dns_blackhole_checker.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | |
| 7 #include "net/url_request/url_fetcher.h" | 8 #include "net/url_request/url_fetcher.h" |
| 8 #include "net/url_request/url_request_context_getter.h" | 9 #include "net/url_request/url_request_context_getter.h" |
| 9 #include "remoting/base/logging.h" | 10 #include "remoting/base/logging.h" |
| 10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 11 | 12 |
| 12 namespace remoting { | 13 namespace remoting { |
| 13 | 14 |
| 14 // Default prefix added to the base talkgadget URL. | 15 // Default prefix added to the base talkgadget URL. |
| 15 const char kDefaultHostTalkGadgetPrefix[] = "chromoting-host"; | 16 const char kDefaultHostTalkGadgetPrefix[] = "chromoting-host"; |
| 16 | 17 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 33 void DnsBlackholeChecker::OnURLFetchComplete(const net::URLFetcher* source) { | 34 void DnsBlackholeChecker::OnURLFetchComplete(const net::URLFetcher* source) { |
| 34 int response = source->GetResponseCode(); | 35 int response = source->GetResponseCode(); |
| 35 bool allow = false; | 36 bool allow = false; |
| 36 if (source->GetResponseCode() == 200) { | 37 if (source->GetResponseCode() == 200) { |
| 37 HOST_LOG << "Successfully connected to host talkgadget."; | 38 HOST_LOG << "Successfully connected to host talkgadget."; |
| 38 allow = true; | 39 allow = true; |
| 39 } else { | 40 } else { |
| 40 HOST_LOG << "Unable to connect to host talkgadget (" << response << ")"; | 41 HOST_LOG << "Unable to connect to host talkgadget (" << response << ")"; |
| 41 } | 42 } |
| 42 url_fetcher_.reset(nullptr); | 43 url_fetcher_.reset(nullptr); |
| 43 callback_.Run(allow); | 44 |
|
Wez
2015/04/24 23:02:31
nit: No need for this blank line
Sergey Ulanov
2015/04/24 23:30:00
Done.
| |
| 44 callback_.Reset(); | 45 base::ResetAndReturn(&callback_).Run(allow); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DnsBlackholeChecker::CheckForDnsBlackhole( | 48 void DnsBlackholeChecker::CheckForDnsBlackhole( |
| 48 const base::Callback<void(bool)>& callback) { | 49 const base::Callback<void(bool)>& callback) { |
| 49 // Make sure we're not currently in the middle of a connection check. | 50 // Make sure we're not currently in the middle of a connection check. |
| 50 if (!url_fetcher_.get()) { | 51 if (!url_fetcher_.get()) { |
| 51 DCHECK(callback_.is_null()); | 52 DCHECK(callback_.is_null()); |
| 52 callback_ = callback; | 53 callback_ = callback; |
| 53 std::string talkgadget_url("https://"); | 54 std::string talkgadget_url("https://"); |
| 54 if (talkgadget_prefix_.empty()) { | 55 if (talkgadget_prefix_.empty()) { |
| 55 talkgadget_url += kDefaultHostTalkGadgetPrefix; | 56 talkgadget_url += kDefaultHostTalkGadgetPrefix; |
| 56 } else { | 57 } else { |
| 57 talkgadget_url += talkgadget_prefix_; | 58 talkgadget_url += talkgadget_prefix_; |
| 58 } | 59 } |
| 59 talkgadget_url += kTalkGadgetUrl; | 60 talkgadget_url += kTalkGadgetUrl; |
| 60 HOST_LOG << "Verifying connection to " << talkgadget_url; | 61 HOST_LOG << "Verifying connection to " << talkgadget_url; |
| 61 url_fetcher_.reset(net::URLFetcher::Create(GURL(talkgadget_url), | 62 url_fetcher_.reset(net::URLFetcher::Create(GURL(talkgadget_url), |
| 62 net::URLFetcher::GET, this)); | 63 net::URLFetcher::GET, this)); |
| 63 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); | 64 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
| 64 url_fetcher_->Start(); | 65 url_fetcher_->Start(); |
| 65 } else { | 66 } else { |
| 66 HOST_LOG << "Pending connection check"; | 67 HOST_LOG << "Pending connection check"; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 } // namespace remoting | 71 } // namespace remoting |
| OLD | NEW |