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

Unified 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: Remove extra comments/whitespace Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/connection_block_checker.cc
diff --git a/remoting/host/connection_block_checker.cc b/remoting/host/connection_block_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c4e76aa920b566d8354bb5a7357ceda1a4a9c68
--- /dev/null
+++ b/remoting/host/connection_block_checker.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/connection_block_checker.h"
+
+#include "googleurl/src/gurl.h"
+#include "net/url_request/url_fetcher.h"
+#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/constants.h"
+
+namespace remoting {
+
+const int kMaxConnectionBlockChecks = 5;
+
+ConnectionBlockChecker::ConnectionBlockChecker(
+ ChromotingHostContext* context,
+ std::string talkgadget_prefix)
+ : context_(context),
+ talkgadget_prefix_(talkgadget_prefix),
+ status_(UNKNOWN),
+ check_pending_(false),
+ reconnect_attempts_(0) {
+}
+
+// This is called in response to the TalkGadget http request initiated from
+// GetStatus().
+void ConnectionBlockChecker::OnURLFetchComplete(const net::URLFetcher* source) {
+ check_pending_ = false;
+ int response = source->GetResponseCode();
+ if (response == 200) {
+ LOG(INFO) << "Successfully connected to talkgadget.";
+ status_ = ALLOW;
+ url_fetcher_.reset(NULL);
+ return;
+ }
+ if (response == 404 || reconnect_attempts_ > kMaxConnectionBlockChecks) {
Sergey Ulanov 2012/08/28 00:33:42 We may get 404 if there is a misbehaving proxy, so
garykac 2012/08/29 00:07:15 Done.
+ LOG(INFO) << "Unable to connect to talkgadget.";
+ status_ = DENY;
+ } else {
+ LOG(INFO) << "Failed to find talkgadget. Retrying...";
+ reconnect_attempts_++;
+ status_ = UNKNOWN;
+ }
+}
+
+ConnectionBlockChecker::Status ConnectionBlockChecker::GetStatus() {
Sergey Ulanov 2012/08/28 00:33:42 Here we check connection status only once when thi
garykac 2012/08/29 00:07:15 Done.
+ if (status_ == UNKNOWN && !check_pending_) {
+ std::string talkgadget_url("https://");
+ if (talkgadget_prefix_.empty()) {
+ talkgadget_url += kDefaultHostTalkGadgetPrefix;
+ } else {
+ talkgadget_url += talkgadget_prefix_;
+ }
+ talkgadget_url += kTalkGadgetUrl;
+ LOG(INFO) << "Verifying connection to " << talkgadget_url;
+ url_fetcher_.reset(net::URLFetcher::Create(GURL(talkgadget_url),
+ net::URLFetcher::GET, this));
+ url_fetcher_->SetRequestContext(context_->url_request_context_getter());
+ url_fetcher_->Start();
+ }
+ return status_;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698