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

Side by Side Diff: services/service_manager/public/cpp/lib/connection_impl.cc

Issue 2804373002: Eliminate Connector::Connect(), Connection, etc. (Closed)
Patch Set: . Created 3 years, 8 months 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 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 "services/service_manager/public/cpp/lib/connection_impl.h"
6
7 #include <stdint.h>
8
9 #include <utility>
10
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "services/service_manager/public/cpp/connection.h"
14 #include "services/service_manager/public/cpp/interface_binder.h"
15
16 namespace service_manager {
17 namespace internal {
18
19 ////////////////////////////////////////////////////////////////////////////////
20 // ConnectionImpl, public:
21
22 ConnectionImpl::ConnectionImpl()
23 : weak_factory_(this) {}
24
25 ConnectionImpl::ConnectionImpl(const Identity& remote, State initial_state)
26 : remote_(remote),
27 state_(initial_state),
28 weak_factory_(this) {
29 }
30
31 ConnectionImpl::~ConnectionImpl() {}
32
33 void ConnectionImpl::SetRemoteInterfaces(
34 std::unique_ptr<InterfaceProvider> remote_interfaces) {
35 remote_interfaces_owner_ = std::move(remote_interfaces);
36 set_remote_interfaces(remote_interfaces_owner_.get());
37 }
38
39 service_manager::mojom::Connector::ConnectCallback
40 ConnectionImpl::GetConnectCallback() {
41 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
42 weak_factory_.GetWeakPtr());
43 }
44
45 ////////////////////////////////////////////////////////////////////////////////
46 // ConnectionImpl, Connection implementation:
47
48 const Identity& ConnectionImpl::GetRemoteIdentity() const {
49 return remote_;
50 }
51
52 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
53 remote_interfaces_->SetConnectionLostClosure(handler);
54 }
55
56 service_manager::mojom::ConnectResult ConnectionImpl::GetResult() const {
57 return result_;
58 }
59
60 bool ConnectionImpl::IsPending() const {
61 return state_ == State::PENDING;
62 }
63
64 void ConnectionImpl::AddConnectionCompletedClosure(
65 const base::Closure& callback) {
66 if (IsPending())
67 connection_completed_callbacks_.push_back(callback);
68 else
69 callback.Run();
70 }
71
72 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
73 return remote_interfaces_;
74 }
75
76 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
77 return weak_factory_.GetWeakPtr();
78 }
79
80 ////////////////////////////////////////////////////////////////////////////////
81 // ConnectionImpl, private:
82
83 void ConnectionImpl::OnConnectionCompleted(
84 service_manager::mojom::ConnectResult result,
85 const std::string& target_user_id) {
86 DCHECK(State::PENDING == state_);
87
88 result_ = result;
89 state_ = result_ == service_manager::mojom::ConnectResult::SUCCEEDED
90 ? State::CONNECTED
91 : State::DISCONNECTED;
92 remote_.set_user_id(target_user_id);
93 std::vector<base::Closure> callbacks;
94 callbacks.swap(connection_completed_callbacks_);
95 for (auto callback : callbacks)
96 callback.Run();
97 }
98
99 } // namespace internal
100 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/connection_impl.h ('k') | services/service_manager/public/cpp/lib/connector_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698