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

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

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 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/shell/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/shell/public/cpp/connection.h"
14 #include "services/shell/public/cpp/interface_binder.h"
15
16 namespace shell {
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 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() {
40 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
41 weak_factory_.GetWeakPtr());
42 }
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // ConnectionImpl, Connection implementation:
46
47 const Identity& ConnectionImpl::GetRemoteIdentity() const {
48 return remote_;
49 }
50
51 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
52 remote_interfaces_->SetConnectionLostClosure(handler);
53 }
54
55 shell::mojom::ConnectResult ConnectionImpl::GetResult() const {
56 return result_;
57 }
58
59 bool ConnectionImpl::IsPending() const {
60 return state_ == State::PENDING;
61 }
62
63 void ConnectionImpl::AddConnectionCompletedClosure(
64 const base::Closure& callback) {
65 if (IsPending())
66 connection_completed_callbacks_.push_back(callback);
67 else
68 callback.Run();
69 }
70
71 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
72 return remote_interfaces_;
73 }
74
75 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
76 return weak_factory_.GetWeakPtr();
77 }
78
79 ////////////////////////////////////////////////////////////////////////////////
80 // ConnectionImpl, private:
81
82 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result,
83 const std::string& target_user_id) {
84 DCHECK(State::PENDING == state_);
85
86 result_ = result;
87 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ?
88 State::CONNECTED : State::DISCONNECTED;
89 remote_.set_user_id(target_user_id);
90 std::vector<base::Closure> callbacks;
91 callbacks.swap(connection_completed_callbacks_);
92 for (auto callback : callbacks)
93 callback.Run();
94 }
95
96 } // namespace internal
97 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/connection_impl.h ('k') | services/shell/public/cpp/lib/connector_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698