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

Side by Side Diff: components/proximity_auth/connection.cc

Issue 562763004: [EasyUnlock] Port PermitMessage class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Left-shift by zero bits for parallelism Created 6 years, 3 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 "components/proximity_auth/connection.h" 5 #include "components/proximity_auth/connection.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "components/proximity_auth/connection_observer.h" 8 #include "components/proximity_auth/connection_observer.h"
9 #include "components/proximity_auth/wire_message.h" 9 #include "components/proximity_auth/wire_message.h"
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 ConnectionObserver, observers_, OnSendCompleted(*this, message, success)); 70 ConnectionObserver, observers_, OnSendCompleted(*this, message, success));
71 } 71 }
72 72
73 void Connection::OnBytesReceived(const std::string& bytes) { 73 void Connection::OnBytesReceived(const std::string& bytes) {
74 if (!IsConnected()) { 74 if (!IsConnected()) {
75 VLOG(1) << "Received bytes, but not connected."; 75 VLOG(1) << "Received bytes, but not connected.";
76 return; 76 return;
77 } 77 }
78 78
79 received_bytes_ += bytes; 79 received_bytes_ += bytes;
80 if (HasReceivedCompleteMessage()) {
81 scoped_ptr<WireMessage> message = DeserializeWireMessage();
82 if (message) {
83 FOR_EACH_OBSERVER(
84 ConnectionObserver, observers_, OnMessageReceived(*this, *message));
85 }
86 80
87 // Whether the message was parsed successfully or not, clear the 81 bool is_incomplete_message;
88 // |received_bytes_| buffer. 82 scoped_ptr<WireMessage> message =
89 received_bytes_.clear(); 83 DeserializeWireMessage(&is_incomplete_message);
84 if (is_incomplete_message)
85 return;
86
87 if (message) {
88 FOR_EACH_OBSERVER(
89 ConnectionObserver, observers_, OnMessageReceived(*this, *message));
90 } 90 }
91
92 // Whether the message was parsed successfully or not, clear the
93 // |received_bytes_| buffer.
94 received_bytes_.clear();
91 } 95 }
92 96
93 bool Connection::HasReceivedCompleteMessage() { 97 scoped_ptr<WireMessage> Connection::DeserializeWireMessage(
94 return WireMessage::IsCompleteMessage(received_bytes_); 98 bool* is_incomplete_message) {
95 } 99 return WireMessage::Deserialize(received_bytes_, is_incomplete_message);
96
97 scoped_ptr<WireMessage> Connection::DeserializeWireMessage() {
98 return WireMessage::Deserialize(received_bytes_);
99 } 100 }
100 101
101 } // namespace proximity_auth 102 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/connection.h ('k') | components/proximity_auth/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698