1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/application/browser/application_service_provider_linux.h"
10 #include "dbus/exported_object.h"
11 #include "dbus/message.h"
12 #include "xwalk/dbus/xwalk_service_name.h"
13 #include "xwalk/application/browser/linux/running_application_object.h"
14 #include "xwalk/application/browser/linux/running_applications_manager.h"
17 namespace application {
19 ApplicationServiceProviderLinux::ApplicationServiceProviderLinux(
20 ApplicationService* app_service,
21 scoped_refptr<dbus::Bus> session_bus)
22 : session_bus_(session_bus) {
23 running_apps_.reset(new RunningApplicationsManager(session_bus_,
26 // TODO(cmarcelo): This is just a placeholder to test D-Bus is working, remove
27 // once we exported proper objects.
30 // Auto activation waits for the service name to be registered, so we do this
31 // as the last step so all the object paths and interfaces are set.
32 session_bus_->RequestOwnership(
33 kXWalkDBusServiceName,
34 dbus::Bus::REQUIRE_PRIMARY,
35 base::Bind(&ApplicationServiceProviderLinux::OnServiceNameExported,
36 base::Unretained(this)));
39 ApplicationServiceProviderLinux::~ApplicationServiceProviderLinux() {}
41 RunningApplicationObject*
42 ApplicationServiceProviderLinux::GetRunningApplicationObject(
43 const Application* app) {
44 return running_apps_->GetRunningApp(app->id());
47 void ApplicationServiceProviderLinux::OnServiceNameExported(
48 const std::string& service_name, bool success) {
50 LOG(ERROR) << "Couldn't own D-Bus service name: " << service_name;
53 VLOG(1) << "D-Bus service name exported.";
58 void OnExported(const std::string& interface_name,
59 const std::string& method_name,
62 LOG(WARNING) << "Couldn't export method '" + method_name
63 << "' from '" + interface_name + "'.";
67 void OnPing(dbus::MethodCall* method_call,
68 dbus::ExportedObject::ResponseSender response_sender) {
69 scoped_ptr<dbus::Response> response =
70 dbus::Response::FromMethodCall(method_call);
71 dbus::MessageWriter writer(response.get());
72 writer.AppendString("Pong");
73 response_sender.Run(response.Pass());
78 void ApplicationServiceProviderLinux::ExportTestObject() {
79 dbus::ExportedObject* object =
80 session_bus_->GetExportedObject(dbus::ObjectPath("/test"));
81 object->ExportMethod("org.crosswalkproject.TestInterface1", "Ping",
82 base::Bind(&OnPing), base::Bind(&OnExported));
85 } // namespace application