OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/threading/sequenced_worker_pool.h" |
6 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
7 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
9 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
10 #include "mojo/public/cpp/application/interface_factory.h" | 11 #include "mojo/public/cpp/application/interface_factory.h" |
11 #include "services/asset_bundle/asset_unpacker_impl.h" | 12 #include "services/asset_bundle/asset_unpacker_impl.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 namespace asset_bundle { | 15 namespace asset_bundle { |
15 | 16 |
16 class AssetBundleApp : public ApplicationDelegate, | 17 class AssetBundleApp : public ApplicationDelegate, |
17 public InterfaceFactory<AssetUnpacker> { | 18 public InterfaceFactory<AssetUnpacker> { |
18 public: | 19 public: |
19 AssetBundleApp() {} | 20 AssetBundleApp() {} |
20 ~AssetBundleApp() override {} | 21 ~AssetBundleApp() override {} |
21 | 22 |
22 private: | 23 private: |
23 // |ApplicationDelegate| override: | 24 // |ApplicationDelegate| override: |
24 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 25 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
25 connection->AddService<AssetUnpacker>(this); | 26 connection->AddService<AssetUnpacker>(this); |
26 return true; | 27 return true; |
27 } | 28 } |
28 | 29 |
29 // |InterfaceFactory<AssetUnpacker>| implementation: | 30 // |InterfaceFactory<AssetUnpacker>| implementation: |
30 void Create(ApplicationConnection* connection, | 31 void Create(ApplicationConnection* connection, |
31 InterfaceRequest<AssetUnpacker> request) override { | 32 InterfaceRequest<AssetUnpacker> request) override { |
32 new AssetUnpackerImpl(request.Pass()); | 33 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in the |
| 34 // constructor, since AtExitManager is only created in |
| 35 // ApplicationRunnerChromium::Run().) |
| 36 if (!sequenced_worker_pool_) { |
| 37 // TODO(vtl): What's the "right" way to choose the maximum number of |
| 38 // threads? |
| 39 sequenced_worker_pool_ = |
| 40 new base::SequencedWorkerPool(4, "AssetBundleWorker"); |
| 41 } |
| 42 |
| 43 new AssetUnpackerImpl( |
| 44 request.Pass(), |
| 45 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior( |
| 46 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
33 } | 47 } |
34 | 48 |
| 49 // We don't really need the "sequenced" part, but we need to be able to shut |
| 50 // down our worker pool. |
| 51 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
| 52 |
35 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); | 53 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); |
36 }; | 54 }; |
37 | 55 |
38 } // namespace asset_bundle | 56 } // namespace asset_bundle |
39 } // namespace mojo | 57 } // namespace mojo |
40 | 58 |
41 MojoResult MojoMain(MojoHandle application_request) { | 59 MojoResult MojoMain(MojoHandle application_request) { |
42 mojo::ApplicationRunnerChromium runner( | 60 mojo::ApplicationRunnerChromium runner( |
43 new mojo::asset_bundle::AssetBundleApp()); | 61 new mojo::asset_bundle::AssetBundleApp()); |
44 return runner.Run(application_request); | 62 return runner.Run(application_request); |
45 } | 63 } |
OLD | NEW |