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

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

Issue 1975253002: ApplicationConnection devolution, part 2.1. (Closed) Base URL: https://github.com/domokit/mojo.git@work792-x-work791_service_registry_spimpl
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
« no previous file with comments | « mojo/ui/view_provider_app.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/interface_factory.h"
12 #include "services/asset_bundle/asset_unpacker_impl.h" 11 #include "services/asset_bundle/asset_unpacker_impl.h"
13 12
14 namespace mojo { 13 namespace mojo {
15 namespace asset_bundle { 14 namespace asset_bundle {
16 15
17 class AssetBundleApp : public ApplicationDelegate, 16 class AssetBundleApp : public ApplicationDelegate {
18 public InterfaceFactory<AssetUnpacker> {
19 public: 17 public:
20 AssetBundleApp() {} 18 AssetBundleApp() {}
21 ~AssetBundleApp() override {} 19 ~AssetBundleApp() override {}
22 20
23 private: 21 private:
24 // |ApplicationDelegate| override: 22 // |ApplicationDelegate| override:
25 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 23 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
26 connection->AddService<AssetUnpacker>(this); 24 connection->GetServiceProviderImpl().AddService<AssetUnpacker>(
25 [this](const ConnectionContext& connection_context,
26 InterfaceRequest<AssetUnpacker> asset_unpacker_request) {
27 // Lazily initialize |sequenced_worker_pool_|. (We can't create it in
28 // the constructor, since AtExitManager is only created in
29 // ApplicationRunnerChromium::Run().)
30 if (!sequenced_worker_pool_) {
31 // TODO(vtl): What's the "right" way to choose the maximum number of
32 // threads?
33 sequenced_worker_pool_ =
34 new base::SequencedWorkerPool(4, "AssetBundleWorker");
35 }
36
37 new AssetUnpackerImpl(
38 asset_unpacker_request.Pass(),
39 sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior(
40 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
41 });
27 return true; 42 return true;
28 } 43 }
29 44
30 // |InterfaceFactory<AssetUnpacker>| implementation:
31 void Create(const ConnectionContext& connection_context,
32 InterfaceRequest<AssetUnpacker> request) override {
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));
47 }
48
49 // 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
50 // down our worker pool. 46 // down our worker pool.
51 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; 47 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
52 48
53 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp); 49 DISALLOW_COPY_AND_ASSIGN(AssetBundleApp);
54 }; 50 };
55 51
56 } // namespace asset_bundle 52 } // namespace asset_bundle
57 } // namespace mojo 53 } // namespace mojo
58 54
59 MojoResult MojoMain(MojoHandle application_request) { 55 MojoResult MojoMain(MojoHandle application_request) {
60 mojo::ApplicationRunnerChromium runner( 56 mojo::ApplicationRunnerChromium runner(
61 new mojo::asset_bundle::AssetBundleApp()); 57 new mojo::asset_bundle::AssetBundleApp());
62 return runner.Run(application_request); 58 return runner.Run(application_request);
63 } 59 }
OLDNEW
« no previous file with comments | « mojo/ui/view_provider_app.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698