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

Side by Side Diff: remoting/host/connection_block_checker.cc

Issue 10873050: [Chromoting] Hook up host talkgadget policy checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup logging Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "remoting/host/connection_block_checker.h"
6
7 #include "googleurl/src/gurl.h"
8 #include "net/url_request/url_fetcher.h"
9 #include "remoting/host/chromoting_host_context.h"
10 #include "remoting/host/constants.h"
11
12 namespace remoting {
13
14 const int kMaxConnectionBlockChecks = 5;
15
16 ConnectionBlockChecker::ConnectionBlockChecker(
17 ChromotingHostContext* context,
18 std::string talkgadget_prefix,
19 const base::Callback<void(bool)>& callback)
20 : context_(context),
21 talkgadget_prefix_(talkgadget_prefix),
22 callback_(callback) {
23 }
24
25 ConnectionBlockChecker::~ConnectionBlockChecker() {
26 }
27
28 // This is called in response to the TalkGadget http request initiated from
29 // CheckStatus().
30 void ConnectionBlockChecker::OnURLFetchComplete(const net::URLFetcher* source) {
31 int response = source->GetResponseCode();
32 int allow = false;
33 if (source->GetResponseCode() == 200) {
34 LOG(INFO) << "Successfully connected to host talkgadget.";
35 allow = true;
36 } else {
37 LOG(INFO) << "Unable to connect to host talkgadget (" << response << ")";
38 }
39 url_fetcher_.reset(NULL);
40 callback_.Run(allow);
41 }
42
43 void ConnectionBlockChecker::CheckStatus() {
44 // Make sure we're not currently in the middle of a connection check.
45 if (!url_fetcher_.get()) {
46 std::string talkgadget_url("https://");
47 if (talkgadget_prefix_.empty()) {
48 talkgadget_url += kDefaultHostTalkGadgetPrefix;
49 } else {
50 talkgadget_url += talkgadget_prefix_;
51 }
52 talkgadget_url += kTalkGadgetUrl;
53 LOG(INFO) << "Verifying connection to " << talkgadget_url;
54 url_fetcher_.reset(net::URLFetcher::Create(GURL(talkgadget_url),
55 net::URLFetcher::GET, this));
56 url_fetcher_->SetRequestContext(context_->url_request_context_getter());
57 url_fetcher_->Start();
58 } else {
59 LOG(INFO) << "Pending connection check";
Sergey Ulanov 2012/08/29 20:10:29 I think it's better to DCHECK(!url_fetcher_.get())
garykac 2012/08/29 22:30:51 A DCHECK for this is wrong since CheckStatus can p
60 }
61 }
62
63 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698