| 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/service_manager/background_service_loader.h" | 5 #include "mojo/service_manager/background_service_loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mojo/service_manager/service_manager.h" | 8 #include "mojo/service_manager/service_manager.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 | 11 |
| 12 class BackgroundServiceLoader::BackgroundLoader { | 12 class BackgroundServiceLoader::BackgroundLoader { |
| 13 public: | 13 public: |
| 14 explicit BackgroundLoader(ServiceLoader* loader) : loader_(loader) {} | 14 explicit BackgroundLoader(ServiceLoader* loader) : loader_(loader) {} |
| 15 ~BackgroundLoader() {} | 15 ~BackgroundLoader() {} |
| 16 | 16 |
| 17 void LoadService(ServiceManager* manager, | 17 void LoadService(ServiceManager* manager, |
| 18 const GURL& url, | 18 const GURL& url, |
| 19 ScopedShellHandle shell_handle) { | 19 ScopedMessagePipeHandle shell_handle) { |
| 20 loader_->LoadService(manager, url, shell_handle.Pass()); | 20 loader_->LoadService(manager, url, shell_handle.Pass()); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void OnServiceError(ServiceManager* manager, const GURL& url) { | 23 void OnServiceError(ServiceManager* manager, const GURL& url) { |
| 24 loader_->OnServiceError(manager, url); | 24 loader_->OnServiceError(manager, url); |
| 25 } | 25 } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 ServiceLoader* loader_; // Owned by BackgroundServiceLoader | 28 ServiceLoader* loader_; // Owned by BackgroundServiceLoader |
| 29 | 29 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 BackgroundServiceLoader::~BackgroundServiceLoader() { | 41 BackgroundServiceLoader::~BackgroundServiceLoader() { |
| 42 if (thread_.IsRunning()) { | 42 if (thread_.IsRunning()) { |
| 43 thread_.message_loop()->PostTask( | 43 thread_.message_loop()->PostTask( |
| 44 FROM_HERE, | 44 FROM_HERE, |
| 45 base::Bind(&BackgroundServiceLoader::ShutdownOnBackgroundThread, | 45 base::Bind(&BackgroundServiceLoader::ShutdownOnBackgroundThread, |
| 46 base::Unretained(this))); | 46 base::Unretained(this))); |
| 47 } | 47 } |
| 48 thread_.Stop(); | 48 thread_.Stop(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void BackgroundServiceLoader::LoadService(ServiceManager* manager, | 51 void BackgroundServiceLoader::LoadService( |
| 52 const GURL& url, | 52 ServiceManager* manager, |
| 53 ScopedShellHandle service_handle) { | 53 const GURL& url, |
| 54 ScopedMessagePipeHandle service_handle) { |
| 54 if (!thread_.IsRunning()) | 55 if (!thread_.IsRunning()) |
| 55 thread_.Start(); | 56 thread_.Start(); |
| 56 thread_.message_loop()->PostTask( | 57 thread_.message_loop()->PostTask( |
| 57 FROM_HERE, | 58 FROM_HERE, |
| 58 base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, | 59 base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, |
| 59 base::Unretained(this), manager, url, | 60 base::Unretained(this), manager, url, |
| 60 base::Owned(new ScopedShellHandle(service_handle.Pass())))); | 61 base::Owned( |
| 62 new ScopedMessagePipeHandle(service_handle.Pass())))); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void BackgroundServiceLoader::OnServiceError(ServiceManager* manager, | 65 void BackgroundServiceLoader::OnServiceError(ServiceManager* manager, |
| 64 const GURL& url) { | 66 const GURL& url) { |
| 65 if (!thread_.IsRunning()) | 67 if (!thread_.IsRunning()) |
| 66 thread_.Start(); | 68 thread_.Start(); |
| 67 thread_.message_loop()->PostTask( | 69 thread_.message_loop()->PostTask( |
| 68 FROM_HERE, | 70 FROM_HERE, |
| 69 base::Bind(&BackgroundServiceLoader::OnServiceErrorOnBackgroundThread, | 71 base::Bind(&BackgroundServiceLoader::OnServiceErrorOnBackgroundThread, |
| 70 base::Unretained(this), manager, url)); | 72 base::Unretained(this), manager, url)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void BackgroundServiceLoader::LoadServiceOnBackgroundThread( | 75 void BackgroundServiceLoader::LoadServiceOnBackgroundThread( |
| 74 ServiceManager* manager, | 76 ServiceManager* manager, |
| 75 const GURL& url, | 77 const GURL& url, |
| 76 ScopedShellHandle* shell_handle) { | 78 ScopedMessagePipeHandle* shell_handle) { |
| 77 if (!background_loader_) | 79 if (!background_loader_) |
| 78 background_loader_ = new BackgroundLoader(loader_.get()); | 80 background_loader_ = new BackgroundLoader(loader_.get()); |
| 79 background_loader_->LoadService(manager, url, shell_handle->Pass()); | 81 background_loader_->LoadService(manager, url, shell_handle->Pass()); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void BackgroundServiceLoader::OnServiceErrorOnBackgroundThread( | 84 void BackgroundServiceLoader::OnServiceErrorOnBackgroundThread( |
| 83 ServiceManager* manager, | 85 ServiceManager* manager, |
| 84 const GURL& url) { | 86 const GURL& url) { |
| 85 if (!background_loader_) | 87 if (!background_loader_) |
| 86 background_loader_ = new BackgroundLoader(loader_.get()); | 88 background_loader_ = new BackgroundLoader(loader_.get()); |
| 87 background_loader_->OnServiceError(manager, url); | 89 background_loader_->OnServiceError(manager, url); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void BackgroundServiceLoader::ShutdownOnBackgroundThread() { | 92 void BackgroundServiceLoader::ShutdownOnBackgroundThread() { |
| 91 delete background_loader_; | 93 delete background_loader_; |
| 92 } | 94 } |
| 93 | 95 |
| 94 } // namespace mojo | 96 } // namespace mojo |
| OLD | NEW |