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_service_loader_linux.h" | 5 #include "mojo/shell/dbus_service_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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // Manages the connection to a single externally-running service. | 30 // Manages the connection to a single externally-running service. |
31 class DBusServiceLoader::LoadContext { | 31 class DBusServiceLoader::LoadContext { |
32 public: | 32 public: |
33 // Kicks off the attempt to bootstrap a connection to the externally-running | 33 // Kicks off the attempt to bootstrap a connection to the externally-running |
34 // service specified by url_. | 34 // service specified by url_. |
35 // Creates a MessagePipe and passes one end over DBus to the service. Then, | 35 // Creates a MessagePipe and passes one end over DBus to the service. Then, |
36 // calls ExternalService::Activate(ShellHandle) over the now-shared pipe. | 36 // calls ExternalService::Activate(ShellHandle) over the now-shared pipe. |
37 LoadContext(DBusServiceLoader* loader, | 37 LoadContext(DBusServiceLoader* loader, |
38 const scoped_refptr<dbus::Bus>& bus, | 38 const scoped_refptr<dbus::Bus>& bus, |
39 const GURL& url, | 39 const GURL& url, |
40 ScopedMessagePipeHandle shell_handle) | 40 ScopedMessagePipeHandle service_provider_handle) |
41 : loader_(loader), | 41 : loader_(loader), |
42 bus_(bus), | 42 bus_(bus), |
43 service_dbus_proxy_(NULL), | 43 service_dbus_proxy_(NULL), |
44 url_(url), | 44 url_(url), |
45 shell_handle_(shell_handle.Pass()), | 45 service_provider_handle_(service_provider_handle.Pass()), |
46 keep_alive_(loader->context_) { | 46 keep_alive_(loader->context_) { |
47 base::PostTaskAndReplyWithResult( | 47 base::PostTaskAndReplyWithResult( |
48 loader_->context_->task_runners()->io_runner(), | 48 loader_->context_->task_runners()->io_runner(), |
49 FROM_HERE, | 49 FROM_HERE, |
50 base::Bind(&LoadContext::CreateChannelOnIOThread, | 50 base::Bind(&LoadContext::CreateChannelOnIOThread, |
51 base::Unretained(this)), | 51 base::Unretained(this)), |
52 base::Bind(&LoadContext::ConnectChannel, base::Unretained(this))); | 52 base::Bind(&LoadContext::ConnectChannel, base::Unretained(this))); |
53 } | 53 } |
54 | 54 |
55 virtual ~LoadContext() { | 55 virtual ~LoadContext() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 101 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
102 base::Bind(&LoadContext::ActivateService, base::Unretained(this))); | 102 base::Bind(&LoadContext::ActivateService, base::Unretained(this))); |
103 } | 103 } |
104 | 104 |
105 // Sends a ShellHandle over to the now-connected externally-running service, | 105 // Sends a ShellHandle over to the now-connected externally-running service, |
106 // using the Mojo ExternalService API. | 106 // using the Mojo ExternalService API. |
107 void ActivateService(dbus::Response* response) { | 107 void ActivateService(dbus::Response* response) { |
108 mojo::AllocationScope scope; | 108 mojo::AllocationScope scope; |
109 external_service_->Activate( | 109 external_service_->Activate( |
110 mojo::ScopedMessagePipeHandle( | 110 mojo::ScopedMessagePipeHandle( |
111 mojo::MessagePipeHandle(shell_handle_.release().value()))); | 111 mojo::MessagePipeHandle( |
| 112 service_provider_handle_.release().value()))); |
112 } | 113 } |
113 | 114 |
114 // Should the ExternalService disappear completely, destroy connection state. | 115 // Should the ExternalService disappear completely, destroy connection state. |
115 // NB: This triggers off of the service disappearing from | 116 // NB: This triggers off of the service disappearing from |
116 // DBus. Perhaps there's a way to watch at the Mojo layer instead, | 117 // DBus. Perhaps there's a way to watch at the Mojo layer instead, |
117 // and that would be superior? | 118 // and that would be superior? |
118 void HandleNameOwnerChanged(const std::string& old_owner, | 119 void HandleNameOwnerChanged(const std::string& old_owner, |
119 const std::string& new_owner) { | 120 const std::string& new_owner) { |
120 DCHECK(loader_->context_->task_runners()->ui_runner()-> | 121 DCHECK(loader_->context_->task_runners()->ui_runner()-> |
121 BelongsToCurrentThread()); | 122 BelongsToCurrentThread()); |
122 | 123 |
123 if (new_owner.empty()) { | 124 if (new_owner.empty()) { |
124 loader_->context_->task_runners()->ui_runner()->PostTask( | 125 loader_->context_->task_runners()->ui_runner()->PostTask( |
125 FROM_HERE, | 126 FROM_HERE, |
126 base::Bind(&DBusServiceLoader::ForgetService, | 127 base::Bind(&DBusServiceLoader::ForgetService, |
127 base::Unretained(loader_), url_)); | 128 base::Unretained(loader_), url_)); |
128 } | 129 } |
129 } | 130 } |
130 | 131 |
131 DBusServiceLoader* const loader_; | 132 DBusServiceLoader* const loader_; |
132 scoped_refptr<dbus::Bus> bus_; | 133 scoped_refptr<dbus::Bus> bus_; |
133 dbus::ObjectProxy* service_dbus_proxy_; // Owned by bus_; | 134 dbus::ObjectProxy* service_dbus_proxy_; // Owned by bus_; |
134 const GURL url_; | 135 const GURL url_; |
135 ScopedMessagePipeHandle shell_handle_; | 136 ScopedMessagePipeHandle service_provider_handle_; |
136 KeepAlive keep_alive_; | 137 KeepAlive keep_alive_; |
137 scoped_ptr<common::ChannelInit> channel_init_; | 138 scoped_ptr<common::ChannelInit> channel_init_; |
138 ExternalServicePtr external_service_; | 139 ExternalServicePtr external_service_; |
139 | 140 |
140 DISALLOW_COPY_AND_ASSIGN(LoadContext); | 141 DISALLOW_COPY_AND_ASSIGN(LoadContext); |
141 }; | 142 }; |
142 | 143 |
143 DBusServiceLoader::DBusServiceLoader(Context* context) : context_(context) { | 144 DBusServiceLoader::DBusServiceLoader(Context* context) : context_(context) { |
144 dbus::Bus::Options options; | 145 dbus::Bus::Options options; |
145 options.bus_type = dbus::Bus::SESSION; | 146 options.bus_type = dbus::Bus::SESSION; |
(...skipping 27 matching lines...) Expand all Loading... |
173 DCHECK(it != url_to_load_context_.end()) << url; | 174 DCHECK(it != url_to_load_context_.end()) << url; |
174 | 175 |
175 LoadContext* doomed = it->second; | 176 LoadContext* doomed = it->second; |
176 url_to_load_context_.erase(it); | 177 url_to_load_context_.erase(it); |
177 | 178 |
178 delete doomed; | 179 delete doomed; |
179 } | 180 } |
180 | 181 |
181 } // namespace shell | 182 } // namespace shell |
182 } // namespace mojo | 183 } // namespace mojo |
OLD | NEW |