ApplicationManager: Use callback to get notified on application shutdown.
Until now, the Delegate had a OnApplicationError that was called
whenever an application ended. Because it was used to keep track of when
a given started application ended, it needed to send back the URL that
was used to start an application. This was cumbersome as mapping and
rediect change the url during the loading process.
Instead this change allows a caller fo ApplicationManager to register a
closure that will be called when the application ends, if the call
started a new application.
R=davemoore@chromium.org
Review URL: https://codereview.chromium.org/983113002
diff --git a/shell/application_manager/application_manager_unittest.cc b/shell/application_manager/application_manager_unittest.cc
index 19edcff..2e7c279 100644
--- a/shell/application_manager/application_manager_unittest.cc
+++ b/shell/application_manager/application_manager_unittest.cc
@@ -33,6 +33,11 @@
int num_loader_deletes;
};
+void QuitClosure(bool* value) {
+ *value = true;
+ base::MessageLoop::current()->QuitWhenIdle();
+}
+
class QuitMessageLoopErrorHandler : public ErrorHandler {
public:
QuitMessageLoopErrorHandler() {}
@@ -137,6 +142,13 @@
DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
};
+class ClosingApplicationLoader : public ApplicationLoader {
+ private:
+ // ApplicationLoader implementation.
+ void Load(const GURL& url,
+ InterfaceRequest<Application> application_request) override {}
+};
+
class TesterContext {
public:
explicit TesterContext(base::MessageLoop* loop)
@@ -403,8 +415,6 @@
return mapped_url;
}
- void OnApplicationError(const GURL& url) override {}
-
private:
std::map<GURL, GURL> mappings_;
};
@@ -801,6 +811,19 @@
EXPECT_EQ(1, scheme_loader->num_loads());
}
+TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
+ ClosingApplicationLoader* loader = new ClosingApplicationLoader();
+ application_manager_->SetLoaderForScheme(
+ scoped_ptr<ApplicationLoader>(loader), "test");
+
+ bool called = false;
+ application_manager_->ConnectToApplication(
+ GURL("test:test"), GURL(), nullptr, nullptr,
+ base::Bind(&QuitClosure, base::Unretained(&called)));
+ loop_.Run();
+ EXPECT_TRUE(called);
+}
+
} // namespace
} // namespace shell
} // namespace mojo