summaryrefslogtreecommitdiffstats
path: root/mojo/shell/background
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2016-02-18 11:45:37 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-18 19:47:56 +0000
commitc88b1fac82ef4f189b36d0639a3d991ef6e68d46 (patch)
treee3189e9bfb58b5613b6c4e5faacc236c85e046bc /mojo/shell/background
parentb54cda2bde753f1606df98b679f6b49179b8aca3 (diff)
downloadchromium_src-c88b1fac82ef4f189b36d0639a3d991ef6e68d46.zip
chromium_src-c88b1fac82ef4f189b36d0639a3d991ef6e68d46.tar.gz
chromium_src-c88b1fac82ef4f189b36d0639a3d991ef6e68d46.tar.bz2
Makes BackgroundShell work with async completion
This way it'll work once ConnectToApplication with an ApplicationLoader is async. BUG=581539 TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/1712663002 Cr-Commit-Position: refs/heads/master@{#376236}
Diffstat (limited to 'mojo/shell/background')
-rw-r--r--mojo/shell/background/background_shell.cc53
1 files changed, 31 insertions, 22 deletions
diff --git a/mojo/shell/background/background_shell.cc b/mojo/shell/background/background_shell.cc
index 0c5adda..3b94d04 100644
--- a/mojo/shell/background/background_shell.cc
+++ b/mojo/shell/background/background_shell.cc
@@ -29,27 +29,27 @@ scoped_ptr<base::MessagePump> CreateMessagePumpMojo() {
return make_scoped_ptr(new common::MessagePumpMojo);
}
-// Used to obtain the InterfaceRequest for an application.
+// Used to obtain the ShellClientRequest for an application. When
+// ApplicationLoader::Load() is called a callback is run with the
+// ShellClientRequest.
class BackgroundApplicationLoader : public ApplicationLoader {
public:
- BackgroundApplicationLoader() {}
- ~BackgroundApplicationLoader() override {}
+ using Callback = base::Callback<void(mojom::ShellClientRequest)>;
- bool got_request() const { return got_request_; }
- InterfaceRequest<mojom::ShellClient> TakeApplicationRequest() {
- return std::move(request_);
- }
+ explicit BackgroundApplicationLoader(const Callback& callback)
+ : callback_(callback) {}
+ ~BackgroundApplicationLoader() override {}
// ApplicationLoader:
- void Load(const GURL& url,
- InterfaceRequest<mojom::ShellClient> request) override {
- got_request_ = true;
- request_ = std::move(request);
+ void Load(const GURL& url, mojom::ShellClientRequest request) override {
+ DCHECK(!callback_.is_null()); // Callback should only be run once.
+ Callback callback = callback_;
+ callback_.Reset();
+ callback.Run(std::move(request));
}
private:
- bool got_request_ = false;
- InterfaceRequest<mojom::ShellClient> request_;
+ Callback callback_;
DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader);
};
@@ -77,21 +77,20 @@ class BackgroundShell::MojoThread : public base::SimpleThread {
void CreateShellClientRequest(base::WaitableEvent* signal,
scoped_ptr<ConnectToApplicationParams> params,
- InterfaceRequest<mojom::ShellClient>* request) {
+ mojom::ShellClientRequest* request) {
// Only valid to call this on the background thread.
DCHECK_EQ(message_loop_, base::MessageLoop::current());
// Ownership of |loader| passes to ApplicationManager.
- BackgroundApplicationLoader* loader = new BackgroundApplicationLoader;
const GURL url = params->target().url();
+ BackgroundApplicationLoader* loader = new BackgroundApplicationLoader(
+ base::Bind(&MojoThread::OnGotApplicationRequest, base::Unretained(this),
+ url, signal, request));
context_->application_manager()->SetLoaderForURL(make_scoped_ptr(loader),
url);
context_->application_manager()->ConnectToApplication(std::move(params));
- DCHECK(loader->got_request());
- *request = loader->TakeApplicationRequest();
- // Trigger destruction of the loader.
- context_->application_manager()->SetLoaderForURL(nullptr, url);
- signal->Signal();
+ // The request is asynchronously processed. When processed
+ // OnGotApplicationRequest() is called and we'll signal |signal|.
}
base::MessageLoop* message_loop() { return message_loop_; }
@@ -137,6 +136,16 @@ class BackgroundShell::MojoThread : public base::SimpleThread {
}
private:
+ void OnGotApplicationRequest(const GURL& url,
+ base::WaitableEvent* signal,
+ mojom::ShellClientRequest* request_result,
+ mojom::ShellClientRequest actual_request) {
+ *request_result = std::move(actual_request);
+ // Trigger destruction of the loader.
+ context_->application_manager()->SetLoaderForURL(nullptr, url);
+ signal->Signal();
+ }
+
// We own this. It's created on the main thread, but destroyed on the
// background thread.
MojoMessageLoop* message_loop_ = nullptr;
@@ -158,12 +167,12 @@ void BackgroundShell::Init() {
thread_->Start();
}
-InterfaceRequest<mojom::ShellClient> BackgroundShell::CreateShellClientRequest(
+mojom::ShellClientRequest BackgroundShell::CreateShellClientRequest(
const GURL& url) {
scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
params->SetTarget(
Identity(url, std::string(), GetPermissiveCapabilityFilter()));
- InterfaceRequest<mojom::ShellClient> request;
+ mojom::ShellClientRequest request;
base::WaitableEvent signal(true, false);
thread_->message_loop()->task_runner()->PostTask(
FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest,