| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "dbus/bus.h" | 6 #include "dbus/bus.h" |
| 7 #include "dbus/exported_object.h" | 7 #include "dbus/exported_object.h" |
| 8 #include "dbus/message.h" | 8 #include "dbus/message.h" |
| 9 #include "dbus/object_path.h" | 9 #include "dbus/object_path.h" |
| 10 #include "mojo/embedder/channel_init.h" | 10 #include "mojo/embedder/channel_init.h" |
| 11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 14 #include "mojo/public/cpp/application/interface_factory.h" |
| 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 16 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 15 #include "mojo/shell/external_service.mojom.h" | 17 #include "mojo/shell/external_service.mojom.h" |
| 16 | 18 |
| 17 namespace mojo { | 19 namespace mojo { |
| 18 const char kMojoDBusImplPath[] = "/org/chromium/MojoImpl"; | 20 const char kMojoDBusImplPath[] = "/org/chromium/MojoImpl"; |
| 19 const char kMojoDBusInterface[] = "org.chromium.Mojo"; | 21 const char kMojoDBusInterface[] = "org.chromium.Mojo"; |
| 20 const char kMojoDBusConnectMethod[] = "ConnectChannel"; | 22 const char kMojoDBusConnectMethod[] = "ConnectChannel"; |
| 21 | 23 |
| 22 class DBusExternalServiceBase { | 24 class DBusExternalServiceBase { |
| 23 public: | 25 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 void TakeDBusServiceOwnership(); | 45 void TakeDBusServiceOwnership(); |
| 44 | 46 |
| 45 const std::string service_name_; | 47 const std::string service_name_; |
| 46 scoped_refptr<dbus::Bus> bus_; | 48 scoped_refptr<dbus::Bus> bus_; |
| 47 dbus::ExportedObject* exported_object_; // Owned by bus_; | 49 dbus::ExportedObject* exported_object_; // Owned by bus_; |
| 48 scoped_ptr<embedder::ChannelInit> channel_init_; | 50 scoped_ptr<embedder::ChannelInit> channel_init_; |
| 49 DISALLOW_COPY_AND_ASSIGN(DBusExternalServiceBase); | 51 DISALLOW_COPY_AND_ASSIGN(DBusExternalServiceBase); |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 template <class ServiceImpl> | 54 template <class ServiceImpl> |
| 53 class DBusExternalService : public DBusExternalServiceBase, | 55 class DBusExternalService |
| 54 public ApplicationDelegate { | 56 : public DBusExternalServiceBase, |
| 57 public ApplicationDelegate, |
| 58 public InterfaceFactory<typename ServiceImpl::ImplementedInterface> { |
| 55 public: | 59 public: |
| 56 explicit DBusExternalService(const std::string& service_name) | 60 explicit DBusExternalService(const std::string& service_name) |
| 57 : DBusExternalServiceBase(service_name) { | 61 : DBusExternalServiceBase(service_name) { |
| 58 } | 62 } |
| 59 virtual ~DBusExternalService() {} | 63 virtual ~DBusExternalService() {} |
| 60 | 64 |
| 61 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 62 MOJO_OVERRIDE { | 66 MOJO_OVERRIDE { |
| 63 connection->AddService<ServiceImpl>(); | 67 connection->AddService(this); |
| 64 return true; | 68 return true; |
| 65 } | 69 } |
| 66 | 70 |
| 71 virtual void Create( |
| 72 ApplicationConnection* connection, |
| 73 InterfaceRequest<typename ServiceImpl::ImplementedInterface> request) |
| 74 MOJO_OVERRIDE { |
| 75 BindToRequest(new ServiceImpl, &request); |
| 76 } |
| 77 |
| 67 protected: | 78 protected: |
| 68 virtual void Connect(ScopedMessagePipeHandle client_handle) OVERRIDE { | 79 virtual void Connect(ScopedMessagePipeHandle client_handle) OVERRIDE { |
| 69 external_service_.reset(BindToPipe(new Impl(this), client_handle.Pass())); | 80 external_service_.reset(BindToPipe(new Impl(this), client_handle.Pass())); |
| 70 } | 81 } |
| 71 | 82 |
| 72 virtual void Disconnect() OVERRIDE { | 83 virtual void Disconnect() OVERRIDE { |
| 73 external_service_.reset(); | 84 external_service_.reset(); |
| 74 } | 85 } |
| 75 | 86 |
| 76 private: | 87 private: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 } | 98 } |
| 88 private: | 99 private: |
| 89 DBusExternalService* service_; | 100 DBusExternalService* service_; |
| 90 scoped_ptr<Application> app_; | 101 scoped_ptr<Application> app_; |
| 91 }; | 102 }; |
| 92 | 103 |
| 93 scoped_ptr<Impl> external_service_; | 104 scoped_ptr<Impl> external_service_; |
| 94 }; | 105 }; |
| 95 | 106 |
| 96 } // namespace mojo | 107 } // namespace mojo |
| OLD | NEW |