1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/shell/ui_application_loader_android.h"
8 #include "mojo/application_manager/application_manager.h"
9 #include "mojo/shell/context.h"
13 class UIApplicationLoader::UILoader {
15 explicit UILoader(ApplicationLoader* loader) : loader_(loader) {}
18 void Load(ApplicationManager* manager,
20 ScopedMessagePipeHandle shell_handle) {
21 scoped_refptr<LoadCallbacks> callbacks(
22 new ApplicationLoader::SimpleLoadCallbacks(shell_handle.Pass()));
23 loader_->Load(manager, url, callbacks);
26 void OnApplicationError(ApplicationManager* manager, const GURL& url) {
27 loader_->OnApplicationError(manager, url);
31 ApplicationLoader* loader_; // Owned by UIApplicationLoader
33 DISALLOW_COPY_AND_ASSIGN(UILoader);
36 UIApplicationLoader::UIApplicationLoader(
37 scoped_ptr<ApplicationLoader> real_loader,
38 shell::Context* context)
39 : loader_(real_loader.Pass()), context_(context) {
42 UIApplicationLoader::~UIApplicationLoader() {
43 context_->ui_loop()->PostTask(
45 base::Bind(&UIApplicationLoader::ShutdownOnUIThread,
46 base::Unretained(this)));
49 void UIApplicationLoader::Load(ApplicationManager* manager,
51 scoped_refptr<LoadCallbacks> callbacks) {
52 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
53 if (!shell_handle.is_valid())
55 context_->ui_loop()->PostTask(
58 &UIApplicationLoader::LoadOnUIThread,
59 base::Unretained(this),
62 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass()))));
65 void UIApplicationLoader::OnApplicationError(ApplicationManager* manager,
67 context_->ui_loop()->PostTask(
69 base::Bind(&UIApplicationLoader::OnApplicationErrorOnUIThread,
70 base::Unretained(this),
75 void UIApplicationLoader::LoadOnUIThread(
76 ApplicationManager* manager,
78 ScopedMessagePipeHandle* shell_handle) {
80 ui_loader_ = new UILoader(loader_.get());
81 ui_loader_->Load(manager, url, shell_handle->Pass());
84 void UIApplicationLoader::OnApplicationErrorOnUIThread(
85 ApplicationManager* manager,
88 ui_loader_ = new UILoader(loader_.get());
89 ui_loader_->OnApplicationError(manager, url);
92 void UIApplicationLoader::ShutdownOnUIThread() {
94 // Destroy |loader_| on the thread it's actually used on.