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 ScopedMessagePipeHandle 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 base::MessageLoop::Type message_loop_type_; |
28 ServiceLoader* loader_; // Owned by BackgroundServiceLoader | 29 ServiceLoader* loader_; // Owned by BackgroundServiceLoader |
29 | 30 |
30 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); | 31 DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); |
31 }; | 32 }; |
32 | 33 |
33 BackgroundServiceLoader::BackgroundServiceLoader( | 34 BackgroundServiceLoader::BackgroundServiceLoader( |
34 scoped_ptr<ServiceLoader> real_loader, | 35 scoped_ptr<ServiceLoader> real_loader, |
35 const char* thread_name) | 36 const char* thread_name, |
| 37 base::MessageLoop::Type message_loop_type) |
36 : loader_(real_loader.Pass()), | 38 : loader_(real_loader.Pass()), |
37 thread_(thread_name), | 39 thread_(thread_name), |
| 40 message_loop_type_(message_loop_type), |
38 background_loader_(NULL) { | 41 background_loader_(NULL) { |
39 } | 42 } |
40 | 43 |
41 BackgroundServiceLoader::~BackgroundServiceLoader() { | 44 BackgroundServiceLoader::~BackgroundServiceLoader() { |
42 if (thread_.IsRunning()) { | 45 if (thread_.IsRunning()) { |
43 thread_.message_loop()->PostTask( | 46 thread_.message_loop()->PostTask( |
44 FROM_HERE, | 47 FROM_HERE, |
45 base::Bind(&BackgroundServiceLoader::ShutdownOnBackgroundThread, | 48 base::Bind(&BackgroundServiceLoader::ShutdownOnBackgroundThread, |
46 base::Unretained(this))); | 49 base::Unretained(this))); |
47 } | 50 } |
48 thread_.Stop(); | 51 thread_.Stop(); |
49 } | 52 } |
50 | 53 |
51 void BackgroundServiceLoader::LoadService( | 54 void BackgroundServiceLoader::LoadService( |
52 ServiceManager* manager, | 55 ServiceManager* manager, |
53 const GURL& url, | 56 const GURL& url, |
54 ScopedMessagePipeHandle service_handle) { | 57 ScopedMessagePipeHandle service_handle) { |
| 58 const int kDefaultStackSize = 0; |
55 if (!thread_.IsRunning()) | 59 if (!thread_.IsRunning()) |
56 thread_.Start(); | 60 thread_.StartWithOptions( |
| 61 base::Thread::Options(message_loop_type_, kDefaultStackSize)); |
57 thread_.message_loop()->PostTask( | 62 thread_.message_loop()->PostTask( |
58 FROM_HERE, | 63 FROM_HERE, |
59 base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, | 64 base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, |
60 base::Unretained(this), manager, url, | 65 base::Unretained(this), manager, url, |
61 base::Owned( | 66 base::Owned( |
62 new ScopedMessagePipeHandle(service_handle.Pass())))); | 67 new ScopedMessagePipeHandle(service_handle.Pass())))); |
63 } | 68 } |
64 | 69 |
65 void BackgroundServiceLoader::OnServiceError(ServiceManager* manager, | 70 void BackgroundServiceLoader::OnServiceError(ServiceManager* manager, |
66 const GURL& url) { | 71 const GURL& url) { |
(...skipping 22 matching lines...) Expand all Loading... |
89 background_loader_->OnServiceError(manager, url); | 94 background_loader_->OnServiceError(manager, url); |
90 } | 95 } |
91 | 96 |
92 void BackgroundServiceLoader::ShutdownOnBackgroundThread() { | 97 void BackgroundServiceLoader::ShutdownOnBackgroundThread() { |
93 delete background_loader_; | 98 delete background_loader_; |
94 // Destroy |loader_| on the thread it's actually used on. | 99 // Destroy |loader_| on the thread it's actually used on. |
95 loader_.reset(); | 100 loader_.reset(); |
96 } | 101 } |
97 | 102 |
98 } // namespace mojo | 103 } // namespace mojo |
OLD | NEW |