Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: chromeos/dbus/console_service_client.cc

Issue 697493002: Support transition between chrome and user mode console (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DBUS API to support chrome/console transition Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "base/bind.h"
6 #include "chromeos/dbus/console_service_client.h"
7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "dbus/bus.h"
9 #include "dbus/exported_object.h"
10 #include "dbus/message.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
12
13 namespace chromeos {
14
15 ConsoleServiceClient* ConsoleServiceClient::instance = NULL;
stevenjb 2014/10/31 17:00:46 File local in anonymous namespace, 's_console_serv
dsodman 2014/10/31 17:54:34 Done.
16
17 class ConsoleServiceClientImpl : public ConsoleServiceClient {
stevenjb 2014/10/31 17:00:46 The implementation can also be in an anonymous nam
dsodman 2014/10/31 17:54:34 Done.
18 public:
19 ConsoleServiceClientImpl();
stevenjb 2014/10/31 17:00:46 This needs a destructor override.
dsodman 2014/10/31 17:54:34 Done.
20
21 void AddObserver(Observer* observer) override {
22 observers_.AddObserver(observer);
23 }
stevenjb 2014/10/31 17:00:46 With the exception of trivial accessors, it is bet
dsodman 2014/10/31 17:54:33 Done.
24
25 void RemoveObserver(Observer* observer) override {
26 observers_.RemoveObserver(observer);
27 }
28
29 bool HasObserver(Observer* observer) override {
30 return observers_.HasObserver(observer);
31 }
32
33 void OnOwnership(const std::string& service_name, bool success);
stevenjb 2014/10/31 17:00:46 Include a brief comment for each of these methods.
dsodman 2014/10/31 17:54:34 Done.
34
35 void OnExported(const std::string& interface_name,
36 const std::string& method_name,
37 bool success);
38
39 void ActivateConsole(dbus::MethodCall* method_call,
40 dbus::ExportedObject::ResponseSender response_sender);
41
42 protected:
43 virtual void Init(dbus::Bus* bus) override;
stevenjb 2014/10/31 17:00:46 No 'virtual' for overrides.
dsodman 2014/10/31 17:54:34 Done.
44
45 private:
46 dbus::Bus* bus_;
47 ObserverList<Observer> observers_;
48 scoped_refptr<dbus::ExportedObject> exported_object_;
49 base::WeakPtrFactory<ConsoleServiceClientImpl> weak_ptr_factory_;
50
51 DISALLOW_COPY_AND_ASSIGN(ConsoleServiceClientImpl);
52 };
53
54 void ConsoleServiceClientImpl::OnOwnership(const std::string& service_name,
stevenjb 2014/10/31 17:00:46 Ordering of method implementations should match de
dsodman 2014/10/31 17:54:34 Done.
55 bool success) {
56 LOG_IF(FATAL, !success) << "failed to own: " << service_name;
57 }
58
59 void ConsoleServiceClientImpl::OnExported(const std::string& interface_name,
60 const std::string& method_name,
61 bool success) {
62 if (!success) {
63 LOG(ERROR) << "failed to export " << interface_name << "." << method_name;
64 }
65 }
66
67 ConsoleServiceClientImpl::ConsoleServiceClientImpl() : weak_ptr_factory_(this) {
stevenjb 2014/10/31 17:00:46 bus_ needs to be initialized.
dsodman 2014/10/31 17:54:34 Done.
68 }
69
70 ConsoleServiceClient::ConsoleServiceClient() {
71 instance = this;
stevenjb 2014/10/31 17:00:46 CHECK_EQ(NULL, s_chonsole_service_client); ALso, b
dsodman 2014/10/31 17:54:34 Done.
72 }
73
74 ConsoleServiceClient* ConsoleServiceClient::Create() {
75 return new ConsoleServiceClientImpl();
76 }
77
78 ConsoleServiceClient* ConsoleServiceClient::GetInstance() {
79 return instance;
80 }
81
82 void ConsoleServiceClientImpl::ActivateConsole(
83 dbus::MethodCall* method_call,
84 dbus::ExportedObject::ResponseSender response_sender) {
85 dbus::MessageReader reader(method_call);
86 int console_id = 0;
87 if (reader.PopInt32(&console_id)) {
88 FOR_EACH_OBSERVER(Observer, observers_, OnActivateConsole(console_id));
89 } else {
90 LOG(ERROR) << "Unable to parse " << kActivateConsole << " request";
91 }
92 response_sender.Run(dbus::Response::FromMethodCall(method_call));
93 }
94
95 void ConsoleServiceClientImpl::Init(dbus::Bus* bus) {
96 LOG(ERROR) << "ConsoleServiceClientImpl::Init";
stevenjb 2014/10/31 17:00:46 VLOG
dsodman 2014/10/31 17:54:34 Done.
97 bus_ = DBusThreadManager::Get()->GetSystemBus();
98
99 if (!bus_) {
100 LOG(ERROR) << "Unable to get system d-bus for the ConsoleServiceClient";
101 return;
102 }
103
104 bus_->RequestOwnership(kConsoleServiceName,
105 dbus::Bus::REQUIRE_PRIMARY_ALLOW_REPLACEMENT,
106 base::Bind(&ConsoleServiceClientImpl::OnOwnership,
107 base::Unretained(this)));
108
109 exported_object_ = bus_->GetExportedObject(
110 dbus::ObjectPath(dbus::ObjectPath(kConsoleServicePath)));
111
112 exported_object_->ExportMethod(
113 kConsoleServiceInterface,
114 kActivateConsole,
115 base::Bind(&ConsoleServiceClientImpl::ActivateConsole,
116 weak_ptr_factory_.GetWeakPtr()),
117 base::Bind(&ConsoleServiceClientImpl::OnExported,
118 weak_ptr_factory_.GetWeakPtr()));
119 }
120
121 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698