Upstream version 10.39.225.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 <string>
8 #include "base/bind.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/threading/thread.h"
11 #include "dbus/bus.h"
12
13 namespace xwalk {
14
15 DBusManager::DBusManager() {}
16
17 DBusManager::~DBusManager() {
18   if (session_bus_.get())
19     session_bus_->ShutdownOnDBusThreadAndBlock();
20 }
21
22 scoped_refptr<dbus::Bus> DBusManager::session_bus() {
23   if (!session_bus_.get()) {
24     base::Thread::Options thread_options;
25     thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
26     std::string thread_name = "Crosswalk D-Bus thread";
27     dbus_thread_.reset(new base::Thread(thread_name.c_str()));
28     dbus_thread_->StartWithOptions(thread_options);
29
30     dbus::Bus::Options options;
31     options.dbus_task_runner = dbus_thread_->message_loop_proxy();
32
33     session_bus_ = new dbus::Bus(options);
34   }
35
36   return session_bus_;
37 }
38
39 }  // namespace xwalk