Rewrite most of the scopers in //base/mac to use ScopedTypeRef or ScopedGeneric.
This removes a lot of duplicated code in favor of using type aliases and minimal Traits structs. R=mark@chromium.org Review URL: https://codereview.chromium.org/1551943002 . Cr-Commit-Position: refs/heads/master@{#367322}
This commit is contained in:
base
mac
launchd.ccscoped_block.hscoped_cffiledescriptorref.hscoped_cftyperef.hscoped_ioobject.hscoped_ioplugininterface.hscoped_launch_data.hscoped_nsobject.hscoped_nsobject_unittest.mmscoped_typeref.h
message_loop
chrome/browser
media/base/mac
remoting/host/mac
third_party/crashpad
ui
@ -18,7 +18,7 @@ launch_data_t MessageForJob(const std::string& job_label,
|
|||||||
const char* operation) {
|
const char* operation) {
|
||||||
// launch_data_alloc returns something that needs to be freed.
|
// launch_data_alloc returns something that needs to be freed.
|
||||||
ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
|
ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
|
||||||
if (!message) {
|
if (!message.is_valid()) {
|
||||||
LOG(ERROR) << "launch_data_alloc";
|
LOG(ERROR) << "launch_data_alloc";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -28,38 +28,38 @@ launch_data_t MessageForJob(const std::string& job_label,
|
|||||||
// called, so put it in a scoper and .release() it when given to the
|
// called, so put it in a scoper and .release() it when given to the
|
||||||
// dictionary.
|
// dictionary.
|
||||||
ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
|
ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
|
||||||
if (!job_label_launchd) {
|
if (!job_label_launchd.is_valid()) {
|
||||||
LOG(ERROR) << "launch_data_new_string";
|
LOG(ERROR) << "launch_data_new_string";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!launch_data_dict_insert(message,
|
if (!launch_data_dict_insert(message.get(), job_label_launchd.release(),
|
||||||
job_label_launchd.release(),
|
|
||||||
operation)) {
|
operation)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return launch_msg(message);
|
return launch_msg(message.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t PIDForJob(const std::string& job_label) {
|
pid_t PIDForJob(const std::string& job_label) {
|
||||||
ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
|
ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
|
||||||
if (!response) {
|
if (!response.is_valid()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_type_t response_type = launch_data_get_type(response);
|
launch_data_type_t response_type = launch_data_get_type(response.get());
|
||||||
if (response_type != LAUNCH_DATA_DICTIONARY) {
|
if (response_type != LAUNCH_DATA_DICTIONARY) {
|
||||||
if (response_type == LAUNCH_DATA_ERRNO) {
|
if (response_type == LAUNCH_DATA_ERRNO) {
|
||||||
LOG(ERROR) << "PIDForJob: error " << launch_data_get_errno(response);
|
LOG(ERROR) << "PIDForJob: error "
|
||||||
|
<< launch_data_get_errno(response.get());
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "PIDForJob: expected dictionary, got " << response_type;
|
LOG(ERROR) << "PIDForJob: expected dictionary, got " << response_type;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_t pid_data = launch_data_dict_lookup(response,
|
launch_data_t pid_data =
|
||||||
LAUNCH_JOBKEY_PID);
|
launch_data_dict_lookup(response.get(), LAUNCH_JOBKEY_PID);
|
||||||
if (!pid_data)
|
if (!pid_data)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -7,83 +7,27 @@
|
|||||||
|
|
||||||
#include <Block.h>
|
#include <Block.h>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/mac/scoped_typeref.h"
|
||||||
#include "base/memory/scoped_policy.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template <typename B>
|
||||||
|
struct ScopedBlockTraits {
|
||||||
|
static B InvalidValue() { return nullptr; }
|
||||||
|
static B Retain(B block) { return Block_copy(block); }
|
||||||
|
static void Release(B block) { Block_release(block); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
|
// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
|
||||||
// Block_release() instead of CFRetain() and CFRelease().
|
// Block_release() instead of CFRetain() and CFRelease().
|
||||||
|
|
||||||
template<typename B>
|
template <typename B>
|
||||||
class ScopedBlock {
|
using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
|
||||||
public:
|
|
||||||
explicit ScopedBlock(
|
|
||||||
B block = nullptr,
|
|
||||||
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
|
|
||||||
: block_(block) {
|
|
||||||
if (block_ && policy == base::scoped_policy::RETAIN)
|
|
||||||
block_ = Block_copy(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedBlock(const ScopedBlock<B>& that)
|
|
||||||
: block_(that.block_) {
|
|
||||||
if (block_)
|
|
||||||
block_ = Block_copy(block_);
|
|
||||||
}
|
|
||||||
|
|
||||||
~ScopedBlock() {
|
|
||||||
if (block_)
|
|
||||||
Block_release(block_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedBlock& operator=(const ScopedBlock<B>& that) {
|
|
||||||
reset(that.get(), base::scoped_policy::RETAIN);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(B block = nullptr,
|
|
||||||
base::scoped_policy::OwnershipPolicy policy =
|
|
||||||
base::scoped_policy::ASSUME) {
|
|
||||||
if (block && policy == base::scoped_policy::RETAIN)
|
|
||||||
block = Block_copy(block);
|
|
||||||
if (block_)
|
|
||||||
Block_release(block_);
|
|
||||||
block_ = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(B that) const {
|
|
||||||
return block_ == that;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(B that) const {
|
|
||||||
return block_ != that;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator B() const {
|
|
||||||
return block_;
|
|
||||||
}
|
|
||||||
|
|
||||||
B get() const {
|
|
||||||
return block_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(ScopedBlock& that) {
|
|
||||||
B temp = that.block_;
|
|
||||||
that.block_ = block_;
|
|
||||||
block_ = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
B release() WARN_UNUSED_RESULT {
|
|
||||||
B temp = block_;
|
|
||||||
block_ = nullptr;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
B block_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -7,67 +7,31 @@
|
|||||||
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/scoped_generic.h"
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
struct ScopedCFFileDescriptorRefTraits {
|
||||||
|
static CFFileDescriptorRef InvalidValue() { return nullptr; }
|
||||||
|
static void Free(CFFileDescriptorRef ref) {
|
||||||
|
CFFileDescriptorInvalidate(ref);
|
||||||
|
CFRelease(ref);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// ScopedCFFileDescriptorRef is designed after ScopedCFTypeRef<>. On
|
// ScopedCFFileDescriptorRef is designed after ScopedCFTypeRef<>. On
|
||||||
// destruction, it will invalidate the file descriptor.
|
// destruction, it will invalidate the file descriptor.
|
||||||
// ScopedCFFileDescriptorRef (unlike ScopedCFTypeRef<>) does not support RETAIN
|
// ScopedCFFileDescriptorRef (unlike ScopedCFTypeRef<>) does not support RETAIN
|
||||||
// semantics, copying, or assignment, as doing so would increase the chances
|
// semantics, copying, or assignment, as doing so would increase the chances
|
||||||
// that a file descriptor is invalidated while still in use.
|
// that a file descriptor is invalidated while still in use.
|
||||||
class ScopedCFFileDescriptorRef {
|
using ScopedCFFileDescriptorRef =
|
||||||
public:
|
ScopedGeneric<CFFileDescriptorRef,
|
||||||
explicit ScopedCFFileDescriptorRef(CFFileDescriptorRef fdref = NULL)
|
internal::ScopedCFFileDescriptorRefTraits>;
|
||||||
: fdref_(fdref) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~ScopedCFFileDescriptorRef() {
|
|
||||||
if (fdref_) {
|
|
||||||
CFFileDescriptorInvalidate(fdref_);
|
|
||||||
CFRelease(fdref_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(CFFileDescriptorRef fdref = NULL) {
|
|
||||||
if (fdref_ == fdref)
|
|
||||||
return;
|
|
||||||
if (fdref_) {
|
|
||||||
CFFileDescriptorInvalidate(fdref_);
|
|
||||||
CFRelease(fdref_);
|
|
||||||
}
|
|
||||||
fdref_ = fdref;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(CFFileDescriptorRef that) const {
|
|
||||||
return fdref_ == that;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(CFFileDescriptorRef that) const {
|
|
||||||
return fdref_ != that;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator CFFileDescriptorRef() const {
|
|
||||||
return fdref_;
|
|
||||||
}
|
|
||||||
|
|
||||||
CFFileDescriptorRef get() const {
|
|
||||||
return fdref_;
|
|
||||||
}
|
|
||||||
|
|
||||||
CFFileDescriptorRef release() WARN_UNUSED_RESULT {
|
|
||||||
CFFileDescriptorRef temp = fdref_;
|
|
||||||
fdref_ = NULL;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
CFFileDescriptorRef fdref_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScopedCFFileDescriptorRef);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -30,8 +30,9 @@ namespace internal {
|
|||||||
template<typename CFT>
|
template<typename CFT>
|
||||||
struct ScopedCFTypeRefTraits {
|
struct ScopedCFTypeRefTraits {
|
||||||
static CFT InvalidValue() { return nullptr; }
|
static CFT InvalidValue() { return nullptr; }
|
||||||
static void Retain(CFT object) {
|
static CFT Retain(CFT object) {
|
||||||
CFRetain(object);
|
CFRetain(object);
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
static void Release(CFT object) {
|
static void Release(CFT object) {
|
||||||
CFRelease(object);
|
CFRelease(object);
|
||||||
|
@ -7,67 +7,29 @@
|
|||||||
|
|
||||||
#include <IOKit/IOKitLib.h>
|
#include <IOKit/IOKitLib.h>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/mac/scoped_typeref.h"
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
// Just like ScopedCFTypeRef but for io_object_t and subclasses.
|
namespace internal {
|
||||||
template<typename IOT>
|
|
||||||
class ScopedIOObject {
|
|
||||||
public:
|
|
||||||
typedef IOT element_type;
|
|
||||||
|
|
||||||
explicit ScopedIOObject(IOT object = IO_OBJECT_NULL)
|
template <typename IOT>
|
||||||
: object_(object) {
|
struct ScopedIOObjectTraits {
|
||||||
|
static IOT InvalidValue() { return IO_OBJECT_NULL; }
|
||||||
|
static IOT Retain(IOT iot) {
|
||||||
|
IOObjectRetain(iot);
|
||||||
|
return iot;
|
||||||
}
|
}
|
||||||
|
static void Release(IOT iot) { IOObjectRelease(iot); }
|
||||||
~ScopedIOObject() {
|
|
||||||
if (object_)
|
|
||||||
IOObjectRelease(object_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(IOT object = IO_OBJECT_NULL) {
|
|
||||||
if (object_)
|
|
||||||
IOObjectRelease(object_);
|
|
||||||
object_ = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(IOT that) const {
|
|
||||||
return object_ == that;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(IOT that) const {
|
|
||||||
return object_ != that;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator IOT() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
IOT get() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(ScopedIOObject& that) {
|
|
||||||
IOT temp = that.object_;
|
|
||||||
that.object_ = object_;
|
|
||||||
object_ = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
IOT release() WARN_UNUSED_RESULT {
|
|
||||||
IOT temp = object_;
|
|
||||||
object_ = IO_OBJECT_NULL;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IOT object_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScopedIOObject);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespce internal
|
||||||
|
|
||||||
|
// Just like ScopedCFTypeRef but for io_object_t and subclasses.
|
||||||
|
template <typename IOT>
|
||||||
|
using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|
||||||
|
@ -7,68 +7,30 @@
|
|||||||
|
|
||||||
#include <IOKit/IOKitLib.h>
|
#include <IOKit/IOKitLib.h>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/mac/scoped_typeref.h"
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct ScopedIOPluginInterfaceTraits {
|
||||||
|
static T InvalidValue() { return nullptr; }
|
||||||
|
static T Retain(T t) {
|
||||||
|
(*t)->AddRef(t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
static void Release(T t) { (*t)->Release(t); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends
|
// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends
|
||||||
// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
|
// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
|
||||||
template<typename T>
|
template <typename T>
|
||||||
class ScopedIOPluginInterface {
|
using ScopedIOPluginInterface =
|
||||||
public:
|
ScopedTypeRef<T**, internal::ScopedIOPluginInterfaceTraits<T**>>;
|
||||||
typedef T** InterfaceT;
|
|
||||||
typedef InterfaceT element_type;
|
|
||||||
|
|
||||||
explicit ScopedIOPluginInterface(InterfaceT object = NULL)
|
|
||||||
: object_(object) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~ScopedIOPluginInterface() {
|
|
||||||
if (object_)
|
|
||||||
(*object_)->Release(object_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(InterfaceT object = NULL) {
|
|
||||||
if (object_)
|
|
||||||
(*object_)->Release(object_);
|
|
||||||
object_ = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(InterfaceT that) const {
|
|
||||||
return object_ == that;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(InterfaceT that) const {
|
|
||||||
return object_ != that;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator InterfaceT() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
InterfaceT get() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(ScopedIOPluginInterface& that) {
|
|
||||||
InterfaceT temp = that.object_;
|
|
||||||
that.object_ = object_;
|
|
||||||
object_ = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
InterfaceT release() WARN_UNUSED_RESULT {
|
|
||||||
InterfaceT temp = object_;
|
|
||||||
object_ = NULL;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
InterfaceT object_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -7,68 +7,24 @@
|
|||||||
|
|
||||||
#include <launch.h>
|
#include <launch.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include "base/scoped_generic.h"
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace mac {
|
namespace mac {
|
||||||
|
|
||||||
// Just like scoped_ptr<> but for launch_data_t.
|
namespace internal {
|
||||||
class ScopedLaunchData {
|
|
||||||
public:
|
|
||||||
typedef launch_data_t element_type;
|
|
||||||
|
|
||||||
explicit ScopedLaunchData(launch_data_t object = NULL)
|
struct ScopedLaunchDataTraits {
|
||||||
: object_(object) {
|
static launch_data_t InvalidValue() { return nullptr; }
|
||||||
}
|
static void Free(launch_data_t ldt) { launch_data_free(ldt); }
|
||||||
|
|
||||||
~ScopedLaunchData() {
|
|
||||||
if (object_)
|
|
||||||
launch_data_free(object_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(launch_data_t object = NULL) {
|
|
||||||
if (object != object_) {
|
|
||||||
if (object_)
|
|
||||||
launch_data_free(object_);
|
|
||||||
object_ = object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(launch_data_t that) const {
|
|
||||||
return object_ == that;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(launch_data_t that) const {
|
|
||||||
return object_ != that;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator launch_data_t() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
launch_data_t get() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(ScopedLaunchData& that) {
|
|
||||||
std::swap(object_, that.object_);
|
|
||||||
}
|
|
||||||
|
|
||||||
launch_data_t release() WARN_UNUSED_RESULT {
|
|
||||||
launch_data_t temp = object_;
|
|
||||||
object_ = NULL;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
launch_data_t object_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScopedLaunchData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
// Just like scoped_ptr<> but for launch_data_t.
|
||||||
|
using ScopedLaunchData =
|
||||||
|
ScopedGeneric<launch_data_t, internal::ScopedLaunchDataTraits>;
|
||||||
|
|
||||||
} // namespace mac
|
} // namespace mac
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|
||||||
|
@ -5,13 +5,15 @@
|
|||||||
#ifndef BASE_MAC_SCOPED_NSOBJECT_H_
|
#ifndef BASE_MAC_SCOPED_NSOBJECT_H_
|
||||||
#define BASE_MAC_SCOPED_NSOBJECT_H_
|
#define BASE_MAC_SCOPED_NSOBJECT_H_
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
// Include NSObject.h directly because Foundation.h pulls in many dependencies.
|
// Include NSObject.h directly because Foundation.h pulls in many dependencies.
|
||||||
// (Approx 100k lines of code versus 1.5k for NSObject.h). scoped_nsobject gets
|
// (Approx 100k lines of code versus 1.5k for NSObject.h). scoped_nsobject gets
|
||||||
// singled out because it is most typically included from other header files.
|
// singled out because it is most typically included from other header files.
|
||||||
#import <Foundation/NSObject.h>
|
#import <Foundation/NSObject.h>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "base/macros.h"
|
#include "base/mac/scoped_typeref.h"
|
||||||
|
|
||||||
@class NSAutoreleasePool;
|
@class NSAutoreleasePool;
|
||||||
|
|
||||||
@ -37,71 +39,26 @@ namespace base {
|
|||||||
// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
|
// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
|
||||||
// time with a template specialization (see below).
|
// time with a template specialization (see below).
|
||||||
|
|
||||||
template<typename NST>
|
namespace internal {
|
||||||
class scoped_nsprotocol {
|
|
||||||
|
template <typename NST>
|
||||||
|
struct ScopedNSProtocolTraits {
|
||||||
|
static NST InvalidValue() { return nil; }
|
||||||
|
static NST Retain(NST nst) { return [nst retain]; }
|
||||||
|
static void Release(NST nst) { [nst release]; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
template <typename NST>
|
||||||
|
class scoped_nsprotocol
|
||||||
|
: public ScopedTypeRef<NST, internal::ScopedNSProtocolTraits<NST>> {
|
||||||
public:
|
public:
|
||||||
explicit scoped_nsprotocol(NST object = nil) : object_(object) {}
|
using ScopedTypeRef<NST,
|
||||||
|
internal::ScopedNSProtocolTraits<NST>>::ScopedTypeRef;
|
||||||
scoped_nsprotocol(const scoped_nsprotocol<NST>& that)
|
|
||||||
: object_([that.object_ retain]) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename NSU>
|
|
||||||
scoped_nsprotocol(const scoped_nsprotocol<NSU>& that)
|
|
||||||
: object_([that.get() retain]) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~scoped_nsprotocol() {
|
|
||||||
[object_ release];
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_nsprotocol& operator=(const scoped_nsprotocol<NST>& that) {
|
|
||||||
reset([that.get() retain]);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset(NST object = nil) {
|
|
||||||
// We intentionally do not check that object != object_ as the caller must
|
|
||||||
// either already have an ownership claim over whatever it passes to this
|
|
||||||
// method, or call it with the |RETAIN| policy which will have ensured that
|
|
||||||
// the object is retained once more when reaching this point.
|
|
||||||
[object_ release];
|
|
||||||
object_ = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(NST that) const { return object_ == that; }
|
|
||||||
bool operator!=(NST that) const { return object_ != that; }
|
|
||||||
|
|
||||||
operator NST() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
NST get() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(scoped_nsprotocol& that) {
|
|
||||||
NST temp = that.object_;
|
|
||||||
that.object_ = object_;
|
|
||||||
object_ = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// scoped_nsprotocol<>::release() is like scoped_ptr<>::release. It is NOT a
|
|
||||||
// wrapper for [object_ release]. To force a scoped_nsprotocol<> to call
|
|
||||||
// [object_ release], use scoped_nsprotocol<>::reset().
|
|
||||||
NST release() WARN_UNUSED_RESULT {
|
|
||||||
NST temp = object_;
|
|
||||||
object_ = nil;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shift reference to the autorelease pool to be released later.
|
// Shift reference to the autorelease pool to be released later.
|
||||||
NST autorelease() {
|
NST autorelease() { return [this->release() autorelease]; }
|
||||||
return [release() autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
NST object_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Free functions
|
// Free functions
|
||||||
@ -120,56 +77,20 @@ bool operator!=(C p1, const scoped_nsprotocol<C>& p2) {
|
|||||||
return p1 != p2.get();
|
return p1 != p2.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename NST>
|
template <typename NST>
|
||||||
class scoped_nsobject : public scoped_nsprotocol<NST*> {
|
class scoped_nsobject : public scoped_nsprotocol<NST*> {
|
||||||
public:
|
public:
|
||||||
explicit scoped_nsobject(NST* object = nil)
|
using scoped_nsprotocol<NST*>::scoped_nsprotocol;
|
||||||
: scoped_nsprotocol<NST*>(object) {}
|
|
||||||
|
|
||||||
scoped_nsobject(const scoped_nsobject<NST>& that)
|
static_assert(std::is_same<NST, NSAutoreleasePool>::value == false,
|
||||||
: scoped_nsprotocol<NST*>(that) {
|
"Use ScopedNSAutoreleasePool instead");
|
||||||
}
|
|
||||||
|
|
||||||
template<typename NSU>
|
|
||||||
scoped_nsobject(const scoped_nsobject<NSU>& that)
|
|
||||||
: scoped_nsprotocol<NST*>(that) {
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_nsobject& operator=(const scoped_nsobject<NST>& that) {
|
|
||||||
scoped_nsprotocol<NST*>::operator=(that);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialization to make scoped_nsobject<id> work.
|
// Specialization to make scoped_nsobject<id> work.
|
||||||
template<>
|
template<>
|
||||||
class scoped_nsobject<id> : public scoped_nsprotocol<id> {
|
class scoped_nsobject<id> : public scoped_nsprotocol<id> {
|
||||||
public:
|
public:
|
||||||
explicit scoped_nsobject(id object = nil) : scoped_nsprotocol<id>(object) {}
|
using scoped_nsprotocol<id>::scoped_nsprotocol;
|
||||||
|
|
||||||
scoped_nsobject(const scoped_nsobject<id>& that)
|
|
||||||
: scoped_nsprotocol<id>(that) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename NSU>
|
|
||||||
scoped_nsobject(const scoped_nsobject<NSU>& that)
|
|
||||||
: scoped_nsprotocol<id>(that) {
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_nsobject& operator=(const scoped_nsobject<id>& that) {
|
|
||||||
scoped_nsprotocol<id>::operator=(that);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Do not use scoped_nsobject for NSAutoreleasePools, use
|
|
||||||
// ScopedNSAutoreleasePool instead. This is a compile time check. See details
|
|
||||||
// at top of header.
|
|
||||||
template<>
|
|
||||||
class scoped_nsobject<NSAutoreleasePool> {
|
|
||||||
private:
|
|
||||||
explicit scoped_nsobject(NSAutoreleasePool* object = nil);
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -52,6 +52,12 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
|
|||||||
ASSERT_EQ(2u, [p1 retainCount]);
|
ASSERT_EQ(2u, [p1 retainCount]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) {
|
||||||
|
base::scoped_nsobject<NSAutoreleasePool> pool;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
|
TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
|
||||||
base::scoped_nsobject<id> p([[NSObject alloc] init]);
|
base::scoped_nsobject<id> p([[NSObject alloc] init]);
|
||||||
ASSERT_TRUE(p.get());
|
ASSERT_TRUE(p.get());
|
||||||
|
@ -22,7 +22,10 @@ namespace base {
|
|||||||
// template<>
|
// template<>
|
||||||
// struct ScopedTypeRefTraits<CGLContextObj> {
|
// struct ScopedTypeRefTraits<CGLContextObj> {
|
||||||
// static CGLContextObj InvalidValue() { return nullptr; }
|
// static CGLContextObj InvalidValue() { return nullptr; }
|
||||||
// static void Retain(CGLContextObj object) { CGLContextRetain(object); }
|
// static CGLContextObj Retain(CGLContextObj object) {
|
||||||
|
// CGLContextRetain(object);
|
||||||
|
// return object;
|
||||||
|
// }
|
||||||
// static void Release(CGLContextObj object) { CGLContextRelease(object); }
|
// static void Release(CGLContextObj object) { CGLContextRelease(object); }
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
@ -55,13 +58,13 @@ class ScopedTypeRef {
|
|||||||
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
|
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
|
||||||
: object_(object) {
|
: object_(object) {
|
||||||
if (object_ && policy == base::scoped_policy::RETAIN)
|
if (object_ && policy == base::scoped_policy::RETAIN)
|
||||||
Traits::Retain(object_);
|
object_ = Traits::Retain(object_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedTypeRef(const ScopedTypeRef<T, Traits>& that)
|
ScopedTypeRef(const ScopedTypeRef<T, Traits>& that)
|
||||||
: object_(that.object_) {
|
: object_(that.object_) {
|
||||||
if (object_)
|
if (object_)
|
||||||
Traits::Retain(object_);
|
object_ = Traits::Retain(object_);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScopedTypeRef() {
|
~ScopedTypeRef() {
|
||||||
@ -86,7 +89,7 @@ class ScopedTypeRef {
|
|||||||
base::scoped_policy::OwnershipPolicy policy =
|
base::scoped_policy::OwnershipPolicy policy =
|
||||||
base::scoped_policy::ASSUME) {
|
base::scoped_policy::ASSUME) {
|
||||||
if (object && policy == base::scoped_policy::RETAIN)
|
if (object && policy == base::scoped_policy::RETAIN)
|
||||||
Traits::Retain(object);
|
object = Traits::Retain(object);
|
||||||
if (object_)
|
if (object_)
|
||||||
Traits::Release(object_);
|
Traits::Release(object_);
|
||||||
object_ = object;
|
object_ = object;
|
||||||
|
@ -22,7 +22,7 @@ bool MessagePumpIOSForIO::FileDescriptorWatcher::StopWatchingFileDescriptor() {
|
|||||||
if (fdref_ == NULL)
|
if (fdref_ == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
CFFileDescriptorDisableCallBacks(fdref_, callback_types_);
|
CFFileDescriptorDisableCallBacks(fdref_.get(), callback_types_);
|
||||||
if (pump_)
|
if (pump_)
|
||||||
pump_->RemoveRunLoopSource(fd_source_);
|
pump_->RemoveRunLoopSource(fd_source_);
|
||||||
fd_source_.reset();
|
fd_source_.reset();
|
||||||
@ -39,7 +39,7 @@ void MessagePumpIOSForIO::FileDescriptorWatcher::Init(
|
|||||||
CFRunLoopSourceRef fd_source,
|
CFRunLoopSourceRef fd_source,
|
||||||
bool is_persistent) {
|
bool is_persistent) {
|
||||||
DCHECK(fdref);
|
DCHECK(fdref);
|
||||||
DCHECK(!fdref_);
|
DCHECK(!fdref_.is_valid());
|
||||||
|
|
||||||
is_persistent_ = is_persistent;
|
is_persistent_ = is_persistent;
|
||||||
fdref_.reset(fdref);
|
fdref_.reset(fdref);
|
||||||
@ -97,7 +97,7 @@ bool MessagePumpIOSForIO::WatchFileDescriptor(
|
|||||||
callback_types |= kCFFileDescriptorWriteCallBack;
|
callback_types |= kCFFileDescriptorWriteCallBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFFileDescriptorRef fdref = controller->fdref_;
|
CFFileDescriptorRef fdref = controller->fdref_.get();
|
||||||
if (fdref == NULL) {
|
if (fdref == NULL) {
|
||||||
base::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
|
base::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
|
||||||
CFFileDescriptorCreate(
|
CFFileDescriptorCreate(
|
||||||
@ -174,7 +174,7 @@ void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref,
|
|||||||
void* context) {
|
void* context) {
|
||||||
FileDescriptorWatcher* controller =
|
FileDescriptorWatcher* controller =
|
||||||
static_cast<FileDescriptorWatcher*>(context);
|
static_cast<FileDescriptorWatcher*>(context);
|
||||||
DCHECK_EQ(fdref, controller->fdref_);
|
DCHECK_EQ(fdref, controller->fdref_.get());
|
||||||
|
|
||||||
// Ensure that |fdref| will remain live for the duration of this function
|
// Ensure that |fdref| will remain live for the duration of this function
|
||||||
// call even if |controller| is deleted or |StopWatchingFileDescriptor()| is
|
// call even if |controller| is deleted or |StopWatchingFileDescriptor()| is
|
||||||
@ -194,14 +194,14 @@ void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref,
|
|||||||
// guarantees that |controller| has not been deleted.
|
// guarantees that |controller| has not been deleted.
|
||||||
if (callback_types & kCFFileDescriptorReadCallBack &&
|
if (callback_types & kCFFileDescriptorReadCallBack &&
|
||||||
CFFileDescriptorIsValid(fdref)) {
|
CFFileDescriptorIsValid(fdref)) {
|
||||||
DCHECK_EQ(fdref, controller->fdref_);
|
DCHECK_EQ(fdref, controller->fdref_.get());
|
||||||
controller->OnFileCanReadWithoutBlocking(fd, pump);
|
controller->OnFileCanReadWithoutBlocking(fd, pump);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-enable callbacks after the read/write if the file descriptor is still
|
// Re-enable callbacks after the read/write if the file descriptor is still
|
||||||
// valid and the controller is persistent.
|
// valid and the controller is persistent.
|
||||||
if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) {
|
if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) {
|
||||||
DCHECK_EQ(fdref, controller->fdref_);
|
DCHECK_EQ(fdref, controller->fdref_.get());
|
||||||
CFFileDescriptorEnableCallBacks(fdref, callback_types);
|
CFFileDescriptorEnableCallBacks(fdref, callback_types);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class MessagePumpIOSForIOTest : public testing::Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleFdIOEvent(MessageLoopForIO::FileDescriptorWatcher* watcher) {
|
void HandleFdIOEvent(MessageLoopForIO::FileDescriptorWatcher* watcher) {
|
||||||
MessagePumpIOSForIO::HandleFdIOEvent(watcher->fdref_,
|
MessagePumpIOSForIO::HandleFdIOEvent(watcher->fdref_.get(),
|
||||||
kCFFileDescriptorReadCallBack | kCFFileDescriptorWriteCallBack,
|
kCFFileDescriptorReadCallBack | kCFFileDescriptorWriteCallBack,
|
||||||
watcher);
|
watcher);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,8 @@ TEST_F(ServiceDiscoveryClientMacTest, ServiceResolver) {
|
|||||||
|
|
||||||
ServiceResolverImplMac* resolver_impl =
|
ServiceResolverImplMac* resolver_impl =
|
||||||
static_cast<ServiceResolverImplMac*>(resolver.get());
|
static_cast<ServiceResolverImplMac*>(resolver.get());
|
||||||
resolver_impl->GetContainerForTesting()->SetServiceForTesting(test_service);
|
resolver_impl->GetContainerForTesting()->SetServiceForTesting(
|
||||||
|
test_service.release());
|
||||||
resolver->StartResolving();
|
resolver->StartResolving();
|
||||||
|
|
||||||
resolver_impl->GetContainerForTesting()->OnResolveUpdate(
|
resolver_impl->GetContainerForTesting()->OnResolveUpdate(
|
||||||
|
@ -375,8 +375,7 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
|||||||
// The basic gradient shown inside; see above.
|
// The basic gradient shown inside; see above.
|
||||||
NSGradient* gradient;
|
NSGradient* gradient;
|
||||||
if (hoverAlpha == 0 && !useThemeGradient) {
|
if (hoverAlpha == 0 && !useThemeGradient) {
|
||||||
gradient = defaultGradient ? defaultGradient
|
gradient = defaultGradient ? defaultGradient : gradient_.get();
|
||||||
: gradient_;
|
|
||||||
} else {
|
} else {
|
||||||
gradient = [self gradientForHoverAlpha:hoverAlpha
|
gradient = [self gradientForHoverAlpha:hoverAlpha
|
||||||
isThemed:useThemeGradient];
|
isThemed:useThemeGradient];
|
||||||
|
@ -94,11 +94,11 @@ MEDIA_EXPORT
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
MEDIA_EXPORT
|
MEDIA_EXPORT
|
||||||
@interface CrAVCaptureInput // Originally from AVCaptureInput.h.
|
@interface CrAVCaptureInput : NSObject // Originally from AVCaptureInput.h.
|
||||||
@end
|
@end
|
||||||
|
|
||||||
MEDIA_EXPORT
|
MEDIA_EXPORT
|
||||||
@interface CrAVCaptureOutput // Originally from AVCaptureOutput.h.
|
@interface CrAVCaptureOutput : NSObject // Originally from AVCaptureOutput.h.
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Originally AVCaptureSession and coming from AVCaptureSession.h.
|
// Originally AVCaptureSession and coming from AVCaptureSession.h.
|
||||||
|
@ -64,7 +64,7 @@ launch_data_t MessageForJob(const std::string& job_label,
|
|||||||
const char* operation) {
|
const char* operation) {
|
||||||
// launch_data_alloc returns something that needs to be freed.
|
// launch_data_alloc returns something that needs to be freed.
|
||||||
ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
|
ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
|
||||||
if (!message) {
|
if (!message.is_valid()) {
|
||||||
NSLog(@"launch_data_alloc");
|
NSLog(@"launch_data_alloc");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -74,37 +74,37 @@ launch_data_t MessageForJob(const std::string& job_label,
|
|||||||
// called, so put it in a scoper and .release() it when given to the
|
// called, so put it in a scoper and .release() it when given to the
|
||||||
// dictionary.
|
// dictionary.
|
||||||
ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
|
ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
|
||||||
if (!job_label_launchd) {
|
if (!job_label_launchd.is_valid()) {
|
||||||
NSLog(@"launch_data_new_string");
|
NSLog(@"launch_data_new_string");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!launch_data_dict_insert(message,
|
if (!launch_data_dict_insert(message.get(),
|
||||||
job_label_launchd.release(),
|
job_label_launchd.release(),
|
||||||
operation)) {
|
operation)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return launch_msg(message);
|
return launch_msg(message.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t PIDForJob(const std::string& job_label) {
|
pid_t PIDForJob(const std::string& job_label) {
|
||||||
ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
|
ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
|
||||||
if (!response) {
|
if (!response.is_valid()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_type_t response_type = launch_data_get_type(response);
|
launch_data_type_t response_type = launch_data_get_type(response.get());
|
||||||
if (response_type != LAUNCH_DATA_DICTIONARY) {
|
if (response_type != LAUNCH_DATA_DICTIONARY) {
|
||||||
if (response_type == LAUNCH_DATA_ERRNO) {
|
if (response_type == LAUNCH_DATA_ERRNO) {
|
||||||
NSLog(@"PIDForJob: error %d", launch_data_get_errno(response));
|
NSLog(@"PIDForJob: error %d", launch_data_get_errno(response.get()));
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"PIDForJob: expected dictionary, got %d", response_type);
|
NSLog(@"PIDForJob: expected dictionary, got %d", response_type);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_t pid_data = launch_data_dict_lookup(response,
|
launch_data_t pid_data = launch_data_dict_lookup(response.get(),
|
||||||
LAUNCH_JOBKEY_PID);
|
LAUNCH_JOBKEY_PID);
|
||||||
if (!pid_data)
|
if (!pid_data)
|
||||||
return 0;
|
return 0;
|
||||||
@ -583,7 +583,7 @@ std::string JsonHostConfig::GetSerializedData() const {
|
|||||||
- (BOOL)sendJobControlMessage:(const char*)launch_key {
|
- (BOOL)sendJobControlMessage:(const char*)launch_key {
|
||||||
base::mac::ScopedLaunchData response(
|
base::mac::ScopedLaunchData response(
|
||||||
base::mac::MessageForJob(remoting::kServiceName, launch_key));
|
base::mac::MessageForJob(remoting::kServiceName, launch_key));
|
||||||
if (!response) {
|
if (!response.is_valid()) {
|
||||||
NSLog(@"Failed to send message to launchd");
|
NSLog(@"Failed to send message to launchd");
|
||||||
[self showError];
|
[self showError];
|
||||||
return NO;
|
return NO;
|
||||||
|
2
third_party/crashpad/README.chromium
vendored
2
third_party/crashpad/README.chromium
vendored
@ -37,3 +37,5 @@ $ git am --3way --message-id -p4 /tmp/patchdir
|
|||||||
Local Modifications:
|
Local Modifications:
|
||||||
- Removed references to "base/basictypes.h" and replaced them with appropriate
|
- Removed references to "base/basictypes.h" and replaced them with appropriate
|
||||||
headers.
|
headers.
|
||||||
|
- Updated usage of ScopedLaunchData to use explicit methods rather than the
|
||||||
|
implicit |operator T()| conversion.
|
||||||
|
@ -51,7 +51,8 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchDataDictInsert(dictionary_launch, value_launch, [key UTF8String]);
|
LaunchDataDictInsert(
|
||||||
|
dictionary_launch.get(), value_launch, [key UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_launch = dictionary_launch.release();
|
data_launch = dictionary_launch.release();
|
||||||
@ -71,7 +72,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchDataArraySetIndex(array_launch, element_launch, index++);
|
LaunchDataArraySetIndex(array_launch.get(), element_launch, index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_launch = array_launch.release();
|
data_launch = array_launch.release();
|
||||||
|
@ -28,10 +28,10 @@ namespace {
|
|||||||
launch_data_t LaunchDataDictionaryForJob(const std::string& label) {
|
launch_data_t LaunchDataDictionaryForJob(const std::string& label) {
|
||||||
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
||||||
LaunchDataDictInsert(
|
LaunchDataDictInsert(
|
||||||
request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_GETJOB);
|
request.get(), LaunchDataNewString(label.c_str()), LAUNCH_KEY_GETJOB);
|
||||||
|
|
||||||
base::mac::ScopedLaunchData response(LaunchMsg(request));
|
base::mac::ScopedLaunchData response(LaunchMsg(request.get()));
|
||||||
if (LaunchDataGetType(response) != LAUNCH_DATA_DICTIONARY) {
|
if (LaunchDataGetType(response.get()) != LAUNCH_DATA_DICTIONARY) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,21 +47,21 @@ bool ServiceManagementSubmitJob(CFDictionaryRef job_cf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
base::mac::ScopedLaunchData jobs(LaunchDataAlloc(LAUNCH_DATA_ARRAY));
|
base::mac::ScopedLaunchData jobs(LaunchDataAlloc(LAUNCH_DATA_ARRAY));
|
||||||
LaunchDataArraySetIndex(jobs, job_launch.release(), 0);
|
LaunchDataArraySetIndex(jobs.get(), job_launch.release(), 0);
|
||||||
|
|
||||||
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
||||||
LaunchDataDictInsert(request, jobs.release(), LAUNCH_KEY_SUBMITJOB);
|
LaunchDataDictInsert(request.get(), jobs.release(), LAUNCH_KEY_SUBMITJOB);
|
||||||
|
|
||||||
base::mac::ScopedLaunchData response(LaunchMsg(request));
|
base::mac::ScopedLaunchData response(LaunchMsg(request.get()));
|
||||||
if (LaunchDataGetType(response) != LAUNCH_DATA_ARRAY) {
|
if (LaunchDataGetType(response.get()) != LAUNCH_DATA_ARRAY) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LaunchDataArrayGetCount(response) != 1) {
|
if (LaunchDataArrayGetCount(response.get()) != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_t response_element = LaunchDataArrayGetIndex(response, 0);
|
launch_data_t response_element = LaunchDataArrayGetIndex(response.get(), 0);
|
||||||
if (LaunchDataGetType(response_element) != LAUNCH_DATA_ERRNO) {
|
if (LaunchDataGetType(response_element) != LAUNCH_DATA_ERRNO) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -77,14 +77,14 @@ bool ServiceManagementSubmitJob(CFDictionaryRef job_cf) {
|
|||||||
bool ServiceManagementRemoveJob(const std::string& label, bool wait) {
|
bool ServiceManagementRemoveJob(const std::string& label, bool wait) {
|
||||||
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY));
|
||||||
LaunchDataDictInsert(
|
LaunchDataDictInsert(
|
||||||
request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_REMOVEJOB);
|
request.get(), LaunchDataNewString(label.c_str()), LAUNCH_KEY_REMOVEJOB);
|
||||||
|
|
||||||
base::mac::ScopedLaunchData response(LaunchMsg(request));
|
base::mac::ScopedLaunchData response(LaunchMsg(request.get()));
|
||||||
if (LaunchDataGetType(response) != LAUNCH_DATA_ERRNO) {
|
if (LaunchDataGetType(response.get()) != LAUNCH_DATA_ERRNO) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = LaunchDataGetErrno(response);
|
int err = LaunchDataGetErrno(response.get());
|
||||||
if (err == EINPROGRESS) {
|
if (err == EINPROGRESS) {
|
||||||
if (wait) {
|
if (wait) {
|
||||||
// TODO(mark): Use a kqueue to wait for the process to exit. To avoid a
|
// TODO(mark): Use a kqueue to wait for the process to exit. To avoid a
|
||||||
@ -108,7 +108,7 @@ bool ServiceManagementRemoveJob(const std::string& label, bool wait) {
|
|||||||
|
|
||||||
bool ServiceManagementIsJobLoaded(const std::string& label) {
|
bool ServiceManagementIsJobLoaded(const std::string& label) {
|
||||||
base::mac::ScopedLaunchData dictionary(LaunchDataDictionaryForJob(label));
|
base::mac::ScopedLaunchData dictionary(LaunchDataDictionaryForJob(label));
|
||||||
if (!dictionary) {
|
if (!dictionary.is_valid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,11 +117,11 @@ bool ServiceManagementIsJobLoaded(const std::string& label) {
|
|||||||
|
|
||||||
pid_t ServiceManagementIsJobRunning(const std::string& label) {
|
pid_t ServiceManagementIsJobRunning(const std::string& label) {
|
||||||
base::mac::ScopedLaunchData dictionary(LaunchDataDictionaryForJob(label));
|
base::mac::ScopedLaunchData dictionary(LaunchDataDictionaryForJob(label));
|
||||||
if (!dictionary) {
|
if (!dictionary.is_valid()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch_data_t pid = LaunchDataDictLookup(dictionary, LAUNCH_JOBKEY_PID);
|
launch_data_t pid = LaunchDataDictLookup(dictionary.get(), LAUNCH_JOBKEY_PID);
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ namespace base {
|
|||||||
template<>
|
template<>
|
||||||
struct ScopedTypeRefTraits<CVDisplayLinkRef> {
|
struct ScopedTypeRefTraits<CVDisplayLinkRef> {
|
||||||
static CVDisplayLinkRef InvalidValue() { return nullptr; }
|
static CVDisplayLinkRef InvalidValue() { return nullptr; }
|
||||||
static void Retain(CVDisplayLinkRef object) {
|
static CVDisplayLinkRef Retain(CVDisplayLinkRef object) {
|
||||||
CVDisplayLinkRetain(object);
|
return CVDisplayLinkRetain(object);
|
||||||
}
|
}
|
||||||
static void Release(CVDisplayLinkRef object) {
|
static void Release(CVDisplayLinkRef object) {
|
||||||
CVDisplayLinkRelease(object);
|
CVDisplayLinkRelease(object);
|
||||||
|
@ -16,8 +16,8 @@ namespace base {
|
|||||||
template<>
|
template<>
|
||||||
struct ScopedTypeRefTraits<CGLContextObj> {
|
struct ScopedTypeRefTraits<CGLContextObj> {
|
||||||
static CGLContextObj InvalidValue() { return nullptr; }
|
static CGLContextObj InvalidValue() { return nullptr; }
|
||||||
static void Retain(CGLContextObj object) {
|
static CGLContextObj Retain(CGLContextObj object) {
|
||||||
CGLRetainContext(object);
|
return CGLRetainContext(object);
|
||||||
}
|
}
|
||||||
static void Release(CGLContextObj object) {
|
static void Release(CGLContextObj object) {
|
||||||
CGLReleaseContext(object);
|
CGLReleaseContext(object);
|
||||||
@ -27,8 +27,8 @@ struct ScopedTypeRefTraits<CGLContextObj> {
|
|||||||
template<>
|
template<>
|
||||||
struct ScopedTypeRefTraits<CGLPixelFormatObj> {
|
struct ScopedTypeRefTraits<CGLPixelFormatObj> {
|
||||||
static CGLPixelFormatObj InvalidValue() { return nullptr; }
|
static CGLPixelFormatObj InvalidValue() { return nullptr; }
|
||||||
static void Retain(CGLPixelFormatObj object) {
|
static CGLPixelFormatObj Retain(CGLPixelFormatObj object) {
|
||||||
CGLRetainPixelFormat(object);
|
return CGLRetainPixelFormat(object);
|
||||||
}
|
}
|
||||||
static void Release(CGLPixelFormatObj object) {
|
static void Release(CGLPixelFormatObj object) {
|
||||||
CGLReleasePixelFormat(object);
|
CGLReleasePixelFormat(object);
|
||||||
|
Reference in New Issue
Block a user