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/installed_applications_manager.h"
14 #include "xwalk/application/browser/linux/running_application_object.h"
15 #include "xwalk/application/browser/linux/running_applications_manager.h"
18 namespace application {
20 ApplicationServiceProviderLinux::ApplicationServiceProviderLinux(
21 ApplicationService* app_service,
22 ApplicationStorage* app_storage,
23 scoped_refptr<dbus::Bus> session_bus)
24 : session_bus_(session_bus) {
25 installed_apps_.reset(new InstalledApplicationsManager(session_bus_,
28 running_apps_.reset(new RunningApplicationsManager(session_bus_,
31 // TODO(cmarcelo): This is just a placeholder to test D-Bus is working, remove
32 // once we exported proper objects.
35 // Auto activation waits for the service name to be registered, so we do this
36 // as the last step so all the object paths and interfaces are set.
37 session_bus_->RequestOwnership(
38 kXWalkDBusServiceName,
39 dbus::Bus::REQUIRE_PRIMARY,
40 base::Bind(&ApplicationServiceProviderLinux::OnServiceNameExported,
41 base::Unretained(this)));
44 ApplicationServiceProviderLinux::~ApplicationServiceProviderLinux() {}
46 RunningApplicationObject*
47 ApplicationServiceProviderLinux::GetRunningApplicationObject(
48 const Application* app) {
49 return running_apps_->GetRunningApp(app->id());
52 void ApplicationServiceProviderLinux::OnServiceNameExported(
53 const std::string& service_name, bool success) {
55 LOG(ERROR) << "Couldn't own D-Bus service name: " << service_name;
58 VLOG(1) << "D-Bus service name exported.";
63 void OnExported(const std::string& interface_name,
64 const std::string& method_name,
67 LOG(WARNING) << "Couldn't export method '" + method_name
68 << "' from '" + interface_name + "'.";
72 void OnPing(dbus::MethodCall* method_call,
73 dbus::ExportedObject::ResponseSender response_sender) {
74 scoped_ptr<dbus::Response> response =
75 dbus::Response::FromMethodCall(method_call);
76 dbus::MessageWriter writer(response.get());
77 writer.AppendString("Pong");
78 response_sender.Run(response.Pass());
83 void ApplicationServiceProviderLinux::ExportTestObject() {
84 dbus::ExportedObject* object =
85 session_bus_->GetExportedObject(dbus::ObjectPath("/test"));
86 object->ExportMethod("org.crosswalkproject.TestInterface1", "Ping",
87 base::Bind(&OnPing), base::Bind(&OnExported));
90 } // namespace application