OLD | NEW |
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/shell/dbus_application_loader_linux.h" | 5 #include "mojo/shell/dbus_application_loader_linux.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
15 #include "dbus/file_descriptor.h" | 15 #include "dbus/file_descriptor.h" |
16 #include "dbus/message.h" | 16 #include "dbus/message.h" |
17 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
19 #include "mojo/dbus/dbus_external_service.h" | 19 #include "mojo/dbus/dbus_external_service.h" |
20 #include "mojo/embedder/channel_init.h" | 20 #include "mojo/embedder/channel_init.h" |
21 #include "mojo/embedder/platform_channel_pair.h" | 21 #include "mojo/embedder/platform_channel_pair.h" |
22 #include "mojo/shell/context.h" | 22 #include "mojo/shell/context.h" |
23 #include "mojo/shell/external_service.mojom.h" | 23 #include "mojo/shell/external_service.mojom.h" |
24 #include "mojo/shell/keep_alive.h" | |
25 | 24 |
26 namespace mojo { | 25 namespace mojo { |
27 namespace shell { | 26 namespace shell { |
28 | 27 |
29 // Manages the connection to a single externally-running service. | 28 // Manages the connection to a single externally-running service. |
30 class DBusApplicationLoader::LoadContext { | 29 class DBusApplicationLoader::LoadContext { |
31 public: | 30 public: |
32 // Kicks off the attempt to bootstrap a connection to the externally-running | 31 // Kicks off the attempt to bootstrap a connection to the externally-running |
33 // service specified by url_. | 32 // service specified by url_. |
34 // Creates a MessagePipe and passes one end over DBus to the service. Then, | 33 // Creates a MessagePipe and passes one end over DBus to the service. Then, |
35 // calls ExternalService::Activate(ShellHandle) over the now-shared pipe. | 34 // calls ExternalService::Activate(ShellHandle) over the now-shared pipe. |
36 LoadContext(DBusApplicationLoader* loader, | 35 LoadContext(DBusApplicationLoader* loader, |
37 const scoped_refptr<dbus::Bus>& bus, | 36 const scoped_refptr<dbus::Bus>& bus, |
38 const GURL& url, | 37 const GURL& url, |
39 ScopedMessagePipeHandle service_provider_handle) | 38 ScopedMessagePipeHandle service_provider_handle) |
40 : loader_(loader), | 39 : loader_(loader), |
41 bus_(bus), | 40 bus_(bus), |
42 service_dbus_proxy_(NULL), | 41 service_dbus_proxy_(NULL), |
43 url_(url), | 42 url_(url), |
44 service_provider_handle_(service_provider_handle.Pass()), | 43 service_provider_handle_(service_provider_handle.Pass()) { |
45 keep_alive_(loader->context_) { | |
46 base::PostTaskAndReplyWithResult( | 44 base::PostTaskAndReplyWithResult( |
47 loader_->context_->task_runners()->io_runner(), | 45 loader_->context_->task_runners()->io_runner(), |
48 FROM_HERE, | 46 FROM_HERE, |
49 base::Bind(&LoadContext::CreateChannelOnIOThread, | 47 base::Bind(&LoadContext::CreateChannelOnIOThread, |
50 base::Unretained(this)), | 48 base::Unretained(this)), |
51 base::Bind(&LoadContext::ConnectChannel, base::Unretained(this))); | 49 base::Bind(&LoadContext::ConnectChannel, base::Unretained(this))); |
52 } | 50 } |
53 | 51 |
54 virtual ~LoadContext() {} | 52 virtual ~LoadContext() {} |
55 | 53 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 base::Unretained(loader_), | 122 base::Unretained(loader_), |
125 url_)); | 123 url_)); |
126 } | 124 } |
127 } | 125 } |
128 | 126 |
129 DBusApplicationLoader* const loader_; | 127 DBusApplicationLoader* const loader_; |
130 scoped_refptr<dbus::Bus> bus_; | 128 scoped_refptr<dbus::Bus> bus_; |
131 dbus::ObjectProxy* service_dbus_proxy_; // Owned by bus_; | 129 dbus::ObjectProxy* service_dbus_proxy_; // Owned by bus_; |
132 const GURL url_; | 130 const GURL url_; |
133 ScopedMessagePipeHandle service_provider_handle_; | 131 ScopedMessagePipeHandle service_provider_handle_; |
134 KeepAlive keep_alive_; | |
135 scoped_ptr<embedder::ChannelInit> channel_init_; | 132 scoped_ptr<embedder::ChannelInit> channel_init_; |
136 ExternalServicePtr external_service_; | 133 ExternalServicePtr external_service_; |
137 | 134 |
138 DISALLOW_COPY_AND_ASSIGN(LoadContext); | 135 DISALLOW_COPY_AND_ASSIGN(LoadContext); |
139 }; | 136 }; |
140 | 137 |
141 DBusApplicationLoader::DBusApplicationLoader(Context* context) | 138 DBusApplicationLoader::DBusApplicationLoader(Context* context) |
142 : context_(context) { | 139 : context_(context) { |
143 dbus::Bus::Options options; | 140 dbus::Bus::Options options; |
144 options.bus_type = dbus::Bus::SESSION; | 141 options.bus_type = dbus::Bus::SESSION; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 DCHECK(it != url_to_load_context_.end()) << url; | 175 DCHECK(it != url_to_load_context_.end()) << url; |
179 | 176 |
180 LoadContext* doomed = it->second; | 177 LoadContext* doomed = it->second; |
181 url_to_load_context_.erase(it); | 178 url_to_load_context_.erase(it); |
182 | 179 |
183 delete doomed; | 180 delete doomed; |
184 } | 181 } |
185 | 182 |
186 } // namespace shell | 183 } // namespace shell |
187 } // namespace mojo | 184 } // namespace mojo |
OLD | NEW |