Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_CRYPTAUTH_SECURE_CHANNEL_H_ | 5 #ifndef COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ |
| 6 #define COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ | 6 #define COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class Delegate { | 62 class Delegate { |
| 63 public: | 63 public: |
| 64 virtual ~Delegate(); | 64 virtual ~Delegate(); |
| 65 | 65 |
| 66 virtual std::unique_ptr<SecureMessageDelegate> | 66 virtual std::unique_ptr<SecureMessageDelegate> |
| 67 CreateSecureMessageDelegate() = 0; | 67 CreateSecureMessageDelegate() = 0; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 SecureChannel( | 70 class Factory { |
| 71 std::unique_ptr<Connection> connection, | 71 public: |
| 72 std::unique_ptr<Delegate> delegate); | 72 static std::unique_ptr<SecureChannel> NewInstance( |
| 73 std::unique_ptr<Connection> connection, | |
| 74 std::unique_ptr<Delegate> delegate); | |
| 75 | |
| 76 static void SetInstanceForTesting(Factory* factory); | |
| 77 | |
| 78 protected: | |
| 79 virtual std::unique_ptr<SecureChannel> BuildInstance( | |
| 80 std::unique_ptr<Connection> connection, | |
| 81 std::unique_ptr<Delegate> delegate); | |
| 82 | |
| 83 private: | |
| 84 static Factory* factory_instance_; | |
| 85 }; | |
| 86 | |
| 73 ~SecureChannel() override; | 87 ~SecureChannel() override; |
| 74 | 88 |
| 75 void Initialize(); | 89 virtual void Initialize(); |
| 76 | 90 |
| 77 void SendMessage(const std::string& feature, const std::string& payload); | 91 virtual void SendMessage( |
| 92 const std::string& feature, const std::string& payload); | |
| 78 | 93 |
| 79 void Disconnect(); | 94 virtual void Disconnect(); |
| 80 | 95 |
| 81 void AddObserver(Observer* observer); | 96 virtual void AddObserver(Observer* observer); |
| 82 void RemoveObserver(Observer* observer); | 97 virtual void RemoveObserver(Observer* observer); |
| 83 | 98 |
| 84 Status status() const { | 99 Status status() const { |
| 85 return status_; | 100 return status_; |
| 86 } | 101 } |
| 87 | 102 |
| 88 // ConnectionObserver: | 103 // ConnectionObserver: |
| 89 void OnConnectionStatusChanged(Connection* connection, | 104 void OnConnectionStatusChanged(Connection* connection, |
| 90 Connection::Status old_status, | 105 Connection::Status old_status, |
| 91 Connection::Status new_status) override; | 106 Connection::Status new_status) override; |
| 92 void OnMessageReceived(const Connection& connection, | 107 void OnMessageReceived(const Connection& connection, |
| 93 const WireMessage& wire_message) override; | 108 const WireMessage& wire_message) override; |
| 94 void OnSendCompleted(const cryptauth::Connection& connection, | 109 void OnSendCompleted(const cryptauth::Connection& connection, |
| 95 const cryptauth::WireMessage& wire_message, | 110 const cryptauth::WireMessage& wire_message, |
| 96 bool success) override; | 111 bool success) override; |
| 97 | 112 |
| 113 protected: | |
| 114 SecureChannel( | |
|
Ryan Hansberry
2017/02/14 18:27:28
nit: one level too indented
Kyle Horimoto
2017/02/14 22:54:46
Done.
| |
| 115 std::unique_ptr<Connection> connection, | |
| 116 std::unique_ptr<Delegate> delegate); | |
| 117 | |
| 118 Status status_; | |
| 119 | |
| 98 private: | 120 private: |
| 99 // Message waiting to be sent. Note that this is *not* the message that will | 121 // Message waiting to be sent. Note that this is *not* the message that will |
| 100 // end up being sent over the wire; before that can be done, the payload must | 122 // end up being sent over the wire; before that can be done, the payload must |
| 101 // be encrypted. | 123 // be encrypted. |
| 102 struct PendingMessage { | 124 struct PendingMessage { |
| 103 PendingMessage(); | 125 PendingMessage(); |
| 104 PendingMessage(const std::string& feature, const std::string& payload); | 126 PendingMessage(const std::string& feature, const std::string& payload); |
| 105 virtual ~PendingMessage(); | 127 virtual ~PendingMessage(); |
| 106 | 128 |
| 107 const std::string feature; | 129 const std::string feature; |
| 108 const std::string payload; | 130 const std::string payload; |
| 109 }; | 131 }; |
| 110 | 132 |
| 111 void TransitionToStatus(const Status& new_status); | 133 void TransitionToStatus(const Status& new_status); |
| 112 void Authenticate(); | 134 void Authenticate(); |
| 113 void ProcessMessageQueue(); | 135 void ProcessMessageQueue(); |
| 114 void OnMessageEncoded( | 136 void OnMessageEncoded( |
| 115 const std::string& feature, const std::string& encoded_message); | 137 const std::string& feature, const std::string& encoded_message); |
| 116 void OnMessageDecoded( | 138 void OnMessageDecoded( |
| 117 const std::string& feature, const std::string& decoded_message); | 139 const std::string& feature, const std::string& decoded_message); |
| 118 void OnAuthenticationResult( | 140 void OnAuthenticationResult( |
| 119 Authenticator::Result result, | 141 Authenticator::Result result, |
| 120 std::unique_ptr<SecureContext> secure_context); | 142 std::unique_ptr<SecureContext> secure_context); |
| 121 | 143 |
| 122 std::unique_ptr<Connection> connection_; | 144 std::unique_ptr<Connection> connection_; |
| 123 std::unique_ptr<Delegate> delegate_; | 145 std::unique_ptr<Delegate> delegate_; |
| 124 std::unique_ptr<Authenticator> authenticator_; | 146 std::unique_ptr<Authenticator> authenticator_; |
| 125 std::unique_ptr<SecureContext> secure_context_; | 147 std::unique_ptr<SecureContext> secure_context_; |
| 126 Status status_; | |
| 127 std::deque<PendingMessage> queued_messages_; | 148 std::deque<PendingMessage> queued_messages_; |
| 128 std::unique_ptr<PendingMessage> pending_message_; | 149 std::unique_ptr<PendingMessage> pending_message_; |
| 129 base::ObserverList<Observer> observer_list_; | 150 base::ObserverList<Observer> observer_list_; |
| 130 base::WeakPtrFactory<SecureChannel> weak_ptr_factory_; | 151 base::WeakPtrFactory<SecureChannel> weak_ptr_factory_; |
| 131 | 152 |
| 132 DISALLOW_COPY_AND_ASSIGN(SecureChannel); | 153 DISALLOW_COPY_AND_ASSIGN(SecureChannel); |
| 133 }; | 154 }; |
| 134 | 155 |
| 135 } // namespace cryptauth | 156 } // namespace cryptauth |
| 136 | 157 |
| 137 #endif // COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ | 158 #endif // COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ |
| OLD | NEW |