OLD | NEW |
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 #ifndef COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H |
6 #define COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H | 6 #define COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "components/proximity_auth/connection_observer.h" | 14 #include "components/proximity_auth/connection_observer.h" |
15 #include "components/proximity_auth/messenger.h" | 15 #include "components/proximity_auth/messenger.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } | 19 } |
20 | 20 |
21 namespace proximity_auth { | 21 namespace proximity_auth { |
22 | 22 |
23 class Connection; | 23 class Connection; |
24 class SecureContext; | 24 class SecureContext; |
25 | 25 |
26 // Concrete implementation of the Messenger interface. | 26 // Concrete implementation of the Messenger interface. |
27 class MessengerImpl : public Messenger, public ConnectionObserver { | 27 class MessengerImpl : public Messenger, public ConnectionObserver { |
28 public: | 28 public: |
29 // Constructs a messenger that sends and receives messages over the given | 29 // Constructs a messenger that sends and receives messages over the given |
30 // |connection|, using the |secure_context| to encrypt and decrypt the | 30 // |connection|, using the |secure_context| to encrypt and decrypt the |
31 // messages. The |connection| must be connected. The messenger begins | 31 // messages. The |connection| must be connected. The messenger begins |
32 // observing messages as soon as it is constructed. | 32 // observing messages as soon as it is constructed. |
33 MessengerImpl(scoped_ptr<Connection> connection, | 33 MessengerImpl(std::unique_ptr<Connection> connection, |
34 scoped_ptr<SecureContext> secure_context); | 34 std::unique_ptr<SecureContext> secure_context); |
35 ~MessengerImpl() override; | 35 ~MessengerImpl() override; |
36 | 36 |
37 // Messenger: | 37 // Messenger: |
38 void AddObserver(MessengerObserver* observer) override; | 38 void AddObserver(MessengerObserver* observer) override; |
39 void RemoveObserver(MessengerObserver* observer) override; | 39 void RemoveObserver(MessengerObserver* observer) override; |
40 bool SupportsSignIn() const override; | 40 bool SupportsSignIn() const override; |
41 void DispatchUnlockEvent() override; | 41 void DispatchUnlockEvent() override; |
42 void RequestDecryption(const std::string& challenge) override; | 42 void RequestDecryption(const std::string& challenge) override; |
43 void RequestUnlock() override; | 43 void RequestUnlock() override; |
44 SecureContext* GetSecureContext() const override; | 44 SecureContext* GetSecureContext() const override; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void OnConnectionStatusChanged(Connection* connection, | 92 void OnConnectionStatusChanged(Connection* connection, |
93 Connection::Status old_status, | 93 Connection::Status old_status, |
94 Connection::Status new_status) override; | 94 Connection::Status new_status) override; |
95 void OnMessageReceived(const Connection& connection, | 95 void OnMessageReceived(const Connection& connection, |
96 const WireMessage& wire_message) override; | 96 const WireMessage& wire_message) override; |
97 void OnSendCompleted(const Connection& connection, | 97 void OnSendCompleted(const Connection& connection, |
98 const WireMessage& wire_message, | 98 const WireMessage& wire_message, |
99 bool success) override; | 99 bool success) override; |
100 | 100 |
101 // The connection used to send and receive events and status updates. | 101 // The connection used to send and receive events and status updates. |
102 scoped_ptr<Connection> connection_; | 102 std::unique_ptr<Connection> connection_; |
103 | 103 |
104 // Used to encrypt and decrypt payloads sent and received over the | 104 // Used to encrypt and decrypt payloads sent and received over the |
105 // |connection_|. | 105 // |connection_|. |
106 scoped_ptr<SecureContext> secure_context_; | 106 std::unique_ptr<SecureContext> secure_context_; |
107 | 107 |
108 // The registered observers of |this_| messenger. | 108 // The registered observers of |this_| messenger. |
109 base::ObserverList<MessengerObserver> observers_; | 109 base::ObserverList<MessengerObserver> observers_; |
110 | 110 |
111 // Queue of messages to send to the remote device. | 111 // Queue of messages to send to the remote device. |
112 std::deque<PendingMessage> queued_messages_; | 112 std::deque<PendingMessage> queued_messages_; |
113 | 113 |
114 // The current message being sent or waiting on the remote device for a | 114 // The current message being sent or waiting on the remote device for a |
115 // response. Null if there is no message currently in this state. | 115 // response. Null if there is no message currently in this state. |
116 scoped_ptr<PendingMessage> pending_message_; | 116 std::unique_ptr<PendingMessage> pending_message_; |
117 | 117 |
118 base::WeakPtrFactory<MessengerImpl> weak_ptr_factory_; | 118 base::WeakPtrFactory<MessengerImpl> weak_ptr_factory_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(MessengerImpl); | 120 DISALLOW_COPY_AND_ASSIGN(MessengerImpl); |
121 }; | 121 }; |
122 | 122 |
123 } // namespace proximity_auth | 123 } // namespace proximity_auth |
124 | 124 |
125 #endif // COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H | 125 #endif // COMPONENTS_PROXIMITY_AUTH_MESSENGER_IMPL_H |
OLD | NEW |