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

Unified Diff: content/renderer/p2p/host_address_request.cc

Issue 7599003: Add IPC for DNS host address resolution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 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
« no previous file with comments | « content/renderer/p2p/host_address_request.h ('k') | content/renderer/p2p/socket_dispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/p2p/host_address_request.cc
diff --git a/content/renderer/p2p/host_address_request.cc b/content/renderer/p2p/host_address_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1db935a594b7be2f93b66c716aff8705e83b08b0
--- /dev/null
+++ b/content/renderer/p2p/host_address_request.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2011 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 "content/renderer/p2p/host_address_request.h"
+
+#include "base/bind.h"
+#include "base/message_loop_proxy.h"
+#include "content/common/p2p_messages.h"
+#include "content/renderer/p2p/socket_dispatcher.h"
+
+P2PHostAddressRequest::P2PHostAddressRequest(P2PSocketDispatcher* dispatcher)
+ : dispatcher_(dispatcher),
+ ipc_message_loop_(dispatcher->message_loop()),
+ delegate_message_loop_(base::MessageLoopProxy::CreateForCurrentThread()),
+ state_(STATE_CREATED),
+ request_id_(0),
+ registered_(false) {
+}
+
+P2PHostAddressRequest::~P2PHostAddressRequest() {
+ DCHECK(state_ == STATE_CREATED || state_ == STATE_FINISHED);
+}
+
+void P2PHostAddressRequest::Request(const std::string& host_name,
+ const DoneCallback& done_callback) {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
+
+ state_ = STATE_SENT;
+ ipc_message_loop_->PostTask(FROM_HERE, base::Bind(
+ &P2PHostAddressRequest::DoSendRequest, this, host_name, done_callback));
+}
+
+void P2PHostAddressRequest::Cancel() {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
+
+ if (state_ != STATE_FINISHED) {
+ state_ = STATE_FINISHED;
+ ipc_message_loop_->PostTask(FROM_HERE, base::Bind(
+ &P2PHostAddressRequest::DoUnregister, this));
+ }
+}
+
+void P2PHostAddressRequest::DoSendRequest(const std::string& host_name,
+ const DoneCallback& done_callback) {
+ DCHECK(ipc_message_loop_->BelongsToCurrentThread());
+
+ done_callback_ = done_callback;
+ request_id_ = dispatcher_->RegisterHostAddressRequest(this);
+ registered_ = true;
+ dispatcher_->SendP2PMessage(
+ new P2PHostMsg_GetHostAddress(0, host_name, request_id_));
+}
+
+void P2PHostAddressRequest::DoUnregister() {
+ DCHECK(ipc_message_loop_->BelongsToCurrentThread());
+ if (registered_) {
+ dispatcher_->UnregisterHostAddressRequest(request_id_);
+ registered_ = false;
+ }
+}
+
+void P2PHostAddressRequest::OnResponse(const net::IPAddressNumber& address) {
+ DCHECK(ipc_message_loop_->BelongsToCurrentThread());
+ delegate_message_loop_->PostTask(FROM_HERE, base::Bind(
+ &P2PHostAddressRequest::DeliverResponse, this, address));
+ dispatcher_->UnregisterHostAddressRequest(request_id_);
+ registered_ = false;
+}
+
+void P2PHostAddressRequest::DeliverResponse(
+ const net::IPAddressNumber& address) {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
+ if (state_ == STATE_SENT) {
+ done_callback_.Run(address);
+ state_ = STATE_FINISHED;
+ }
+}
« no previous file with comments | « content/renderer/p2p/host_address_request.h ('k') | content/renderer/p2p/socket_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698