| 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_CONNECTION_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CONNECTION_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_CONNECTION_H | 6 #define COMPONENTS_PROXIMITY_AUTH_CONNECTION_H |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Called when bytes are read from the connection. There should not be a send | 69 // Called when bytes are read from the connection. There should not be a send |
| 70 // in progress when this function is called. | 70 // in progress when this function is called. |
| 71 void OnBytesReceived(const std::string& bytes); | 71 void OnBytesReceived(const std::string& bytes); |
| 72 | 72 |
| 73 // Sends bytes over the connection. The implementing class should call | 73 // Sends bytes over the connection. The implementing class should call |
| 74 // OnSendCompleted() once the send succeeds or fails. At most one send will be | 74 // OnSendCompleted() once the send succeeds or fails. At most one send will be |
| 75 // in progress. | 75 // in progress. |
| 76 virtual void SendMessageImpl(scoped_ptr<WireMessage> message) = 0; | 76 virtual void SendMessageImpl(scoped_ptr<WireMessage> message) = 0; |
| 77 | 77 |
| 78 // Returns |true| iff the |received_bytes_| are long enough to contain a | |
| 79 // complete wire message. Exposed for testing. | |
| 80 virtual bool HasReceivedCompleteMessage(); | |
| 81 | |
| 82 // Deserializes the |recieved_bytes_| and returns the resulting WireMessage, | 78 // Deserializes the |recieved_bytes_| and returns the resulting WireMessage, |
| 83 // or NULL if the message is malformed. Exposed for testing. | 79 // or NULL if the message is malformed. Sets |is_incomplete_message| to true |
| 84 virtual scoped_ptr<WireMessage> DeserializeWireMessage(); | 80 // if the |serialized_message| does not have enough data to parse the header, |
| 81 // or if the message length encoded in the message header exceeds the size of |
| 82 // the |serialized_message|. Exposed for testing. |
| 83 virtual scoped_ptr<WireMessage> DeserializeWireMessage( |
| 84 bool* is_incomplete_message); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 // The remote device corresponding to this connection. | 87 // The remote device corresponding to this connection. |
| 88 const RemoteDevice remote_device_; | 88 const RemoteDevice remote_device_; |
| 89 | 89 |
| 90 // The current status of the connection. | 90 // The current status of the connection. |
| 91 Status status_; | 91 Status status_; |
| 92 | 92 |
| 93 // The registered observers of the connection. | 93 // The registered observers of the connection. |
| 94 ObserverList<ConnectionObserver> observers_; | 94 ObserverList<ConnectionObserver> observers_; |
| 95 | 95 |
| 96 // A temporary buffer storing bytes received before a received message can be | 96 // A temporary buffer storing bytes received before a received message can be |
| 97 // fully constructed. | 97 // fully constructed. |
| 98 std::string received_bytes_; | 98 std::string received_bytes_; |
| 99 | 99 |
| 100 // Whether a message is currently in the process of being sent. | 100 // Whether a message is currently in the process of being sent. |
| 101 bool is_sending_message_; | 101 bool is_sending_message_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(Connection); | 103 DISALLOW_COPY_AND_ASSIGN(Connection); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 } // namespace proximity_auth | 106 } // namespace proximity_auth |
| 107 | 107 |
| 108 #endif // COMPONENTS_PROXIMITY_AUTH_CONNECTION_H | 108 #endif // COMPONENTS_PROXIMITY_AUTH_CONNECTION_H |
| OLD | NEW |