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

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

Issue 2420253002: Rename shell namespace to service_manager (Closed)
Patch Set: . 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/service_manager/public/cpp/lib/connection_impl.h" 5 #include "services/service_manager/public/cpp/lib/connection_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "services/service_manager/public/cpp/connection.h" 13 #include "services/service_manager/public/cpp/connection.h"
14 #include "services/service_manager/public/cpp/interface_binder.h" 14 #include "services/service_manager/public/cpp/interface_binder.h"
15 15
16 namespace shell { 16 namespace service_manager {
17 namespace internal { 17 namespace internal {
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 // ConnectionImpl, public: 20 // ConnectionImpl, public:
21 21
22 ConnectionImpl::ConnectionImpl() 22 ConnectionImpl::ConnectionImpl()
23 : weak_factory_(this) {} 23 : weak_factory_(this) {}
24 24
25 ConnectionImpl::ConnectionImpl(const Identity& remote, State initial_state) 25 ConnectionImpl::ConnectionImpl(const Identity& remote, State initial_state)
26 : remote_(remote), 26 : remote_(remote),
27 state_(initial_state), 27 state_(initial_state),
28 weak_factory_(this) { 28 weak_factory_(this) {
29 } 29 }
30 30
31 ConnectionImpl::~ConnectionImpl() {} 31 ConnectionImpl::~ConnectionImpl() {}
32 32
33 void ConnectionImpl::SetRemoteInterfaces( 33 void ConnectionImpl::SetRemoteInterfaces(
34 std::unique_ptr<InterfaceProvider> remote_interfaces) { 34 std::unique_ptr<InterfaceProvider> remote_interfaces) {
35 remote_interfaces_owner_ = std::move(remote_interfaces); 35 remote_interfaces_owner_ = std::move(remote_interfaces);
36 set_remote_interfaces(remote_interfaces_owner_.get()); 36 set_remote_interfaces(remote_interfaces_owner_.get());
37 } 37 }
38 38
39 shell::mojom::Connector::ConnectCallback ConnectionImpl::GetConnectCallback() { 39 service_manager::mojom::Connector::ConnectCallback
40 ConnectionImpl::GetConnectCallback() {
40 return base::Bind(&ConnectionImpl::OnConnectionCompleted, 41 return base::Bind(&ConnectionImpl::OnConnectionCompleted,
41 weak_factory_.GetWeakPtr()); 42 weak_factory_.GetWeakPtr());
42 } 43 }
43 44
44 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
45 // ConnectionImpl, Connection implementation: 46 // ConnectionImpl, Connection implementation:
46 47
47 const Identity& ConnectionImpl::GetRemoteIdentity() const { 48 const Identity& ConnectionImpl::GetRemoteIdentity() const {
48 return remote_; 49 return remote_;
49 } 50 }
50 51
51 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) { 52 void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
52 remote_interfaces_->SetConnectionLostClosure(handler); 53 remote_interfaces_->SetConnectionLostClosure(handler);
53 } 54 }
54 55
55 shell::mojom::ConnectResult ConnectionImpl::GetResult() const { 56 service_manager::mojom::ConnectResult ConnectionImpl::GetResult() const {
56 return result_; 57 return result_;
57 } 58 }
58 59
59 bool ConnectionImpl::IsPending() const { 60 bool ConnectionImpl::IsPending() const {
60 return state_ == State::PENDING; 61 return state_ == State::PENDING;
61 } 62 }
62 63
63 void ConnectionImpl::AddConnectionCompletedClosure( 64 void ConnectionImpl::AddConnectionCompletedClosure(
64 const base::Closure& callback) { 65 const base::Closure& callback) {
65 if (IsPending()) 66 if (IsPending())
66 connection_completed_callbacks_.push_back(callback); 67 connection_completed_callbacks_.push_back(callback);
67 else 68 else
68 callback.Run(); 69 callback.Run();
69 } 70 }
70 71
71 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() { 72 InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
72 return remote_interfaces_; 73 return remote_interfaces_;
73 } 74 }
74 75
75 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { 76 base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
76 return weak_factory_.GetWeakPtr(); 77 return weak_factory_.GetWeakPtr();
77 } 78 }
78 79
79 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
80 // ConnectionImpl, private: 81 // ConnectionImpl, private:
81 82
82 void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result, 83 void ConnectionImpl::OnConnectionCompleted(
83 const std::string& target_user_id) { 84 service_manager::mojom::ConnectResult result,
85 const std::string& target_user_id) {
84 DCHECK(State::PENDING == state_); 86 DCHECK(State::PENDING == state_);
85 87
86 result_ = result; 88 result_ = result;
87 state_ = result_ == shell::mojom::ConnectResult::SUCCEEDED ? 89 state_ = result_ == service_manager::mojom::ConnectResult::SUCCEEDED
88 State::CONNECTED : State::DISCONNECTED; 90 ? State::CONNECTED
91 : State::DISCONNECTED;
89 remote_.set_user_id(target_user_id); 92 remote_.set_user_id(target_user_id);
90 std::vector<base::Closure> callbacks; 93 std::vector<base::Closure> callbacks;
91 callbacks.swap(connection_completed_callbacks_); 94 callbacks.swap(connection_completed_callbacks_);
92 for (auto callback : callbacks) 95 for (auto callback : callbacks)
93 callback.Run(); 96 callback.Run();
94 } 97 }
95 98
96 } // namespace internal 99 } // namespace internal
97 } // namespace shell 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