Skip to content

Commit

Permalink
Move DispatchSourceMach from //sandbox/mac to //base/mac.
Browse files Browse the repository at this point in the history
BUG=487674

Review URL: https://codereview.chromium.org/1136953012

Cr-Commit-Position: refs/heads/master@{#329700}
  • Loading branch information
rsesek authored and Commit bot committed May 13, 2015
1 parent 1e53d03 commit 6cba592
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 32 deletions.
3 changes: 3 additions & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ component("base") {
"mac/bundle_locations.h",
"mac/bundle_locations.mm",
"mac/cocoa_protocols.h",
"mac/dispatch_source_mach.cc",
"mac/dispatch_source_mach.h",
"mac/foundation_util.h",
"mac/foundation_util.mm",
"mac/launch_services_util.cc",
Expand Down Expand Up @@ -1150,6 +1152,7 @@ test("base_unittests") {
"lazy_instance_unittest.cc",
"logging_unittest.cc",
"mac/bind_objc_block_unittest.mm",
"mac/dispatch_source_mach_unittest.cc",
"mac/foundation_util_unittest.mm",
"mac/libdispatch_task_runner_unittest.cc",
"mac/mac_util_unittest.mm",
Expand Down
1 change: 1 addition & 0 deletions base/base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
'lazy_instance_unittest.cc',
'logging_unittest.cc',
'mac/bind_objc_block_unittest.mm',
'mac/dispatch_source_mach_unittest.cc',
'mac/foundation_util_unittest.mm',
'mac/libdispatch_task_runner_unittest.cc',
'mac/mac_util_unittest.mm',
Expand Down
2 changes: 2 additions & 0 deletions base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
'mac/bundle_locations.mm',
'mac/close_nocancel.cc',
'mac/cocoa_protocols.h',
'mac/dispatch_source_mach.cc',
'mac/dispatch_source_mach.h',
'mac/foundation_util.h',
'mac/foundation_util.mm',
'mac/launch_services_util.cc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sandbox/mac/dispatch_source_mach.h"
#include "base/mac/dispatch_source_mach.h"

namespace sandbox {
namespace base {

DispatchSourceMach::DispatchSourceMach(const char* name,
mach_port_t port,
Expand Down Expand Up @@ -59,4 +59,4 @@ void DispatchSourceMach::Cancel() {
}
}

} // namespace sandbox
} // namespace base
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SANDBOX_MAC_DISPATCH_SOURCE_MACH_H_
#define SANDBOX_MAC_DISPATCH_SOURCE_MACH_H_
#ifndef BASE_MAC_DISPATCH_SOURCE_MACH_H_
#define BASE_MAC_DISPATCH_SOURCE_MACH_H_

#include <dispatch/dispatch.h>

#include "base/base_export.h"
#include "base/macros.h"
#include "sandbox/sandbox_export.h"

namespace sandbox {
namespace base {

// This class encapsulates a MACH_RECV dispatch source. When this object is
// destroyed, the source will be cancelled and it will wait for the source
// to stop executing work. The source can run on either a user-supplied queue,
// or it can create its own for the source.
class SANDBOX_EXPORT DispatchSourceMach {
class BASE_EXPORT DispatchSourceMach {
public:
// Creates a new dispatch source for the |port| and schedules it on a new
// queue that will be created with |name|. When a Mach message is received,
Expand Down Expand Up @@ -56,6 +56,6 @@ class SANDBOX_EXPORT DispatchSourceMach {
DISALLOW_COPY_AND_ASSIGN(DispatchSourceMach);
};

} // namespace sandbox
} // namespace base

#endif // SANDBOX_MAC_DISPATCH_SOURCE_MACH_H_
#endif // BASE_MAC_DISPATCH_SOURCE_MACH_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sandbox/mac/dispatch_source_mach.h"
#include "base/mac/dispatch_source_mach.h"

#include <mach/mach.h>

Expand All @@ -12,7 +12,7 @@
#include "base/test/test_timeouts.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace sandbox {
namespace base {

class DispatchSourceMachTest : public testing::Test {
public:
Expand Down Expand Up @@ -44,7 +44,7 @@ TEST_F(DispatchSourceMachTest, ReceiveAfterResume) {
dispatch_semaphore_t signal = dispatch_semaphore_create(0);

bool __block did_receive = false;
DispatchSourceMach source("org.chromium.sandbox.test.ReceiveAfterResume",
DispatchSourceMach source("org.chromium.base.test.ReceiveAfterResume",
port(), ^{
mach_msg_empty_rcv_t msg = {{0}};
msg.header.msgh_size = sizeof(msg);
Expand Down Expand Up @@ -75,7 +75,7 @@ TEST_F(DispatchSourceMachTest, NoMessagesAfterDestruction) {
int* __block count_ptr = count.get();

scoped_ptr<DispatchSourceMach> source(new DispatchSourceMach(
"org.chromium.sandbox.test.NoMessagesAfterDestruction",
"org.chromium.base.test.NoMessagesAfterDestruction",
port(), ^{
mach_msg_empty_rcv_t msg = {{0}};
msg.header.msgh_size = sizeof(msg);
Expand All @@ -87,7 +87,7 @@ TEST_F(DispatchSourceMachTest, NoMessagesAfterDestruction) {
source->Resume();

dispatch_queue_t queue =
dispatch_queue_create("org.chromium.sandbox.test.MessageSend", NULL);
dispatch_queue_create("org.chromium.base.test.MessageSend", NULL);
dispatch_semaphore_t signal = dispatch_semaphore_create(0);
for (int i = 0; i < 30; ++i) {
dispatch_async(queue, ^{
Expand Down Expand Up @@ -116,4 +116,4 @@ TEST_F(DispatchSourceMachTest, NoMessagesAfterDestruction) {
dispatch_release(queue);
}

} // namespace sandbox
} // namespace base
3 changes: 0 additions & 3 deletions sandbox/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ component("sandbox") {
sources = [
"bootstrap_sandbox.cc",
"bootstrap_sandbox.h",
"dispatch_source_mach.cc",
"dispatch_source_mach.h",
"launchd_interception_server.cc",
"launchd_interception_server.h",
"mach_message_server.cc",
Expand Down Expand Up @@ -85,7 +83,6 @@ component("sandbox") {
test("sandbox_mac_unittests") {
sources = [
"bootstrap_sandbox_unittest.mm",
"dispatch_source_mach_unittest.cc",
"policy_unittest.cc",
"xpc_message_server_unittest.cc",
]
Expand Down
3 changes: 1 addition & 2 deletions sandbox/mac/mach_message_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/logging.h"
#include "base/mac/mach_logging.h"
#include "base/strings/stringprintf.h"
#include "sandbox/mac/dispatch_source_mach.h"

namespace sandbox {

Expand Down Expand Up @@ -69,7 +68,7 @@ bool MachMessageServer::Initialize() {
// Set up the dispatch queue to service the bootstrap port.
std::string label = base::StringPrintf(
"org.chromium.sandbox.MachMessageServer.%p", demuxer_);
dispatch_source_.reset(new DispatchSourceMach(
dispatch_source_.reset(new base::DispatchSourceMach(
label.c_str(), server_port_.get(), ^{ ReceiveMessage(); }));
dispatch_source_->Resume();

Expand Down
5 changes: 2 additions & 3 deletions sandbox/mac/mach_message_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

#include <mach/mach.h>

#include "base/mac/dispatch_source_mach.h"
#include "base/mac/scoped_mach_port.h"
#include "base/mac/scoped_mach_vm.h"
#include "base/memory/scoped_ptr.h"
#include "sandbox/mac/message_server.h"

namespace sandbox {

class DispatchSourceMach;

// A Mach message server that operates a receive port. Messages are received
// and then passed to the MessageDemuxer for handling. The Demuxer
// can use the server class to send a reply, forward the message to a
Expand Down Expand Up @@ -62,7 +61,7 @@ class MachMessageServer : public MessageServer {
base::mac::ScopedMachVM reply_buffer_;

// MACH_RECV dispatch source that handles the |server_port_|.
scoped_ptr<DispatchSourceMach> dispatch_source_;
scoped_ptr<base::DispatchSourceMach> dispatch_source_;

// Whether or not ForwardMessage() was called during ReceiveMessage().
bool did_forward_message_;
Expand Down
3 changes: 0 additions & 3 deletions sandbox/mac/sandbox_mac.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
'sources': [
'bootstrap_sandbox.cc',
'bootstrap_sandbox.h',
'dispatch_source_mach.cc',
'dispatch_source_mach.h',
'launchd_interception_server.cc',
'launchd_interception_server.h',
'mach_message_server.cc',
Expand Down Expand Up @@ -93,7 +91,6 @@
'type': 'executable',
'sources': [
'bootstrap_sandbox_unittest.mm',
'dispatch_source_mach_unittest.cc',
'policy_unittest.cc',
'xpc_message_server_unittest.cc',
],
Expand Down
3 changes: 1 addition & 2 deletions sandbox/mac/xpc_message_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "base/mac/mach_logging.h"
#include "base/strings/stringprintf.h"
#include "sandbox/mac/dispatch_source_mach.h"
#include "sandbox/mac/xpc.h"

#if defined(MAC_OS_X_VERSION_10_7) && \
Expand Down Expand Up @@ -52,7 +51,7 @@ bool XPCMessageServer::Initialize() {

std::string label = base::StringPrintf(
"org.chromium.sandbox.XPCMessageServer.%p", demuxer_);
dispatch_source_.reset(new DispatchSourceMach(
dispatch_source_.reset(new base::DispatchSourceMach(
label.c_str(), server_port_.get(), ^{ ReceiveMessage(); }));
dispatch_source_->Resume();

Expand Down
5 changes: 2 additions & 3 deletions sandbox/mac/xpc_message_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <AvailabilityMacros.h>

#include "base/mac/dispatch_source_mach.h"
#include "base/mac/scoped_mach_port.h"
#include "base/memory/scoped_ptr.h"
#include "sandbox/mac/message_server.h"
Expand All @@ -27,8 +28,6 @@ XPC_EXPORT XPC_NONNULL1 void xpc_release(xpc_object_t object);

namespace sandbox {

class DispatchSourceMach;

// An implementation of MessageServer that uses XPC pipes to read and write XPC
// messages from a Mach port.
class SANDBOX_EXPORT XPCMessageServer : public MessageServer {
Expand Down Expand Up @@ -62,7 +61,7 @@ class SANDBOX_EXPORT XPCMessageServer : public MessageServer {
base::mac::ScopedMachReceiveRight server_port_;

// MACH_RECV dispatch source that handles the |server_port_|.
scoped_ptr<DispatchSourceMach> dispatch_source_;
scoped_ptr<base::DispatchSourceMach> dispatch_source_;

// The reply message, if one has been created.
xpc_object_t reply_message_;
Expand Down

0 comments on commit 6cba592

Please sign in to comment.