[Extensions UI] Fix another chrome://extensions commands bug
[chromium-blink-merge.git] / chromeos / dbus / services / console_service_provider.cc
blob71a34794d1a61aabc8fb797ad03869ea358102a3
1 // Copyright 2014 The Chromium Authors. 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.
5 #include "chromeos/dbus/services/console_service_provider.h"
7 #include "base/bind.h"
8 #include "dbus/message.h"
9 #include "third_party/cros_system_api/dbus/service_constants.h"
11 namespace chromeos {
12 namespace {
14 void OnDisplayOwnershipChanged(
15 const dbus::ExportedObject::ResponseSender& response_sender,
16 scoped_ptr<dbus::Response> response,
17 bool status) {
18 dbus::MessageWriter writer(response.get());
19 writer.AppendBool(status);
20 response_sender.Run(response.Pass());
23 } // namespace
25 ConsoleServiceProvider::ConsoleServiceProvider(scoped_ptr<Delegate> delegate)
26 : delegate_(delegate.Pass()),
27 weak_ptr_factory_(this) {
30 ConsoleServiceProvider::~ConsoleServiceProvider() {
33 void ConsoleServiceProvider::Start(
34 scoped_refptr<dbus::ExportedObject> exported_object) {
35 exported_object->ExportMethod(
36 kLibCrosServiceInterface, kTakeDisplayOwnership,
37 base::Bind(&ConsoleServiceProvider::TakeDisplayOwnership,
38 weak_ptr_factory_.GetWeakPtr()),
39 base::Bind(&ConsoleServiceProvider::OnExported,
40 weak_ptr_factory_.GetWeakPtr()));
42 exported_object->ExportMethod(
43 kLibCrosServiceInterface, kReleaseDisplayOwnership,
44 base::Bind(&ConsoleServiceProvider::ReleaseDisplayOwnership,
45 weak_ptr_factory_.GetWeakPtr()),
46 base::Bind(&ConsoleServiceProvider::OnExported,
47 weak_ptr_factory_.GetWeakPtr()));
50 void ConsoleServiceProvider::TakeDisplayOwnership(
51 dbus::MethodCall* method_call,
52 dbus::ExportedObject::ResponseSender response_sender) {
53 delegate_->TakeDisplayOwnership(
54 base::Bind(&OnDisplayOwnershipChanged, response_sender,
55 base::Passed(dbus::Response::FromMethodCall(method_call))));
58 void ConsoleServiceProvider::ReleaseDisplayOwnership(
59 dbus::MethodCall* method_call,
60 dbus::ExportedObject::ResponseSender response_sender) {
61 delegate_->ReleaseDisplayOwnership(
62 base::Bind(&OnDisplayOwnershipChanged, response_sender,
63 base::Passed(dbus::Response::FromMethodCall(method_call))));
66 void ConsoleServiceProvider::OnExported(const std::string& interface_name,
67 const std::string& method_name,
68 bool success) {
69 if (!success)
70 LOG(ERROR) << "failed to export " << interface_name << "." << method_name;
73 } // namespace chromeos