Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: services/asset_bundle/main.cc

Issue 2005103003: Add implementations of mojo::{Run,Terminate}[Main]Application() for "chromium". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/application/application_runner_chromium.h"
8 #include "mojo/public/c/system/main.h" 7 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_impl_base.h"
9 #include "mojo/public/cpp/application/run_application.h"
10 #include "mojo/public/cpp/application/service_provider_impl.h" 10 #include "mojo/public/cpp/application/service_provider_impl.h"
11 #include "services/asset_bundle/asset_unpacker_impl.h" 11 #include "services/asset_bundle/asset_unpacker_impl.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace asset_bundle { 14 namespace asset_bundle {
15 15
16 class AssetBundleApp : public ApplicationDelegate { 16 class AssetBundleApp : public ApplicationImplBase {
17 public: 17 public:
18 AssetBundleApp() {} 18 AssetBundleApp() {}
19 ~AssetBundleApp() override {} 19 ~AssetBundleApp() override {}
20 20
21 private: 21 private:
22 // |ApplicationDelegate| override: 22 // |ApplicationImplBase| override:
23 bool ConfigureIncomingConnection( 23 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override {
24 ServiceProviderImpl* service_provider_impl) override {
25 service_provider_impl->AddService<AssetUnpacker>( 24 service_provider_impl->AddService<AssetUnpacker>(
26 [this](const ConnectionContext& connection_context, 25 [this](const ConnectionContext& connection_context,
27 InterfaceRequest<AssetUnpacker> asset_unpacker_request) { 26 InterfaceRequest<AssetUnpacker> asset_unpacker_request) {
28 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in 27 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in
29 // the constructor, since AtExitManager is only created in 28 // the constructor, since AtExitManager is only created in
30 // ApplicationRunnerChromium::Run().) 29 // mojo::RunMainApplication().)
31 if (!sequenced_worker_pool_) { 30 if (!sequenced_worker_pool_) {
32 // TODO(vtl): What's the "right" way to choose the maximum number of 31 // TODO(vtl): What's the "right" way to choose the maximum number of
33 // threads? 32 // threads?
34 sequenced_worker_pool_ = 33 sequenced_worker_pool_ =
35 new base::SequencedWorkerPool(4, "AssetBundleWorker"); 34 new base::SequencedWorkerPool(4, "AssetBundleWorker");
36 } 35 }
37 36
38 new AssetUnpackerImpl( 37 new AssetUnpackerImpl(
39 asset_unpacker_request.Pass(), 38 asset_unpacker_request.Pass(),
40 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior( 39 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior(
41 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 40 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
42 }); 41 });
43 return true; 42 return true;
44 } 43 }
45 44
46 // We don't really need the "sequenced" part, but we need to be able to shut 45 // We don't really need the "sequenced" part, but we need to be able to shut
47 // down our worker pool. 46 // down our worker pool.
48 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; 47 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
49 48
50 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); 49 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp);
51 }; 50 };
52 51
53 } // namespace asset_bundle 52 } // namespace asset_bundle
54 } // namespace mojo 53 } // namespace mojo
55 54
56 MojoResult MojoMain(MojoHandle application_request) { 55 MojoResult MojoMain(MojoHandle application_request) {
57 mojo::ApplicationRunnerChromium runner( 56 mojo::asset_bundle::AssetBundleApp asset_bundle_app;
58 new mojo::asset_bundle::AssetBundleApp()); 57 return mojo::RunMainApplication(application_request, &asset_bundle_app);
59 return runner.Run(application_request);
60 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698