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

Unified Diff: chrome/browser/devtools/protocol_http_request.cc

Issue 12559008: DevTools: add backend for discovering connected ADB devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Offline review comments addressed Created 7 years, 9 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 | « chrome/browser/devtools/protocol_http_request.h ('k') | chrome/browser/resources/inspect/inspect.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/protocol_http_request.cc
diff --git a/chrome/browser/devtools/protocol_http_request.cc b/chrome/browser/devtools/protocol_http_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5dcf1d8afc5a59a9a081d86d7c0e036b76a401ba
--- /dev/null
+++ b/chrome/browser/devtools/protocol_http_request.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2013 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 "chrome/browser/devtools/protocol_http_request.h"
+
+#include "base/threading/thread.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/base/io_buffer.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context_getter.h"
+
+using content::BrowserThread;
+
+namespace {
+
+const int kBufferSize = 16 * 1024;
+
+} // namespace
+
+ProtocolHttpRequest::ProtocolHttpRequest(
+ Profile* profile,
+ const std::string& url,
+ const Callback& callback)
+ : request_context_(profile->GetRequestContext()),
+ url_(url),
+ callback_(callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (!url_.is_valid()) {
+ error_ = "Invalid URL: " + url_.possibly_invalid_spec();
+ RespondOnUIThread();
+ return;
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ProtocolHttpRequest::Start, base::Unretained(this)));
+}
+
+ProtocolHttpRequest::~ProtocolHttpRequest() {
+}
+
+void ProtocolHttpRequest::Start() {
+ request_ = new net::URLRequest(url_, this,
+ request_context_->GetURLRequestContext());
+ io_buffer_ = new net::IOBuffer(kBufferSize);
+ request_->Start();
+}
+
+void ProtocolHttpRequest::OnResponseStarted(net::URLRequest* request) {
+ if (!request->status().is_success())
+ error_ = "HTTP 404";
+ int bytes_read = 0;
+ if (request->status().is_success())
+ request->Read(io_buffer_.get(), kBufferSize, &bytes_read);
+ OnReadCompleted(request, bytes_read);
+}
+
+void ProtocolHttpRequest::OnReadCompleted(net::URLRequest* request,
+ int bytes_read) {
+ do {
+ if (!request->status().is_success() || bytes_read <= 0)
+ break;
+ data_ += std::string(io_buffer_->data(), bytes_read);
+ } while (request->Read(io_buffer_, kBufferSize, &bytes_read));
+
+ if (!request->status().is_io_pending()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ProtocolHttpRequest::RespondOnUIThread,
+ base::Unretained(this)));
+ delete request;
+ }
+}
+
+void ProtocolHttpRequest::RespondOnUIThread() {
+ callback_.Run(error_, data_);
+ delete this;
+}
« no previous file with comments | « chrome/browser/devtools/protocol_http_request.h ('k') | chrome/browser/resources/inspect/inspect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698