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

Side by Side Diff: sandbox/mac/xpc_message_server_unittest.cc

Issue 666193002: Standardize usage of virtual/override/final in sandbox/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « sandbox/mac/xpc_message_server.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 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 "sandbox/mac/xpc_message_server.h" 5 #include "sandbox/mac/xpc_message_server.h"
6 6
7 #include <Block.h> 7 #include <Block.h>
8 #include <mach/mach.h> 8 #include <mach/mach.h>
9 #include <servers/bootstrap.h> 9 #include <servers/bootstrap.h>
10 10
(...skipping 25 matching lines...) Expand all
36 // A MessageDemuxer that manages a test server and executes a block for every 36 // A MessageDemuxer that manages a test server and executes a block for every
37 // message. 37 // message.
38 class BlockDemuxer : public MessageDemuxer { 38 class BlockDemuxer : public MessageDemuxer {
39 public: 39 public:
40 BlockDemuxer() 40 BlockDemuxer()
41 : demux_block_(NULL), 41 : demux_block_(NULL),
42 server_(this, MACH_PORT_NULL), 42 server_(this, MACH_PORT_NULL),
43 pipe_(NULL) { 43 pipe_(NULL) {
44 } 44 }
45 45
46 virtual ~BlockDemuxer() { 46 ~BlockDemuxer() override {
47 if (pipe_) 47 if (pipe_)
48 xpc_release(pipe_); 48 xpc_release(pipe_);
49 if (demux_block_) 49 if (demux_block_)
50 Block_release(demux_block_); 50 Block_release(demux_block_);
51 } 51 }
52 52
53 // Starts running the server, given a block to handle incoming IPC messages. 53 // Starts running the server, given a block to handle incoming IPC messages.
54 bool Initialize(void (^demux_block)(IPCMessage request)) { 54 bool Initialize(void (^demux_block)(IPCMessage request)) {
55 if (!server_.Initialize()) 55 if (!server_.Initialize())
56 return false; 56 return false;
57 57
58 // Create a send right on the port so that the XPC pipe can be created. 58 // Create a send right on the port so that the XPC pipe can be created.
59 if (mach_port_insert_right(mach_task_self(), server_.GetServerPort(), 59 if (mach_port_insert_right(mach_task_self(), server_.GetServerPort(),
60 server_.GetServerPort(), MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) { 60 server_.GetServerPort(), MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) {
61 return false; 61 return false;
62 } 62 }
63 scoped_send_right_.reset(server_.GetServerPort()); 63 scoped_send_right_.reset(server_.GetServerPort());
64 64
65 demux_block_ = Block_copy(demux_block); 65 demux_block_ = Block_copy(demux_block);
66 pipe_ = xpc_pipe_create_from_port(server_.GetServerPort(), 0); 66 pipe_ = xpc_pipe_create_from_port(server_.GetServerPort(), 0);
67 67
68 return true; 68 return true;
69 } 69 }
70 70
71 virtual void DemuxMessage(IPCMessage request) override { 71 void DemuxMessage(IPCMessage request) override { demux_block_(request); }
72 demux_block_(request);
Robert Sesek 2014/10/21 20:52:40 nit: please leave on separate line
dcheng 2014/10/21 20:53:57 How strongly do you feel about this? This is how c
Robert Sesek 2014/10/21 20:58:36 This is less readable. I feel strongly about not c
dcheng 2014/10/21 21:01:11 I'll revert this particular line. However, note it
Robert Sesek 2014/10/21 21:09:05 Thanks. I appreciate that, but trading off readabi
73 }
74 72
75 xpc_pipe_t pipe() { return pipe_; } 73 xpc_pipe_t pipe() { return pipe_; }
76 74
77 XPCMessageServer* server() { return &server_; } 75 XPCMessageServer* server() { return &server_; }
78 76
79 private: 77 private:
80 void (^demux_block_)(IPCMessage request); 78 void (^demux_block_)(IPCMessage request);
81 79
82 XPCMessageServer server_; 80 XPCMessageServer server_;
83 81
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply)); 208 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply));
211 209
212 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first")); 210 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first"));
213 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second")); 211 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second"));
214 212
215 xpc_release(request); 213 xpc_release(request);
216 xpc_release(reply); 214 xpc_release(reply);
217 } 215 }
218 216
219 } // namespace sandbox 217 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/mac/xpc_message_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698