| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/application_manager/background_shell_application_loader.h" | 5 #include "mojo/application_manager/background_shell_application_loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "mojo/application_manager/application_manager.h" | 9 #include "mojo/application_manager/application_manager.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 class BackgroundShellApplicationLoader::BackgroundLoader { | 13 class BackgroundShellApplicationLoader::BackgroundLoader { |
| 14 public: | 14 public: |
| 15 explicit BackgroundLoader(ApplicationLoader* loader) : loader_(loader) {} | 15 explicit BackgroundLoader(ApplicationLoader* loader) : loader_(loader) {} |
| 16 ~BackgroundLoader() {} | 16 ~BackgroundLoader() {} |
| 17 | 17 |
| 18 void Load(ApplicationManager* manager, | 18 void Load(ApplicationManager* manager, |
| 19 const GURL& url, | 19 const GURL& url, |
| 20 ScopedMessagePipeHandle shell_handle) { | 20 ScopedMessagePipeHandle shell_handle) { |
| 21 scoped_refptr<LoadCallbacks> callbacks( | 21 scoped_refptr<LoadCallbacks> callbacks( |
| 22 new ApplicationLoader::SimpleLoadCallbacks(shell_handle.Pass())); | 22 new ApplicationLoader::SimpleLoadCallbacks(shell_handle.Pass())); |
| 23 loader_->Load(manager, url, callbacks); | 23 loader_->Load(manager, url, callbacks); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void OnServiceError(ApplicationManager* manager, const GURL& url) { | 26 void OnApplicationError(ApplicationManager* manager, const GURL& url) { |
| 27 loader_->OnServiceError(manager, url); | 27 loader_->OnApplicationError(manager, url); |
| 28 } | 28 } |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 ApplicationLoader* loader_; // Owned by BackgroundShellApplicationLoader | 31 ApplicationLoader* loader_; // Owned by BackgroundShellApplicationLoader |
| 32 | 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); | 33 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 BackgroundShellApplicationLoader::BackgroundShellApplicationLoader( | 36 BackgroundShellApplicationLoader::BackgroundShellApplicationLoader( |
| 37 scoped_ptr<ApplicationLoader> real_loader, | 37 scoped_ptr<ApplicationLoader> real_loader, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 task_runner_->PostTask( | 73 task_runner_->PostTask( |
| 74 FROM_HERE, | 74 FROM_HERE, |
| 75 base::Bind( | 75 base::Bind( |
| 76 &BackgroundShellApplicationLoader::LoadOnBackgroundThread, | 76 &BackgroundShellApplicationLoader::LoadOnBackgroundThread, |
| 77 base::Unretained(this), | 77 base::Unretained(this), |
| 78 manager, | 78 manager, |
| 79 url, | 79 url, |
| 80 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass())))); | 80 base::Owned(new ScopedMessagePipeHandle(shell_handle.Pass())))); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void BackgroundShellApplicationLoader::OnServiceError( | 83 void BackgroundShellApplicationLoader::OnApplicationError( |
| 84 ApplicationManager* manager, | 84 ApplicationManager* manager, |
| 85 const GURL& url) { | 85 const GURL& url) { |
| 86 task_runner_->PostTask( | 86 task_runner_->PostTask(FROM_HERE, |
| 87 FROM_HERE, | 87 base::Bind(&BackgroundShellApplicationLoader:: |
| 88 base::Bind( | 88 OnApplicationErrorOnBackgroundThread, |
| 89 &BackgroundShellApplicationLoader::OnServiceErrorOnBackgroundThread, | 89 base::Unretained(this), |
| 90 base::Unretained(this), | 90 manager, |
| 91 manager, | 91 url)); |
| 92 url)); | |
| 93 } | 92 } |
| 94 | 93 |
| 95 void BackgroundShellApplicationLoader::Run() { | 94 void BackgroundShellApplicationLoader::Run() { |
| 96 base::MessageLoop message_loop(message_loop_type_); | 95 base::MessageLoop message_loop(message_loop_type_); |
| 97 base::RunLoop loop; | 96 base::RunLoop loop; |
| 98 task_runner_ = message_loop.task_runner(); | 97 task_runner_ = message_loop.task_runner(); |
| 99 quit_closure_ = loop.QuitClosure(); | 98 quit_closure_ = loop.QuitClosure(); |
| 100 message_loop_created_.Signal(); | 99 message_loop_created_.Signal(); |
| 101 loop.Run(); | 100 loop.Run(); |
| 102 | 101 |
| 103 delete background_loader_; | 102 delete background_loader_; |
| 104 background_loader_ = NULL; | 103 background_loader_ = NULL; |
| 105 // Destroy |loader_| on the thread it's actually used on. | 104 // Destroy |loader_| on the thread it's actually used on. |
| 106 loader_.reset(); | 105 loader_.reset(); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void BackgroundShellApplicationLoader::LoadOnBackgroundThread( | 108 void BackgroundShellApplicationLoader::LoadOnBackgroundThread( |
| 110 ApplicationManager* manager, | 109 ApplicationManager* manager, |
| 111 const GURL& url, | 110 const GURL& url, |
| 112 ScopedMessagePipeHandle* shell_handle) { | 111 ScopedMessagePipeHandle* shell_handle) { |
| 113 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 112 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 114 if (!background_loader_) | 113 if (!background_loader_) |
| 115 background_loader_ = new BackgroundLoader(loader_.get()); | 114 background_loader_ = new BackgroundLoader(loader_.get()); |
| 116 background_loader_->Load(manager, url, shell_handle->Pass()); | 115 background_loader_->Load(manager, url, shell_handle->Pass()); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void BackgroundShellApplicationLoader::OnServiceErrorOnBackgroundThread( | 118 void BackgroundShellApplicationLoader::OnApplicationErrorOnBackgroundThread( |
| 120 ApplicationManager* manager, | 119 ApplicationManager* manager, |
| 121 const GURL& url) { | 120 const GURL& url) { |
| 122 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 121 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 123 if (!background_loader_) | 122 if (!background_loader_) |
| 124 background_loader_ = new BackgroundLoader(loader_.get()); | 123 background_loader_ = new BackgroundLoader(loader_.get()); |
| 125 background_loader_->OnServiceError(manager, url); | 124 background_loader_->OnApplicationError(manager, url); |
| 126 } | 125 } |
| 127 | 126 |
| 128 } // namespace mojo | 127 } // namespace mojo |
| OLD | NEW |