Commit 54efb235 authored by aa's avatar aa Committed by Commit bot

Mojo: Fix two bugs in content handling

1. URLLoaders can't be reused, so we need to construct one
   per-load. This became too gnarly to handle with callbacks
   so I put it back to having a loader object that owns the
   URLLoader.

2. The relevant URLLoader needs to be passed to
   ContentHandler::OnConnect() so that it stays alive long
   enough to read the entire response.

BUG=

Review URL: https://codereview.chromium.org/513573002

Cr-Commit-Position: refs/heads/master@{#292460}
parent 82e8b989
......@@ -23,7 +23,7 @@ ApplicationLoader::SimpleLoadCallbacks::RegisterApplication() {
void ApplicationLoader::SimpleLoadCallbacks::LoadWithContentHandler(
const GURL& content_handle_url,
URLResponsePtr content) {
URLResponsePtr url_response) {
NOTREACHED();
}
......
......@@ -34,7 +34,7 @@ class MOJO_APPLICATION_MANAGER_EXPORT ApplicationLoader {
// Load the requested application with a content handler.
virtual void LoadWithContentHandler(const GURL& content_handler_url,
URLResponsePtr response) = 0;
URLResponsePtr url_response) = 0;
protected:
friend base::RefCounted<LoadCallbacks>;
......
......@@ -66,12 +66,12 @@ class ApplicationManager::LoadCallbacksImpl
}
virtual void LoadWithContentHandler(const GURL& content_handler_url,
URLResponsePtr content) OVERRIDE {
URLResponsePtr url_response) OVERRIDE {
if (manager_) {
manager_->LoadWithContentHandler(requested_url_,
requestor_url_,
content_handler_url,
content.Pass(),
url_response.Pass(),
service_provider_.Pass());
}
}
......@@ -232,7 +232,7 @@ void ApplicationManager::LoadWithContentHandler(
const GURL& content_url,
const GURL& requestor_url,
const GURL& content_handler_url,
URLResponsePtr content,
URLResponsePtr url_response,
ServiceProviderPtr service_provider) {
ContentHandlerConnection* connection = NULL;
URLToContentHandlerMap::iterator iter =
......@@ -243,8 +243,11 @@ void ApplicationManager::LoadWithContentHandler(
connection = new ContentHandlerConnection(this, content_handler_url);
url_to_content_handler_[content_handler_url] = connection;
}
InterfaceRequest<ServiceProvider> spir;
spir.Bind(service_provider.PassMessagePipe());
connection->content_handler->OnConnect(
content_url.spec(), content.Pass(), service_provider.Pass());
content_url.spec(), url_response.Pass(), spir.Pass());
}
void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
......
......@@ -123,7 +123,7 @@ class MOJO_APPLICATION_MANAGER_EXPORT ApplicationManager {
void LoadWithContentHandler(const GURL& content_url,
const GURL& requestor_url,
const GURL& content_handler_url,
URLResponsePtr content,
URLResponsePtr url_response,
ServiceProviderPtr service_provider);
// Returns the Loader to use for a url (using default if not overridden.)
......
......@@ -23,8 +23,9 @@ class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
private:
virtual void OnConnect(const mojo::String& url,
URLResponsePtr content,
ServiceProviderPtr service_provider) MOJO_OVERRIDE;
URLResponsePtr response,
InterfaceRequest<ServiceProvider> service_provider)
MOJO_OVERRIDE;
ContentHandlerApp* content_handler_app_;
};
......@@ -71,12 +72,13 @@ class ContentHandlerApp : public ApplicationDelegate {
ContentHandlerApp> content_handler_factory_;
};
void ContentHandlerImpl::OnConnect(const mojo::String& url,
URLResponsePtr content,
ServiceProviderPtr service_provider) {
void ContentHandlerImpl::OnConnect(
const mojo::String& url,
URLResponsePtr response,
InterfaceRequest<ServiceProvider> service_provider) {
printf("ContentHandler::OnConnect - url:%s - body follows\n\n",
url.To<std::string>().c_str());
content_handler_app_->PrintResponse(content->body.Pass());
content_handler_app_->PrintResponse(response->body.Pass());
}
} // namespace examples
......
......@@ -8,9 +8,9 @@ import "mojo/services/public/interfaces/network/url_loader.mojom"
module mojo {
interface ContentHandler {
OnConnect(string? url,
URLResponse? url_response,
ServiceProvider? service_provider);
OnConnect(string url,
URLResponse response,
ServiceProvider&? service_provider);
};
}
This diff is collapsed.
......@@ -7,6 +7,7 @@
#include <map>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
......@@ -44,28 +45,21 @@ class DynamicApplicationLoader : public ApplicationLoader {
const GURL& url) OVERRIDE;
private:
class Loader;
class LocalLoader;
class NetworkLoader;
typedef std::map<std::string, GURL> MimeTypeToURLMap;
typedef base::Callback<void(Loader*)> LoaderCompleteCallback;
void LoadLocalService(const GURL& resolved_url,
scoped_refptr<LoadCallbacks> callbacks);
void LoadNetworkService(const GURL& resolved_url,
scoped_refptr<LoadCallbacks> callbacks);
void OnLoadNetworkServiceComplete(scoped_refptr<LoadCallbacks> callbacks,
URLResponsePtr url_response);
void RunLibrary(const base::FilePath& response_file,
scoped_refptr<LoadCallbacks> callbacks,
bool delete_file_after,
bool response_path_exists);
void OnRunLibraryComplete(DynamicServiceRunner* runner,
const base::FilePath& temp_file);
void LoaderComplete(Loader* loader);
Context* const context_;
scoped_ptr<DynamicServiceRunnerFactory> runner_factory_;
ScopedVector<DynamicServiceRunner> runners_;
NetworkServicePtr network_service_;
URLLoaderPtr url_loader_;
MimeTypeToURLMap mime_type_to_url_;
base::WeakPtrFactory<DynamicApplicationLoader> weak_ptr_factory_;
ScopedVector<Loader> loaders_;
LoaderCompleteCallback loader_complete_callback_;
DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment