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

Unified Diff: mojo/services/launcher/launcher.cc

Issue 373373002: Mojo: Refactor URLLoader interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes per review Created 6 years, 5 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 | « mojo/examples/wget/wget.cc ('k') | mojo/services/network/url_loader_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/launcher/launcher.cc
diff --git a/mojo/services/launcher/launcher.cc b/mojo/services/launcher/launcher.cc
index f9fc881c807a1b0186447a9c7f400aa379e59aee..97a29c3f137042e25ecae8f3c119266cd3ba12b6 100644
--- a/mojo/services/launcher/launcher.cc
+++ b/mojo/services/launcher/launcher.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_tokenizer.h"
+#include "base/strings/string_util.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
@@ -42,7 +44,7 @@ class LauncherConnection : public InterfaceImpl<Launcher> {
DISALLOW_COPY_AND_ASSIGN(LauncherConnection);
};
-class LaunchInstance : public URLLoaderClient {
+class LaunchInstance {
public:
LaunchInstance(LauncherApp* app,
const LaunchCallback& callback,
@@ -50,24 +52,14 @@ class LaunchInstance : public URLLoaderClient {
virtual ~LaunchInstance() {}
private:
- // Overridden from URLLoaderClient:
- virtual void OnReceivedRedirect(URLResponsePtr response,
- const String& new_url,
- const String& new_method) OVERRIDE {
- }
- virtual void OnReceivedResponse(URLResponsePtr response) OVERRIDE;
- virtual void OnReceivedError(NetworkErrorPtr error) OVERRIDE {
- ScheduleDestroy();
- }
- virtual void OnReceivedEndOfResponseBody() OVERRIDE {
- ScheduleDestroy();
- }
+ void OnReceivedResponse(URLResponsePtr response);
std::string GetContentType(const Array<String>& headers) {
for (size_t i = 0; i < headers.size(); ++i) {
base::StringTokenizer t(headers[i], ": ;=");
while (t.GetNext()) {
- if (!t.token_is_delim() && t.token() == "Content-Type") {
+ if (!t.token_is_delim() &&
+ LowerCaseEqualsASCII(t.token(), "content-type")) {
while (t.GetNext()) {
if (!t.token_is_delim())
return t.token();
@@ -154,31 +146,33 @@ LaunchInstance::LaunchInstance(LauncherApp* app,
: app_(app),
destroy_scheduled_(false),
callback_(callback) {
- url_loader_ = app_->CreateURLLoader();
- url_loader_.set_client(this);
-
URLRequestPtr request(URLRequest::New());
request->url = url;
request->method = "GET";
request->auto_follow_redirects = true;
- DataPipe data_pipe;
- response_body_stream_ = data_pipe.consumer_handle.Pass();
-
- url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass());
+ url_loader_ = app_->CreateURLLoader();
+ url_loader_->Start(request.Pass(),
+ base::Bind(&LaunchInstance::OnReceivedResponse,
+ base::Unretained(this)));
}
void LaunchInstance::OnReceivedResponse(URLResponsePtr response) {
- std::string content_type = GetContentType(response->headers);
- std::string handler_url = app_->GetHandlerForContentType(content_type);
- if (!handler_url.empty()) {
- navigation::ResponseDetailsPtr nav_response(
- navigation::ResponseDetails::New());
- nav_response->response = response.Pass();
- nav_response->response_body_stream = response_body_stream_.Pass();
- String response_url = nav_response->response->url;
- callback_.Run(handler_url, response_url, nav_response.Pass());
+ if (!response->error) {
+ std::string content_type = GetContentType(response->headers);
+ std::string handler_url = app_->GetHandlerForContentType(content_type);
+ if (handler_url.empty()) {
+ DLOG(WARNING) << "No handler for content type: " << content_type;
+ } else {
+ navigation::ResponseDetailsPtr nav_response(
+ navigation::ResponseDetails::New());
+ nav_response->loader_handle = url_loader_.PassMessagePipe();
+ nav_response->response = response.Pass();
+ String response_url = nav_response->response->url;
+ callback_.Run(handler_url, response_url, nav_response.Pass());
+ }
}
+ ScheduleDestroy();
}
} // namespace launcher
« no previous file with comments | « mojo/examples/wget/wget.cc ('k') | mojo/services/network/url_loader_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698