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: |
20 // TODO(vtl): What's the "right" way to choose the maximum number of threads? | |
kulakowski
2015/06/24 22:19:08
This could maybe be closer to the magical |4| cons
viettrungluu
2015/06/24 22:23:43
Done. (Forgot to move the comment after I discover
| |
19 AssetBundleApp() {} | 21 AssetBundleApp() {} |
20 ~AssetBundleApp() override {} | 22 ~AssetBundleApp() override {} |
21 | 23 |
22 private: | 24 private: |
23 // |ApplicationDelegate| override: | 25 // |ApplicationDelegate| override: |
24 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 26 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
25 connection->AddService<AssetUnpacker>(this); | 27 connection->AddService<AssetUnpacker>(this); |
26 return true; | 28 return true; |
27 } | 29 } |
28 | 30 |
29 // |InterfaceFactory<AssetUnpacker>| implementation: | 31 // |InterfaceFactory<AssetUnpacker>| implementation: |
30 void Create(ApplicationConnection* connection, | 32 void Create(ApplicationConnection* connection, |
31 InterfaceRequest<AssetUnpacker> request) override { | 33 InterfaceRequest<AssetUnpacker> request) override { |
32 new AssetUnpackerImpl(request.Pass()); | 34 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in the |
35 // constructor, since AtExitManager is only created in | |
36 // ApplicationRunnerChromium::Run().) | |
37 if (!sequenced_worker_pool_) { | |
38 sequenced_worker_pool_ = | |
39 new base::SequencedWorkerPool(4, "AssetBundleWorker"); | |
40 } | |
41 | |
42 new AssetUnpackerImpl( | |
43 request.Pass(), | |
44 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior( | |
45 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
33 } | 46 } |
34 | 47 |
48 // We don't really need the "sequenced" part, but we need to be able to shut | |
49 // down our worker pool. | |
50 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | |
51 | |
35 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); | 52 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); |
36 }; | 53 }; |
37 | 54 |
38 } // namespace asset_bundle | 55 } // namespace asset_bundle |
39 } // namespace mojo | 56 } // namespace mojo |
40 | 57 |
41 MojoResult MojoMain(MojoHandle application_request) { | 58 MojoResult MojoMain(MojoHandle application_request) { |
42 mojo::ApplicationRunnerChromium runner( | 59 mojo::ApplicationRunnerChromium runner( |
43 new mojo::asset_bundle::AssetBundleApp()); | 60 new mojo::asset_bundle::AssetBundleApp()); |
44 return runner.Run(application_request); | 61 return runner.Run(application_request); |
45 } | 62 } |
OLD | NEW |