Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / xwalk / dbus / dbus_manager_tizen.cc
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.
4
5 #include "xwalk/dbus/dbus_manager.h"
6
7 #include <glib.h>
8 #include <string>
9 #include "base/bind.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/threading/thread.h"
12 #include "dbus/bus.h"
13
14 namespace xwalk {
15
16 DBusManager::DBusManager() {}
17
18 DBusManager::~DBusManager() {
19   if (session_bus_)
20     session_bus_->ShutdownOnDBusThreadAndBlock();
21 }
22
23 scoped_refptr<dbus::Bus> DBusManager::session_bus() {
24   if (!session_bus_) {
25     base::Thread::Options thread_options;
26     thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
27     std::string thread_name = "Crosswalk D-Bus thread";
28     dbus_thread_.reset(new base::Thread(thread_name.c_str()));
29     dbus_thread_->StartWithOptions(thread_options);
30
31     dbus::Bus::Options options;
32     options.dbus_task_runner = dbus_thread_->message_loop_proxy();
33
34     // On Tizen 2.x DBUS_SESSION_ADDRESS points to a wrong path, so we set
35     // the correct one here.
36     options.bus_type = dbus::Bus::CUSTOM_ADDRESS;
37     options.address = base::StringPrintf(
38         "unix:path=/run/user/%s/dbus/user_bus_socket", g_get_user_name());
39
40     session_bus_ = new dbus::Bus(options);
41   }
42
43   return session_bus_;
44 }
45
46 }  // namespace xwalk