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

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

Issue 2423353002: Reduce usage of FOR_EACH_OBSERVER macro in components/ (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | components/proximity_auth/cryptauth/cryptauth_device_manager.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 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 <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "components/proximity_auth/connection_observer.h" 10 #include "components/proximity_auth/connection_observer.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 void Connection::SetStatus(Status status) { 55 void Connection::SetStatus(Status status) {
56 if (status_ == status) 56 if (status_ == status)
57 return; 57 return;
58 58
59 received_bytes_.clear(); 59 received_bytes_.clear();
60 60
61 Status old_status = status_; 61 Status old_status = status_;
62 status_ = status; 62 status_ = status;
63 FOR_EACH_OBSERVER(ConnectionObserver, observers_, 63 for (auto& observer : observers_)
64 OnConnectionStatusChanged(this, old_status, status_)); 64 observer.OnConnectionStatusChanged(this, old_status, status_);
65 } 65 }
66 66
67 void Connection::OnDidSendMessage(const WireMessage& message, bool success) { 67 void Connection::OnDidSendMessage(const WireMessage& message, bool success) {
68 if (!is_sending_message_) { 68 if (!is_sending_message_) {
69 VLOG(1) << "Send completed, but no message in progress."; 69 VLOG(1) << "Send completed, but no message in progress.";
70 return; 70 return;
71 } 71 }
72 72
73 is_sending_message_ = false; 73 is_sending_message_ = false;
74 FOR_EACH_OBSERVER( 74 for (auto& observer : observers_)
75 ConnectionObserver, observers_, OnSendCompleted(*this, message, success)); 75 observer.OnSendCompleted(*this, message, success);
76 } 76 }
77 77
78 void Connection::OnBytesReceived(const std::string& bytes) { 78 void Connection::OnBytesReceived(const std::string& bytes) {
79 if (!IsConnected()) { 79 if (!IsConnected()) {
80 VLOG(1) << "Received bytes, but not connected."; 80 VLOG(1) << "Received bytes, but not connected.";
81 return; 81 return;
82 } 82 }
83 83
84 received_bytes_ += bytes; 84 received_bytes_ += bytes;
85 85
86 bool is_incomplete_message; 86 bool is_incomplete_message;
87 std::unique_ptr<WireMessage> message = 87 std::unique_ptr<WireMessage> message =
88 DeserializeWireMessage(&is_incomplete_message); 88 DeserializeWireMessage(&is_incomplete_message);
89 if (is_incomplete_message) 89 if (is_incomplete_message)
90 return; 90 return;
91 91
92 if (message) { 92 if (message) {
93 FOR_EACH_OBSERVER( 93 for (auto& observer : observers_)
94 ConnectionObserver, observers_, OnMessageReceived(*this, *message)); 94 observer.OnMessageReceived(*this, *message);
95 } 95 }
96 96
97 // Whether the message was parsed successfully or not, clear the 97 // Whether the message was parsed successfully or not, clear the
98 // |received_bytes_| buffer. 98 // |received_bytes_| buffer.
99 received_bytes_.clear(); 99 received_bytes_.clear();
100 } 100 }
101 101
102 std::unique_ptr<WireMessage> Connection::DeserializeWireMessage( 102 std::unique_ptr<WireMessage> Connection::DeserializeWireMessage(
103 bool* is_incomplete_message) { 103 bool* is_incomplete_message) {
104 return WireMessage::Deserialize(received_bytes_, is_incomplete_message); 104 return WireMessage::Deserialize(received_bytes_, is_incomplete_message);
105 } 105 }
106 106
107 } // namespace proximity_auth 107 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « no previous file | components/proximity_auth/cryptauth/cryptauth_device_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698