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

Unified Diff: mojo/application_manager/application_manager.cc

Issue 696563002: Cache ShellImpl by resolved URL, not initial URL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cleanup Created 6 years, 2 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
Index: mojo/application_manager/application_manager.cc
diff --git a/mojo/application_manager/application_manager.cc b/mojo/application_manager/application_manager.cc
index 75ef7a76694b24773a65b38e644d83bd901d1ce9..11b8fbb4fca715ae096eac2fd8447d14024b488a 100644
--- a/mojo/application_manager/application_manager.cc
+++ b/mojo/application_manager/application_manager.cc
@@ -35,17 +35,30 @@ class StubServiceProvider : public InterfaceImpl<ServiceProvider> {
} // namespace
-ApplicationManager::Delegate::~Delegate() {}
+
+ApplicationManager::Delegate::~Delegate() {
+}
+
+void ApplicationManager::Delegate::OnApplicationError(const GURL& url) {
+ LOG(ERROR) << "Communication error with application: " << url.spec();
+}
+
+GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) {
+ return url;
+}
+
class ApplicationManager::LoadCallbacksImpl
: public ApplicationLoader::LoadCallbacks {
public:
LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager,
const GURL& requested_url,
+ const GURL& resolved_url,
const GURL& requestor_url,
ServiceProviderPtr service_provider)
: manager_(manager),
requested_url_(requested_url),
+ resolved_url_(resolved_url),
requestor_url_(requestor_url),
service_provider_(service_provider.Pass()) {}
@@ -57,6 +70,7 @@ class ApplicationManager::LoadCallbacksImpl
ScopedMessagePipeHandle shell_handle;
if (manager_) {
manager_->RegisterLoadedApplication(requested_url_,
+ resolved_url_,
requestor_url_,
service_provider_.Pass(),
&shell_handle);
@@ -77,14 +91,16 @@ class ApplicationManager::LoadCallbacksImpl
base::WeakPtr<ApplicationManager> manager_;
GURL requested_url_;
+ GURL resolved_url_;
GURL requestor_url_;
ServiceProviderPtr service_provider_;
};
class ApplicationManager::ShellImpl : public InterfaceImpl<Shell> {
public:
- ShellImpl(ApplicationManager* manager, const GURL& url)
- : manager_(manager), url_(url) {}
+ ShellImpl(ApplicationManager* manager, const GURL& requested_url,
DaveMoore 2014/10/31 16:15:58 Nit: could you put these on their own lines?
Aaron Boodman 2014/10/31 18:14:02 Done.
+ const GURL& url)
+ : manager_(manager), requested_url_(requested_url), url_(url) {}
~ShellImpl() override {}
@@ -105,11 +121,13 @@ class ApplicationManager::ShellImpl : public InterfaceImpl<Shell> {
}
const GURL& url() const { return url_; }
+ const GURL& requested_url() const { return requested_url_; }
private:
void OnConnectionError() override { manager_->OnShellImplError(this); }
ApplicationManager* const manager_;
+ const GURL requested_url_;
const GURL url_;
DISALLOW_COPY_AND_ASSIGN(ShellImpl);
@@ -146,8 +164,8 @@ bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
manager_->url_to_shell_impl_.end();
}
-ApplicationManager::ApplicationManager()
- : delegate_(NULL),
+ApplicationManager::ApplicationManager(Delegate* delegate)
+ : delegate_(delegate),
interceptor_(NULL),
weak_ptr_factory_(this) {
}
@@ -163,31 +181,27 @@ void ApplicationManager::TerminateShellConnections() {
STLDeleteValues(&url_to_shell_impl_);
}
-// static
-ApplicationManager* ApplicationManager::GetInstance() {
- static base::LazyInstance<ApplicationManager> instance =
- LAZY_INSTANCE_INITIALIZER;
- has_created_instance = true;
- return &instance.Get();
-}
-
void ApplicationManager::ConnectToApplication(
- const GURL& url,
+ const GURL& requested_url,
const GURL& requestor_url,
ServiceProviderPtr service_provider) {
- URLToShellImplMap::const_iterator shell_it = url_to_shell_impl_.find(url);
+ GURL resolved_url = delegate_->ResolveURL(requested_url);
+
+ URLToShellImplMap::const_iterator shell_it =
+ url_to_shell_impl_.find(resolved_url);
if (shell_it != url_to_shell_impl_.end()) {
- ConnectToClient(
- shell_it->second, url, requestor_url, service_provider.Pass());
+ ConnectToClient(shell_it->second, resolved_url, requestor_url,
+ service_provider.Pass());
return;
}
scoped_refptr<LoadCallbacksImpl> callbacks(
new LoadCallbacksImpl(weak_ptr_factory_.GetWeakPtr(),
- url,
+ requested_url,
+ resolved_url,
requestor_url,
service_provider.Pass()));
- GetLoaderForURL(url)->Load(this, url, callbacks);
+ GetLoaderForURL(resolved_url)->Load(this, resolved_url, callbacks);
}
void ApplicationManager::ConnectToClient(ShellImpl* shell_impl,
@@ -207,16 +221,17 @@ void ApplicationManager::RegisterExternalApplication(
const GURL& url,
ScopedMessagePipeHandle shell_handle) {
url_to_shell_impl_[url] =
- WeakBindToPipe(new ShellImpl(this, url), shell_handle.Pass());
+ WeakBindToPipe(new ShellImpl(this, url, url), shell_handle.Pass());
}
void ApplicationManager::RegisterLoadedApplication(
- const GURL& url,
+ const GURL& requested_url,
+ const GURL& resolved_url,
const GURL& requestor_url,
ServiceProviderPtr service_provider,
ScopedMessagePipeHandle* shell_handle) {
ShellImpl* shell_impl = NULL;
- URLToShellImplMap::iterator iter = url_to_shell_impl_.find(url);
+ URLToShellImplMap::iterator iter = url_to_shell_impl_.find(resolved_url);
if (iter != url_to_shell_impl_.end()) {
// This can happen because services are loaded asynchronously. So if we get
// two requests for the same service close to each other, we might get here
@@ -224,17 +239,19 @@ void ApplicationManager::RegisterLoadedApplication(
shell_impl = iter->second;
} else {
MessagePipe pipe;
- URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
+ URLToArgsMap::const_iterator args_it = url_to_args_.find(resolved_url);
Array<String> args;
if (args_it != url_to_args_.end())
args = Array<String>::From(args_it->second);
- shell_impl = WeakBindToPipe(new ShellImpl(this, url), pipe.handle1.Pass());
- url_to_shell_impl_[url] = shell_impl;
+ shell_impl = WeakBindToPipe(
+ new ShellImpl(this, requested_url, resolved_url), pipe.handle1.Pass());
+ url_to_shell_impl_[resolved_url] = shell_impl;
*shell_handle = pipe.handle0.Pass();
shell_impl->client()->Initialize(args.Pass());
}
- ConnectToClient(shell_impl, url, requestor_url, service_provider.Pass());
+ ConnectToClient(shell_impl, resolved_url, requestor_url,
+ service_provider.Pass());
}
void ApplicationManager::LoadWithContentHandler(
@@ -299,15 +316,15 @@ ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) {
// Called from ~ShellImpl, so we do not need to call Destroy here.
const GURL url = shell_impl->url();
+ const GURL requested_url = shell_impl->requested_url();
URLToShellImplMap::iterator it = url_to_shell_impl_.find(url);
DCHECK(it != url_to_shell_impl_.end());
delete it->second;
url_to_shell_impl_.erase(it);
- ApplicationLoader* loader = GetLoaderForURL(url);
+ ApplicationLoader* loader = GetLoaderForURL(requested_url);
if (loader)
loader->OnApplicationError(this, url);
- if (delegate_)
- delegate_->OnApplicationError(url);
+ delegate_->OnApplicationError(requested_url);
}
ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(

Powered by Google App Engine
This is Rietveld 408576698