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

Side by Side Diff: components/cryptauth/secure_channel.h

Issue 2697763002: [CrOS Tether]: Create BleConnectionManager, which manages secure connections between the current de… (Closed)
Patch Set: Add missing DEP. Created 3 years, 10 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
« no previous file with comments | « components/cryptauth/fake_secure_channel.cc ('k') | components/cryptauth/secure_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(const std::string& feature,
92 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(std::unique_ptr<Connection> connection,
115 std::unique_ptr<Delegate> delegate);
116
117 Status status_;
118
98 private: 119 private:
99 // Message waiting to be sent. Note that this is *not* the message that will 120 // 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 121 // end up being sent over the wire; before that can be done, the payload must
101 // be encrypted. 122 // be encrypted.
102 struct PendingMessage { 123 struct PendingMessage {
103 PendingMessage(); 124 PendingMessage();
104 PendingMessage(const std::string& feature, const std::string& payload); 125 PendingMessage(const std::string& feature, const std::string& payload);
105 virtual ~PendingMessage(); 126 virtual ~PendingMessage();
106 127
107 const std::string feature; 128 const std::string feature;
108 const std::string payload; 129 const std::string payload;
109 }; 130 };
110 131
111 void TransitionToStatus(const Status& new_status); 132 void TransitionToStatus(const Status& new_status);
112 void Authenticate(); 133 void Authenticate();
113 void ProcessMessageQueue(); 134 void ProcessMessageQueue();
114 void OnMessageEncoded( 135 void OnMessageEncoded(
115 const std::string& feature, const std::string& encoded_message); 136 const std::string& feature, const std::string& encoded_message);
116 void OnMessageDecoded( 137 void OnMessageDecoded(
117 const std::string& feature, const std::string& decoded_message); 138 const std::string& feature, const std::string& decoded_message);
118 void OnAuthenticationResult( 139 void OnAuthenticationResult(
119 Authenticator::Result result, 140 Authenticator::Result result,
120 std::unique_ptr<SecureContext> secure_context); 141 std::unique_ptr<SecureContext> secure_context);
121 142
122 std::unique_ptr<Connection> connection_; 143 std::unique_ptr<Connection> connection_;
123 std::unique_ptr<Delegate> delegate_; 144 std::unique_ptr<Delegate> delegate_;
124 std::unique_ptr<Authenticator> authenticator_; 145 std::unique_ptr<Authenticator> authenticator_;
125 std::unique_ptr<SecureContext> secure_context_; 146 std::unique_ptr<SecureContext> secure_context_;
126 Status status_;
127 std::deque<PendingMessage> queued_messages_; 147 std::deque<PendingMessage> queued_messages_;
128 std::unique_ptr<PendingMessage> pending_message_; 148 std::unique_ptr<PendingMessage> pending_message_;
129 base::ObserverList<Observer> observer_list_; 149 base::ObserverList<Observer> observer_list_;
130 base::WeakPtrFactory<SecureChannel> weak_ptr_factory_; 150 base::WeakPtrFactory<SecureChannel> weak_ptr_factory_;
131 151
132 DISALLOW_COPY_AND_ASSIGN(SecureChannel); 152 DISALLOW_COPY_AND_ASSIGN(SecureChannel);
133 }; 153 };
134 154
135 } // namespace cryptauth 155 } // namespace cryptauth
136 156
137 #endif // COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_ 157 #endif // COMPONENTS_CRYPTAUTH_SECURE_CHANNEL_H_
OLDNEW
« no previous file with comments | « components/cryptauth/fake_secure_channel.cc ('k') | components/cryptauth/secure_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698