This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 651
[Tizen] Refactor XWalkLauncher for usage of RESET event. #2563
Merged
pozdnyakov
merged 1 commit into
crosswalk-project:master
from
jakegeno:launcher-reset-event
Dec 10, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
// Copyright (c) 2013 Intel Corporation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "xwalk/application/tools/linux/dbus_object_manager.h" | ||
|
||
#include "base/message_loop/message_loop.h" | ||
|
||
namespace { | ||
|
||
const char kServiceName[] = "org.crosswalkproject.Runtime1"; | ||
const char kRunningManagerIface[] = "org.crosswalkproject.Running.Manager1"; | ||
const char kRunningAppIface[] = "org.crosswalkproject.Running.Application1"; | ||
const char kRunningManagerDBusPath[] = "/running1"; | ||
const char kEPChannelCreatedSignalName[] = "EPChannelCreated"; | ||
|
||
struct Properties : public dbus::PropertySet { | ||
dbus::Property<std::string> app_id; | ||
|
||
Properties(dbus::ObjectProxy* object_proxy, | ||
const std::string& interface_name, | ||
PropertyChangedCallback property_changed_callback) | ||
: PropertySet(object_proxy, interface_name, property_changed_callback) { | ||
RegisterProperty("AppID", &app_id); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
DBusObjectManager::DBusObjectManager(dbus::Bus* bus, | ||
base::MessageLoop* main_loop) | ||
: bus_(bus), | ||
main_loop_(main_loop), | ||
weak_ptr_factory_(this) { | ||
ConnectToApplicationManager(); | ||
} | ||
|
||
bool DBusObjectManager::Launch(const std::string& appid_or_url, | ||
int launcher_pid, bool fullscreen, bool remote_debugging) { | ||
if (!running_proxy_) | ||
return false; | ||
dbus::MethodCall method_call( | ||
kRunningManagerIface, "Launch"); | ||
dbus::MessageWriter writer(&method_call); | ||
writer.AppendString(appid_or_url); | ||
writer.AppendUint32(launcher_pid); | ||
writer.AppendBool(fullscreen); | ||
writer.AppendBool(remote_debugging); | ||
scoped_ptr<dbus::Response> response( | ||
running_proxy_->CallMethodAndBlock(&method_call, | ||
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | ||
if (!response.get()) | ||
return false; | ||
if (!response->GetErrorName().empty()) { | ||
LOG(ERROR) << "Error during call to 'Launch': " | ||
<< response->GetErrorName(); | ||
return false; | ||
} | ||
|
||
dbus::MessageReader reader(response.get()); | ||
dbus::ObjectPath running_application_path; | ||
if (!reader.PopObjectPath(&running_application_path)) { | ||
LOG(WARNING) << "Failed to create app proxy."; | ||
} else { | ||
app_proxy_ = bus_->GetObjectProxy(kServiceName, running_application_path); | ||
if (app_proxy_) | ||
ConnectToApplicationSignal(kEPChannelCreatedSignalName); | ||
} | ||
return true; | ||
} | ||
|
||
std::pair<std::string, int> DBusObjectManager::GetEPChannel() const { | ||
std::pair<std::string, int> fd; | ||
if (!app_proxy_) { | ||
fd.second = -1; | ||
return fd; | ||
} | ||
dbus::MethodCall method_call(kRunningAppIface, "GetEPChannel"); | ||
scoped_ptr<dbus::Response> response = app_proxy_->CallMethodAndBlock( | ||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | ||
const std::string& error = response->GetErrorName(); | ||
if (!error.empty()) { | ||
LOG(ERROR) << "Error during call to 'GetEPChannel': " | ||
<< error; | ||
fd.second = -1; | ||
return fd; | ||
} | ||
dbus::MessageReader reader(response.release()); | ||
dbus::FileDescriptor extension_process_fd_; | ||
if (!reader.PopString(&fd.first) || | ||
!reader.PopFileDescriptor(&extension_process_fd_)) { | ||
LOG(ERROR) << "Couldn't get EP Channel"; | ||
fd.second = -1; | ||
return fd; | ||
} | ||
extension_process_fd_.CheckValidity(); | ||
fd.second = extension_process_fd_.TakeValue(); | ||
return fd; | ||
} | ||
|
||
bool DBusObjectManager::Suspend() { | ||
if (!app_proxy_) | ||
return false; | ||
dbus::MethodCall method_call(kRunningAppIface, "Suspend"); | ||
scoped_ptr<dbus::Response> response = app_proxy_->CallMethodAndBlock( | ||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | ||
if (!response->GetErrorName().empty()) { | ||
LOG(ERROR) << "Error during call to 'Suspend': " | ||
<< response->GetErrorName(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool DBusObjectManager::Resume() { | ||
if (!app_proxy_) | ||
return false; | ||
dbus::MethodCall method_call(kRunningAppIface, "Resume"); | ||
scoped_ptr<dbus::Response> response = app_proxy_->CallMethodAndBlock( | ||
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | ||
if (!response->GetErrorName().empty()) { | ||
LOG(ERROR) << "Error during call to 'Resume': " | ||
<< response->GetErrorName(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void DBusObjectManager::OnOwnershipCallback(const std::string& service_name, | ||
bool success) { | ||
LOG(WARNING) << "Couldn't get ownership of D-Bus service name: " | ||
<< service_name << "."; | ||
} | ||
|
||
void DBusObjectManager::ConnectToApplicationManager() { | ||
running_apps_manager_ = bus_->GetObjectManager(kServiceName, | ||
dbus::ObjectPath(kRunningManagerDBusPath)); | ||
running_apps_manager_->RegisterInterface(kRunningAppIface, this); | ||
running_proxy_ = bus_->GetObjectProxy(kServiceName, | ||
dbus::ObjectPath(kRunningManagerDBusPath)); | ||
} | ||
|
||
void DBusObjectManager::ObjectAdded(const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) { | ||
} | ||
|
||
void DBusObjectManager::ObjectRemoved(const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) { | ||
if (object_path != app_proxy_->object_path()) | ||
return; | ||
LOG(INFO) << "Application '" << object_path.value() | ||
<< "' disappeared, exiting."; | ||
main_loop_->QuitNow(); | ||
} | ||
|
||
dbus::PropertySet* DBusObjectManager::CreateProperties( | ||
dbus::ObjectProxy *object_proxy, | ||
const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) { | ||
Properties* properties = new Properties( | ||
object_proxy, interface_name, | ||
base::Bind(&DBusObjectManager::OnPropertyChanged, | ||
base::Unretained(this), object_path)); | ||
return static_cast<dbus::PropertySet*>(properties); | ||
} | ||
|
||
void DBusObjectManager::OnPropertyChanged(const dbus::ObjectPath& object_path, | ||
const std::string& name) { | ||
if (!running_apps_manager_) | ||
ConnectToApplicationManager(); | ||
} | ||
|
||
void DBusObjectManager::ConnectToApplicationSignal( | ||
const std::string& signal_name) { | ||
DCHECK(app_proxy_); | ||
app_proxy_->ConnectToSignal(kRunningAppIface, signal_name, | ||
base::Bind(&DBusObjectManager::OnAppSignal, | ||
weak_ptr_factory_.GetWeakPtr()), | ||
base::Bind(&DBusObjectManager::OnAppSignalConnected, | ||
weak_ptr_factory_.GetWeakPtr())); | ||
} | ||
|
||
bool DBusObjectManager::IsApplicationRunning(const std::string& app_id) { | ||
std::vector<dbus::ObjectPath> objects = running_apps_manager_->GetObjects(); | ||
bool is_running = false; | ||
for (dbus::ObjectPath obj : objects) { | ||
Properties* properties = | ||
static_cast<Properties*>( | ||
running_apps_manager_->GetProperties( | ||
obj, kRunningAppIface)); | ||
if (!properties) | ||
continue; | ||
if (properties->app_id.value() == app_id) { | ||
is_running = true; | ||
break; | ||
} | ||
} | ||
LOG(INFO) << "Application " << app_id << " is " | ||
<< (is_running ? "running." : "not running."); | ||
return is_running; | ||
} | ||
|
||
void DBusObjectManager::OnAppSignal(dbus::Signal* signal) { | ||
std::string signal_name = signal->GetMember(); | ||
if (signal_name == kEPChannelCreatedSignalName) { | ||
if (observer_) | ||
observer_->OnEPChannelCreated(); | ||
} else { | ||
LOG(INFO) << "Unknown signal received: " << signal_name; | ||
} | ||
} | ||
|
||
void DBusObjectManager::OnAppSignalConnected( | ||
const std::string& interface_name, | ||
const std::string& signal_name, | ||
bool success) { | ||
if (!success) | ||
LOG(WARNING) << "Failed to connect signal: " << signal_name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2013 Intel Corporation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_ | ||
#define XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_ | ||
|
||
#include <map> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "base/macros.h" | ||
#include "base/threading/thread.h" | ||
#include "base/values.h" | ||
#include "dbus/bus.h" | ||
#include "dbus/exported_object.h" | ||
#include "dbus/message.h" | ||
#include "dbus/object_manager.h" | ||
#include "dbus/object_path.h" | ||
#include "dbus/object_proxy.h" | ||
#include "dbus/property.h" | ||
|
||
class DBusObjectManager : public dbus::ObjectManager::Interface { | ||
public: | ||
class Observer { | ||
public: | ||
virtual void OnEPChannelCreated() = 0; | ||
|
||
protected: | ||
virtual ~Observer() {} | ||
}; | ||
|
||
DBusObjectManager(dbus::Bus* bus, base::MessageLoop* main_loop); | ||
|
||
bool Launch(const std::string& appid_or_url, int launcher_pid, | ||
bool fullscreen, bool remote_debugging); | ||
std::pair<std::string, int> GetEPChannel() const; | ||
bool Suspend(); | ||
bool Resume(); | ||
|
||
bool IsApplicationRunning(const std::string& app_id); | ||
|
||
void SetObserver(Observer* observer) { observer_ = observer; } | ||
|
||
private: | ||
void OnOwnershipCallback(const std::string& service_name, bool success); | ||
void ObjectAdded(const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) override; | ||
void ObjectRemoved(const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) override; | ||
dbus::PropertySet* CreateProperties( | ||
dbus::ObjectProxy* object_proxy, | ||
const dbus::ObjectPath& object_path, | ||
const std::string& interface_name) override; | ||
|
||
void OnPropertyChanged(const dbus::ObjectPath& object_path, | ||
const std::string& name); | ||
|
||
void ConnectToApplicationManager(); | ||
void ConnectToApplicationSignal(const std::string& signal_name); | ||
void OnAppSignal(dbus::Signal* signal); | ||
void OnAppSignalConnected(const std::string& interface_name, | ||
const std::string& signal_name, | ||
bool success); | ||
|
||
scoped_refptr<dbus::Bus> bus_; | ||
dbus::ObjectManager* running_apps_manager_; | ||
dbus::ObjectProxy* running_proxy_; | ||
dbus::ObjectProxy* app_proxy_; | ||
|
||
// this is needed for exit events which come via dbus interface | ||
base::MessageLoop* main_loop_; | ||
|
||
base::WeakPtrFactory<DBusObjectManager> weak_ptr_factory_; | ||
|
||
Observer* observer_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DBusObjectManager); | ||
}; | ||
|
||
#endif // XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected:
virtual ~Observer() {}