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_applications_manager.h"
17 namespace application {
19 ApplicationServiceProviderLinux::ApplicationServiceProviderLinux(
20 ApplicationService* app_service,
21 ApplicationStorage* app_storage,
22 scoped_refptr<dbus::Bus> session_bus)
23 : session_bus_(session_bus) {
24 installed_apps_.reset(new InstalledApplicationsManager(session_bus_,
27 running_apps_.reset(new RunningApplicationsManager(session_bus_,
30 // TODO(cmarcelo): This is just a placeholder to test D-Bus is working, remove
31 // once we exported proper objects.
34 // Auto activation waits for the service name to be registered, so we do this
35 // as the last step so all the object paths and interfaces are set.
36 session_bus_->RequestOwnership(
37 kXWalkDBusServiceName,
38 dbus::Bus::REQUIRE_PRIMARY,
39 base::Bind(&ApplicationServiceProviderLinux::OnServiceNameExported,
40 base::Unretained(this)));
43 ApplicationServiceProviderLinux::~ApplicationServiceProviderLinux() {}
45 void ApplicationServiceProviderLinux::OnServiceNameExported(
46 const std::string& service_name, bool success) {
48 LOG(ERROR) << "Couldn't own D-Bus service name: " << service_name;
51 VLOG(1) << "D-Bus service name exported.";
56 void OnExported(const std::string& interface_name,
57 const std::string& method_name,
60 LOG(WARNING) << "Couldn't export method '" + method_name
61 << "' from '" + interface_name + "'.";
65 void OnPing(dbus::MethodCall* method_call,
66 dbus::ExportedObject::ResponseSender response_sender) {
67 scoped_ptr<dbus::Response> response =
68 dbus::Response::FromMethodCall(method_call);
69 dbus::MessageWriter writer(response.get());
70 writer.AppendString("Pong");
71 response_sender.Run(response.Pass());
76 void ApplicationServiceProviderLinux::ExportTestObject() {
77 dbus::ExportedObject* object =
78 session_bus_->GetExportedObject(dbus::ObjectPath("/test"));
79 object->ExportMethod("org.crosswalkproject.TestInterface1", "Ping",
80 base::Bind(&OnPing), base::Bind(&OnExported));
83 } // namespace application