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

Side by Side Diff: mojo/dbus/dbus_external_service.cc

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/dbus/dbus_external_service.h" 5 #include "mojo/dbus/dbus_external_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "dbus/bus.h" 12 #include "dbus/bus.h"
13 #include "dbus/exported_object.h" 13 #include "dbus/exported_object.h"
14 #include "dbus/file_descriptor.h" 14 #include "dbus/file_descriptor.h"
15 #include "dbus/message.h" 15 #include "dbus/message.h"
16 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
17 #include "mojo/common/channel_init.h" 17 #include "mojo/common/channel_init.h"
18 #include "mojo/public/cpp/bindings/error_handler.h" 18 #include "mojo/public/cpp/bindings/error_handler.h"
19 #include "mojo/public/cpp/bindings/remote_ptr.h"
20 #include "mojo/public/cpp/shell/application.h" 19 #include "mojo/public/cpp/shell/application.h"
21 #include "mojo/public/interfaces/shell/shell.mojom.h" 20 #include "mojo/public/interfaces/shell/shell.mojom.h"
22 #include "mojo/shell/external_service.mojom.h" 21 #include "mojo/shell/external_service.mojom.h"
23 22
24 namespace mojo { 23 namespace mojo {
25 24
26 DBusExternalServiceBase::DBusExternalServiceBase( 25 DBusExternalServiceBase::DBusExternalServiceBase(
27 const std::string& service_name) 26 const std::string& service_name)
28 : service_name_(service_name), 27 : service_name_(service_name),
29 exported_object_(NULL) { 28 exported_object_(NULL) {
30 } 29 }
31 DBusExternalServiceBase::~DBusExternalServiceBase() {} 30 DBusExternalServiceBase::~DBusExternalServiceBase() {}
32 31
33 void DBusExternalServiceBase::Start() { 32 void DBusExternalServiceBase::Start() {
34 InitializeDBus(); 33 InitializeDBus();
35 ExportMethods(); 34 ExportMethods();
36 TakeDBusServiceOwnership(); 35 TakeDBusServiceOwnership();
37 DVLOG(1) << "External service started"; 36 DVLOG(1) << "External service started";
38 } 37 }
39 38
40 void DBusExternalServiceBase::OnError() {
41 Disconnect();
42 }
43
44 void DBusExternalServiceBase::ConnectChannel( 39 void DBusExternalServiceBase::ConnectChannel(
45 dbus::MethodCall* method_call, 40 dbus::MethodCall* method_call,
46 dbus::ExportedObject::ResponseSender sender) { 41 dbus::ExportedObject::ResponseSender sender) {
47 dbus::MessageReader reader(method_call); 42 dbus::MessageReader reader(method_call);
48 dbus::FileDescriptor wrapped_fd; 43 dbus::FileDescriptor wrapped_fd;
49 if (!reader.PopFileDescriptor(&wrapped_fd)) { 44 if (!reader.PopFileDescriptor(&wrapped_fd)) {
50 sender.Run( 45 sender.Run(
51 dbus::ErrorResponse::FromMethodCall( 46 dbus::ErrorResponse::FromMethodCall(
52 method_call, 47 method_call,
53 "org.chromium.Mojo.BadHandle", 48 "org.chromium.Mojo.BadHandle",
54 "Invalid FD.").PassAs<dbus::Response>()); 49 "Invalid FD.").PassAs<dbus::Response>());
55 return; 50 return;
56 } 51 }
57 wrapped_fd.CheckValidity(); 52 wrapped_fd.CheckValidity();
58 channel_init_.reset(new mojo::common::ChannelInit); 53 channel_init_.reset(new mojo::common::ChannelInit);
59 mojo::ScopedMessagePipeHandle message_pipe = 54 mojo::ScopedMessagePipeHandle message_pipe =
60 channel_init_->Init(wrapped_fd.TakeValue(), 55 channel_init_->Init(wrapped_fd.TakeValue(),
61 base::MessageLoopProxy::current()); 56 base::MessageLoopProxy::current());
62 CHECK(message_pipe.is_valid()); 57 CHECK(message_pipe.is_valid());
63 58
64 Connect(mojo::ScopedExternalServiceHostHandle::From(message_pipe.Pass())); 59 Connect(message_pipe.Pass());
65 sender.Run(dbus::Response::FromMethodCall(method_call)); 60 sender.Run(dbus::Response::FromMethodCall(method_call));
66 } 61 }
67 62
68 void DBusExternalServiceBase::ExportMethods() { 63 void DBusExternalServiceBase::ExportMethods() {
69 CHECK(exported_object_); 64 CHECK(exported_object_);
70 CHECK(exported_object_->ExportMethodAndBlock( 65 CHECK(exported_object_->ExportMethodAndBlock(
71 kMojoDBusInterface, kMojoDBusConnectMethod, 66 kMojoDBusInterface, kMojoDBusConnectMethod,
72 base::Bind(&DBusExternalServiceBase::ConnectChannel, 67 base::Bind(&DBusExternalServiceBase::ConnectChannel,
73 base::Unretained(this)))); 68 base::Unretained(this))));
74 } 69 }
(...skipping 11 matching lines...) Expand all
86 } 81 }
87 82
88 void DBusExternalServiceBase::TakeDBusServiceOwnership() { 83 void DBusExternalServiceBase::TakeDBusServiceOwnership() {
89 CHECK(bus_->RequestOwnershipAndBlock( 84 CHECK(bus_->RequestOwnershipAndBlock(
90 service_name_, 85 service_name_,
91 dbus::Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT)) 86 dbus::Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT))
92 << "Unable to take ownership of " << service_name_; 87 << "Unable to take ownership of " << service_name_;
93 } 88 }
94 89
95 } // namespace mojo 90 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698