OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "mojo/shell/ui_service_loader_android.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "mojo/service_manager/service_manager.h" |
| 9 #include "mojo/shell/context.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 class UIServiceLoader::UILoader { |
| 14 public: |
| 15 explicit UILoader(ServiceLoader* loader) : loader_(loader) {} |
| 16 ~UILoader() {} |
| 17 |
| 18 void LoadService(ServiceManager* manager, |
| 19 const GURL& url, |
| 20 ScopedMessagePipeHandle shell_handle) { |
| 21 loader_->LoadService(manager, url, shell_handle.Pass()); |
| 22 } |
| 23 |
| 24 void OnServiceError(ServiceManager* manager, const GURL& url) { |
| 25 loader_->OnServiceError(manager, url); |
| 26 } |
| 27 |
| 28 private: |
| 29 ServiceLoader* loader_; // Owned by UIServiceLoader |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(UILoader); |
| 32 }; |
| 33 |
| 34 UIServiceLoader::UIServiceLoader(scoped_ptr<ServiceLoader> real_loader, |
| 35 shell::Context* context) |
| 36 : loader_(real_loader.Pass()), context_(context) { |
| 37 } |
| 38 |
| 39 UIServiceLoader::~UIServiceLoader() { |
| 40 context_->ui_loop()->PostTask( |
| 41 FROM_HERE, |
| 42 base::Bind(&UIServiceLoader::ShutdownOnUIThread, base::Unretained(this))); |
| 43 } |
| 44 |
| 45 void UIServiceLoader::LoadService(ServiceManager* manager, |
| 46 const GURL& url, |
| 47 ScopedMessagePipeHandle shell_handle) { |
| 48 context_->ui_loop()->PostTask( |
| 49 FROM_HERE, |
| 50 base::Bind( |
| 51 &UIServiceLoader::LoadServiceOnUIThread, |
| 52 base::Unretained(this), |
| 53 manager, |
| 54 url, |
| 55 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass())))); |
| 56 } |
| 57 |
| 58 void UIServiceLoader::OnServiceError(ServiceManager* manager, const GURL& url) { |
| 59 context_->ui_loop()->PostTask( |
| 60 FROM_HERE, |
| 61 base::Bind(&UIServiceLoader::OnServiceErrorOnUIThread, |
| 62 base::Unretained(this), |
| 63 manager, |
| 64 url)); |
| 65 } |
| 66 |
| 67 void UIServiceLoader::LoadServiceOnUIThread( |
| 68 ServiceManager* manager, |
| 69 const GURL& url, |
| 70 ScopedMessagePipeHandle* shell_handle) { |
| 71 if (!ui_loader_) |
| 72 ui_loader_ = new UILoader(loader_.get()); |
| 73 ui_loader_->LoadService(manager, url, shell_handle->Pass()); |
| 74 } |
| 75 |
| 76 void UIServiceLoader::OnServiceErrorOnUIThread(ServiceManager* manager, |
| 77 const GURL& url) { |
| 78 if (!ui_loader_) |
| 79 ui_loader_ = new UILoader(loader_.get()); |
| 80 ui_loader_->OnServiceError(manager, url); |
| 81 } |
| 82 |
| 83 void UIServiceLoader::ShutdownOnUIThread() { |
| 84 delete ui_loader_; |
| 85 // Destroy |loader_| on the thread it's actually used on. |
| 86 loader_.reset(); |
| 87 } |
| 88 |
| 89 } // namespace mojo |
OLD | NEW |