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

Side by Side Diff: mojo/edk/system/ports/node.cc

Issue 1985833002: [mojo-edk] Prevent closed port from accepting new messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « mojo/edk/system/ports/node.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/edk/system/ports/node.h" 5 #include "mojo/edk/system/ports/node.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 CHECK(false) << "Oops: " << message; 23 CHECK(false) << "Oops: " << message;
24 return error_code; 24 return error_code;
25 } 25 }
26 26
27 #define OOPS(x) DebugError(#x, x) 27 #define OOPS(x) DebugError(#x, x)
28 28
29 bool CanAcceptMoreMessages(const Port* port) { 29 bool CanAcceptMoreMessages(const Port* port) {
30 // Have we already doled out the last message (i.e., do we expect to NOT 30 // Have we already doled out the last message (i.e., do we expect to NOT
31 // receive further messages)? 31 // receive further messages)?
32 uint64_t next_sequence_num = port->message_queue.next_sequence_num(); 32 uint64_t next_sequence_num = port->message_queue.next_sequence_num();
33 if (port->state == Port::kClosed)
34 return false;
33 if (port->peer_closed || port->remove_proxy_on_last_message) { 35 if (port->peer_closed || port->remove_proxy_on_last_message) {
34 if (port->last_sequence_num_to_receive == next_sequence_num - 1) 36 if (port->last_sequence_num_to_receive == next_sequence_num - 1)
35 return false; 37 return false;
36 } 38 }
37 return true; 39 return true;
38 } 40 }
39 41
40 } // namespace 42 } // namespace
41 43
42 Node::Node(const NodeName& name, NodeDelegate* delegate) 44 Node::Node(const NodeName& name, NodeDelegate* delegate)
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 const scoped_refptr<Port>& port) { 816 const scoped_refptr<Port>& port) {
815 base::AutoLock lock(ports_lock_); 817 base::AutoLock lock(ports_lock_);
816 818
817 if (!ports_.insert(std::make_pair(port_name, port)).second) 819 if (!ports_.insert(std::make_pair(port_name, port)).second)
818 return OOPS(ERROR_PORT_EXISTS); // Suggests a bad UUID generator. 820 return OOPS(ERROR_PORT_EXISTS); // Suggests a bad UUID generator.
819 821
820 DVLOG(2) << "Created port " << port_name << "@" << name_; 822 DVLOG(2) << "Created port " << port_name << "@" << name_;
821 return OK; 823 return OK;
822 } 824 }
823 825
824 void Node::ErasePort(const PortName& port_name) {
825 base::AutoLock lock(ports_lock_);
826 return ErasePort_Locked(port_name);
827 }
828
829 void Node::ErasePort_Locked(const PortName& port_name) { 826 void Node::ErasePort_Locked(const PortName& port_name) {
830 ports_lock_.AssertAcquired(); 827 ports_lock_.AssertAcquired();
831 ports_.erase(port_name); 828 ports_.erase(port_name);
832 DVLOG(2) << "Deleted port " << port_name << "@" << name_; 829 DVLOG(2) << "Deleted port " << port_name << "@" << name_;
833 } 830 }
834 831
835 scoped_refptr<Port> Node::GetPort(const PortName& port_name) { 832 scoped_refptr<Port> Node::GetPort(const PortName& port_name) {
836 base::AutoLock lock(ports_lock_); 833 base::AutoLock lock(ports_lock_);
837 return GetPort_Locked(port_name); 834 return GetPort_Locked(port_name);
838 } 835 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 1237
1241 if (num_data_bytes) 1238 if (num_data_bytes)
1242 memcpy(header + 1, data, num_data_bytes); 1239 memcpy(header + 1, data, num_data_bytes);
1243 1240
1244 return message; 1241 return message;
1245 } 1242 }
1246 1243
1247 } // namespace ports 1244 } // namespace ports
1248 } // namespace edk 1245 } // namespace edk
1249 } // namespace mojo 1246 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/ports/node.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698