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 "base/threading/sequenced_worker_pool.h" |
| 7 #include "mojo/environment/scoped_chromium_init.h" |
7 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_impl_base.h" | 9 #include "mojo/public/cpp/application/application_impl_base.h" |
9 #include "mojo/public/cpp/application/run_application.h" | 10 #include "mojo/public/cpp/application/run_application.h" |
10 #include "mojo/public/cpp/application/service_provider_impl.h" | 11 #include "mojo/public/cpp/application/service_provider_impl.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 ApplicationImplBase { | 17 class AssetBundleApp : public ApplicationImplBase { |
17 public: | 18 public: |
18 AssetBundleApp() {} | 19 AssetBundleApp() {} |
19 ~AssetBundleApp() override {} | 20 ~AssetBundleApp() override {} |
20 | 21 |
21 private: | 22 private: |
22 // |ApplicationImplBase| override: | 23 // |ApplicationImplBase| override: |
23 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override { | 24 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override { |
24 service_provider_impl->AddService<AssetUnpacker>( | 25 service_provider_impl->AddService<AssetUnpacker>( |
25 [this](const ConnectionContext& connection_context, | 26 [this](const ConnectionContext& connection_context, |
26 InterfaceRequest<AssetUnpacker> asset_unpacker_request) { | 27 InterfaceRequest<AssetUnpacker> asset_unpacker_request) { |
27 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in | 28 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in |
28 // the constructor, since AtExitManager is only created in | 29 // the constructor, since the message loop (which implies that there's |
29 // mojo::RunMainApplication().) | 30 // a current SingleThreadTaskRunner) is only created in |
| 31 // mojo::RunApplication().) |
30 if (!sequenced_worker_pool_) { | 32 if (!sequenced_worker_pool_) { |
31 // TODO(vtl): What's the "right" way to choose the maximum number of | 33 // TODO(vtl): What's the "right" way to choose the maximum number of |
32 // threads? | 34 // threads? |
33 sequenced_worker_pool_ = | 35 sequenced_worker_pool_ = |
34 new base::SequencedWorkerPool(4, "AssetBundleWorker"); | 36 new base::SequencedWorkerPool(4, "AssetBundleWorker"); |
35 } | 37 } |
36 | 38 |
37 new AssetUnpackerImpl( | 39 new AssetUnpackerImpl( |
38 asset_unpacker_request.Pass(), | 40 asset_unpacker_request.Pass(), |
39 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior( | 41 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior( |
40 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 42 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
41 }); | 43 }); |
42 return true; | 44 return true; |
43 } | 45 } |
44 | 46 |
45 // We don't really need the "sequenced" part, but we need to be able to shut | 47 // We don't really need the "sequenced" part, but we need to be able to shut |
46 // down our worker pool. | 48 // down our worker pool. |
47 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | 49 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
48 | 50 |
49 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); | 51 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); |
50 }; | 52 }; |
51 | 53 |
52 } // namespace asset_bundle | 54 } // namespace asset_bundle |
53 } // namespace mojo | 55 } // namespace mojo |
54 | 56 |
55 MojoResult MojoMain(MojoHandle application_request) { | 57 MojoResult MojoMain(MojoHandle application_request) { |
| 58 mojo::ScopedChromiumInit init; |
56 mojo::asset_bundle::AssetBundleApp asset_bundle_app; | 59 mojo::asset_bundle::AssetBundleApp asset_bundle_app; |
57 return mojo::RunMainApplication(application_request, &asset_bundle_app); | 60 return mojo::RunApplication(application_request, &asset_bundle_app); |
58 } | 61 } |
OLD | NEW |