cf067f67e6098ae9bab873041a975f933a095636
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / linux / installed_application_object.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/application/browser/linux/installed_application_object.h"
6
7 #include "dbus/bus.h"
8 #include "dbus/message.h"
9 #include "xwalk/application/common/application_data.h"
10
11 namespace xwalk {
12 namespace application {
13
14 // D-Bus Interface implemented by objects that represent installed
15 // applications.
16 //
17 // Methods:
18 //
19 //   Uninstall()
20 //     Will uninstall the application. This object will be unregistered from
21 //     D-Bus.
22 //
23 // Properties:
24 //
25 //   readonly string AppID
26 //   readonly string Name
27 const char kInstalledApplicationDBusInterface[] =
28     "org.crosswalkproject.Installed.Application1";
29
30 const char kInstalledApplicationDBusError[] =
31     "org.crosswalkproject.Installed.Application.Error";
32
33 InstalledApplicationObject::InstalledApplicationObject(
34     scoped_refptr<dbus::Bus> bus, const dbus::ObjectPath& path,
35     const ApplicationData* app)
36     : dbus::ManagedObject(bus, path),
37       app_id_(app->ID()) {
38   scoped_ptr<base::Value> app_id(base::Value::CreateStringValue(app->ID()));
39   properties()->Set(kInstalledApplicationDBusInterface, "AppID", app_id.Pass());
40
41   scoped_ptr<base::Value> name(base::Value::CreateStringValue(app->Name()));
42   properties()->Set(kInstalledApplicationDBusInterface, "Name", name.Pass());
43 }
44
45 void InstalledApplicationObject::OnApplicationNameChanged(
46     const std::string& app_name) {
47   scoped_ptr<base::Value> name(base::Value::CreateStringValue(app_name));
48   properties()->Set(kInstalledApplicationDBusInterface, "Name", name.Pass());
49 }
50
51 void InstalledApplicationObject::ExportUninstallMethod(
52     dbus::ExportedObject::MethodCallCallback method_call_callback,
53     dbus::ExportedObject::OnExportedCallback on_exported_callback) {
54   dbus_object()->ExportMethod(
55       kInstalledApplicationDBusInterface, "Uninstall",
56       method_call_callback, on_exported_callback);
57 }
58
59 }  // namespace application
60 }  // namespace xwalk