Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / dns_blackhole_checker.cc
blob1f71ad5200b1265440409b7cb427f6faa543821b
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
3 // found in the LICENSE file.
5 #include "remoting/host/dns_blackhole_checker.h"
7 #include "base/callback_helpers.h"
8 #include "net/url_request/url_fetcher.h"
9 #include "net/url_request/url_request_context_getter.h"
10 #include "remoting/base/logging.h"
11 #include "url/gurl.h"
13 namespace remoting {
15 // Default prefix added to the base talkgadget URL.
16 const char kDefaultHostTalkGadgetPrefix[] = "chromoting-host";
18 // The base talkgadget URL.
19 const char kTalkGadgetUrl[] = ".talkgadget.google.com/talkgadget/"
20 "oauth/chrome-remote-desktop-host";
22 DnsBlackholeChecker::DnsBlackholeChecker(
23 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
24 std::string talkgadget_prefix)
25 : url_request_context_getter_(request_context_getter),
26 talkgadget_prefix_(talkgadget_prefix) {
29 DnsBlackholeChecker::~DnsBlackholeChecker() {
32 // This is called in response to the TalkGadget http request initiated from
33 // CheckStatus().
34 void DnsBlackholeChecker::OnURLFetchComplete(const net::URLFetcher* source) {
35 int response = source->GetResponseCode();
36 bool allow = false;
37 if (source->GetResponseCode() == 200) {
38 HOST_LOG << "Successfully connected to host talkgadget.";
39 allow = true;
40 } else {
41 HOST_LOG << "Unable to connect to host talkgadget (" << response << ")";
43 url_fetcher_.reset(nullptr);
44 base::ResetAndReturn(&callback_).Run(allow);
47 void DnsBlackholeChecker::CheckForDnsBlackhole(
48 const base::Callback<void(bool)>& callback) {
49 // Make sure we're not currently in the middle of a connection check.
50 if (!url_fetcher_.get()) {
51 DCHECK(callback_.is_null());
52 callback_ = callback;
53 std::string talkgadget_url("https://");
54 if (talkgadget_prefix_.empty()) {
55 talkgadget_url += kDefaultHostTalkGadgetPrefix;
56 } else {
57 talkgadget_url += talkgadget_prefix_;
59 talkgadget_url += kTalkGadgetUrl;
60 HOST_LOG << "Verifying connection to " << talkgadget_url;
61 url_fetcher_ = net::URLFetcher::Create(GURL(talkgadget_url),
62 net::URLFetcher::GET, this);
63 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
64 url_fetcher_->Start();
65 } else {
66 HOST_LOG << "Pending connection check";
70 } // namespace remoting