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

Side by Side Diff: services/device_info/device_info.cc

Issue 1975993002: Change InterfaceFactory<I>::Create() to take a ConnectionContext instead of an ApplicationConnectio… (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
« no previous file with comments | « services/clipboard/main.cc ('k') | services/files/files_impl.h » ('j') | 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 <cstdlib> 5 #include <cstdlib>
6 #include <memory> 6 #include <memory>
7 7
8 #include "mojo/common/binding_set.h" 8 #include "mojo/common/binding_set.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_runner.h" 12 #include "mojo/public/cpp/application/application_runner.h"
13 #include "mojo/public/cpp/application/interface_factory.h" 13 #include "mojo/public/cpp/application/interface_factory.h"
14 #include "mojo/services/device_info/interfaces/device_info.mojom.h" 14 #include "mojo/services/device_info/interfaces/device_info.mojom.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace services { 17 namespace services {
18 namespace device_info { 18 namespace device_info {
19 19
20 // This is a native Mojo application which implements |DeviceInfo| interface for 20 // This is a native Mojo application which implements |DeviceInfo| interface for
21 // Linux. 21 // Linux.
22 class DeviceInfo : public mojo::ApplicationDelegate, 22 class DeviceInfo : public ApplicationDelegate,
23 public mojo::DeviceInfo, 23 public mojo::DeviceInfo,
24 public mojo::InterfaceFactory<mojo::DeviceInfo> { 24 public InterfaceFactory<mojo::DeviceInfo> {
25 public: 25 public:
26 // We look for the 'DISPLAY' environment variable. If present, then we assume 26 // We look for the 'DISPLAY' environment variable. If present, then we assume
27 // it to be a desktop, else we assume it to be a commandline 27 // it to be a desktop, else we assume it to be a commandline
28 void GetDeviceType(const GetDeviceTypeCallback& callback) override { 28 void GetDeviceType(const GetDeviceTypeCallback& callback) override {
29 callback.Run(getenv("DISPLAY") ? DeviceInfo::DeviceType::DESKTOP 29 callback.Run(getenv("DISPLAY") ? DeviceInfo::DeviceType::DESKTOP
30 : DeviceInfo::DeviceType::HEADLESS); 30 : DeviceInfo::DeviceType::HEADLESS);
31 } 31 }
32 32
33 // |ApplicationDelegate| override. 33 // |ApplicationDelegate| override.
34 bool ConfigureIncomingConnection( 34 bool ConfigureIncomingConnection(
35 mojo::ApplicationConnection* connection) override { 35 mojo::ApplicationConnection* connection) override {
36 connection->AddService<mojo::DeviceInfo>(this); 36 connection->AddService<mojo::DeviceInfo>(this);
37 return true; 37 return true;
38 } 38 }
39 39
40 // |InterfaceFactory<DeviceInfo>| implementation. 40 // |InterfaceFactory<DeviceInfo>| implementation.
41 void Create(mojo::ApplicationConnection* connection, 41 void Create(const ConnectionContext& connection_context,
42 mojo::InterfaceRequest<mojo::DeviceInfo> request) override { 42 InterfaceRequest<mojo::DeviceInfo> request) override {
43 binding_.AddBinding(this, request.Pass()); 43 binding_.AddBinding(this, request.Pass());
44 } 44 }
45 45
46 private: 46 private:
47 mojo::BindingSet<mojo::DeviceInfo> binding_; 47 mojo::BindingSet<mojo::DeviceInfo> binding_;
48 }; 48 };
49 49
50 } // namespace device_info 50 } // namespace device_info
51 } // namespace services 51 } // namespace services
52 } // namespace mojo 52 } // namespace mojo
53 53
54 MojoResult MojoMain(MojoHandle application_request) { 54 MojoResult MojoMain(MojoHandle application_request) {
55 mojo::ApplicationRunner runner( 55 mojo::ApplicationRunner runner(
56 std::unique_ptr<mojo::services::device_info::DeviceInfo>( 56 std::unique_ptr<mojo::services::device_info::DeviceInfo>(
57 new mojo::services::device_info::DeviceInfo())); 57 new mojo::services::device_info::DeviceInfo()));
58 return runner.Run(application_request); 58 return runner.Run(application_request);
59 } 59 }
OLDNEW
« no previous file with comments | « services/clipboard/main.cc ('k') | services/files/files_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698