Chromium Code Reviews| Index: mojo/services/launcher/launcher.cc |
| diff --git a/mojo/services/launcher/launcher.cc b/mojo/services/launcher/launcher.cc |
| index f9fc881c807a1b0186447a9c7f400aa379e59aee..5cabeb02b5490a009f8b6f7b175fdf7be9cce9cd 100644 |
| --- a/mojo/services/launcher/launcher.cc |
| +++ b/mojo/services/launcher/launcher.cc |
| @@ -2,6 +2,7 @@ |
| // 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" |
| @@ -42,7 +43,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,18 +51,7 @@ 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) { |
| @@ -154,31 +144,31 @@ 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()) { |
|
Aaron Boodman
2014/07/10 20:05:00
Maybe print out an error or something for now?
|
| + 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 |