Upstream version 6.35.132.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / linux / running_application_object.h
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 #ifndef XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_
6 #define XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_
7
8 #include <string>
9 #include "base/memory/ref_counted.h"
10 #include "dbus/bus.h"
11 #include "ipc/ipc_channel_handle.h"
12 #include "xwalk/application/browser/application.h"
13 #include "xwalk/dbus/object_manager_adaptor.h"
14
15 namespace dbus {
16 class FileDescriptor;
17 }
18
19 namespace xwalk {
20 namespace application {
21
22 // Represents the running application inside D-Bus hierarchy of
23 // RunningApplicationsManager.
24 //
25 // Watches for the D-Bus presence of the launcher, when it disappears (e.g. the
26 // launcher was ended by a task manager) will terminate the corresponding
27 // application in Crosswalk.
28 class RunningApplicationObject : public dbus::ManagedObject {
29  public:
30   RunningApplicationObject(scoped_refptr<dbus::Bus> bus,
31                            const std::string& app_id,
32                            const std::string& launcher_name,
33                            Application* application);
34
35   virtual ~RunningApplicationObject();
36
37   void ExtensionProcessCreated(const IPC::ChannelHandle& handle);
38
39  private:
40   void TerminateApplication(Application::TerminationMode mode);
41
42   void OnExported(const std::string& interface_name,
43                   const std::string& method_name,
44                   bool success);
45
46   void OnTerminate(Application::TerminationMode termination_mode,
47                    dbus::MethodCall* method_call,
48                    dbus::ExportedObject::ResponseSender response_sender);
49
50   void OnGetExtensionProcessChannel(
51       dbus::MethodCall* method_call,
52       dbus::ExportedObject::ResponseSender response_sender);
53
54 #if defined(OS_TIZEN)
55   void OnHide(dbus::MethodCall* method_call,
56               dbus::ExportedObject::ResponseSender response_sender);
57 #endif
58
59   void ListenForOwnerChange();
60   void UnlistenForOwnerChange();
61   void OnNameOwnerChanged(const std::string& service_owner);
62
63   void OnLauncherDisappeared();
64
65   scoped_ptr<dbus::FileDescriptor> CreateClientFileDescriptor();
66   void SendChannel(dbus::MethodCall* method_call,
67                    dbus::ExportedObject::ResponseSender response_sender,
68                    scoped_ptr<dbus::FileDescriptor> client_fd);
69
70   scoped_refptr<dbus::Bus> bus_;
71   std::string launcher_name_;
72   dbus::Bus::GetServiceOwnerCallback owner_change_callback_;
73   Application* application_;
74
75   IPC::ChannelHandle ep_bp_channel_;
76 };
77
78 }  // namespace application
79 }  // namespace xwalk
80
81 #endif  // XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_
82