Remove some more unused stuff, mostly Mac Change-Id: Iee501f3f1280f16e9143c6adcd4d1118e06bb2e2 Reviewed-on: https://gn-review.googlesource.com/1760 Reviewed-by: Petr Hosek <phosek@google.com> Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/bit_cast.h b/base/bit_cast.h deleted file mode 100644 index 30a44c5..0000000 --- a/base/bit_cast.h +++ /dev/null
@@ -1,77 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_BIT_CAST_H_ -#define BASE_BIT_CAST_H_ - -#include <string.h> -#include <type_traits> - -#include "base/compiler_specific.h" -#include "base/template_util.h" -#include "util/build_config.h" - -// bit_cast<Dest,Source> is a template function that implements the equivalent -// of "*reinterpret_cast<Dest*>(&source)". We need this in very low-level -// functions like the protobuf library and fast math support. -// -// float f = 3.14159265358979; -// int i = bit_cast<int32_t>(f); -// // i = 0x40490fdb -// -// The classical address-casting method is: -// -// // WRONG -// float f = 3.14159265358979; // WRONG -// int i = * reinterpret_cast<int*>(&f); // WRONG -// -// The address-casting method actually produces undefined behavior according to -// the ISO C++98 specification, section 3.10 ("basic.lval"), paragraph 15. -// (This did not substantially change in C++11.) Roughly, this section says: if -// an object in memory has one type, and a program accesses it with a different -// type, then the result is undefined behavior for most values of "different -// type". -// -// This is true for any cast syntax, either *(int*)&f or -// *reinterpret_cast<int*>(&f). And it is particularly true for conversions -// between integral lvalues and floating-point lvalues. -// -// The purpose of this paragraph is to allow optimizing compilers to assume that -// expressions with different types refer to different memory. Compilers are -// known to take advantage of this. So a non-conforming program quietly -// produces wildly incorrect output. -// -// The problem is not the use of reinterpret_cast. The problem is type punning: -// holding an object in memory of one type and reading its bits back using a -// different type. -// -// The C++ standard is more subtle and complex than this, but that is the basic -// idea. -// -// Anyways ... -// -// bit_cast<> calls memcpy() which is blessed by the standard, especially by the -// example in section 3.9 . Also, of course, bit_cast<> wraps up the nasty -// logic in one place. -// -// Fortunately memcpy() is very fast. In optimized mode, compilers replace -// calls to memcpy() with inline object code when the size argument is a -// compile-time constant. On a 32-bit system, memcpy(d,s,4) compiles to one -// load and one store, and memcpy(d,s,8) compiles to two loads and two stores. - -template <class Dest, class Source> -inline Dest bit_cast(const Source& source) { - static_assert(sizeof(Dest) == sizeof(Source), - "bit_cast requires source and destination to be the same size"); - static_assert(base::is_trivially_copyable<Dest>::value, - "bit_cast requires the destination type to be copyable"); - static_assert(base::is_trivially_copyable<Source>::value, - "bit_cast requires the source type to be copyable"); - - Dest dest; - memcpy(&dest, &source, sizeof(dest)); - return dest; -} - -#endif // BASE_BIT_CAST_H_
diff --git a/base/callback_list.h b/base/callback_list.h deleted file mode 100644 index cced145..0000000 --- a/base/callback_list.h +++ /dev/null
@@ -1,221 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_CALLBACK_LIST_H_ -#define BASE_CALLBACK_LIST_H_ - -#include <list> -#include <memory> - -#include "base/callback.h" -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/macros.h" - -// OVERVIEW: -// -// A container for a list of (repeating) callbacks. Unlike a normal vector or -// list, this container can be modified during iteration without invalidating -// the iterator. It safely handles the case of a callback removing itself or -// another callback from the list while callbacks are being run. -// -// TYPICAL USAGE: -// -// class MyWidget { -// public: -// ... -// -// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription> -// RegisterCallback(const base::RepeatingCallback<void(const Foo&)>& cb) { -// return callback_list_.Add(cb); -// } -// -// private: -// void NotifyFoo(const Foo& foo) { -// callback_list_.Notify(foo); -// } -// -// base::CallbackList<void(const Foo&)> callback_list_; -// -// DISALLOW_COPY_AND_ASSIGN(MyWidget); -// }; -// -// -// class MyWidgetListener { -// public: -// MyWidgetListener::MyWidgetListener() { -// foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( -// base::BindRepeating(&MyWidgetListener::OnFoo, this))); -// } -// -// MyWidgetListener::~MyWidgetListener() { -// // Subscription gets deleted automatically and will deregister -// // the callback in the process. -// } -// -// private: -// void OnFoo(const Foo& foo) { -// // Do something. -// } -// -// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription> -// foo_subscription_; -// -// DISALLOW_COPY_AND_ASSIGN(MyWidgetListener); -// }; - -namespace base { - -namespace internal { - -template <typename CallbackType> -class CallbackListBase { - public: - class Subscription { - public: - Subscription(CallbackListBase<CallbackType>* list, - typename std::list<CallbackType>::iterator iter) - : list_(list), iter_(iter) {} - - ~Subscription() { - if (list_->active_iterator_count_) { - iter_->Reset(); - } else { - list_->callbacks_.erase(iter_); - if (!list_->removal_callback_.is_null()) - list_->removal_callback_.Run(); - } - } - - private: - CallbackListBase<CallbackType>* list_; - typename std::list<CallbackType>::iterator iter_; - - DISALLOW_COPY_AND_ASSIGN(Subscription); - }; - - // Add a callback to the list. The callback will remain registered until the - // returned Subscription is destroyed, which must occur before the - // CallbackList is destroyed. - std::unique_ptr<Subscription> Add(const CallbackType& cb) WARN_UNUSED_RESULT { - DCHECK(!cb.is_null()); - return std::make_unique<Subscription>( - this, callbacks_.insert(callbacks_.end(), cb)); - } - - // Sets a callback which will be run when a subscription list is changed. - void set_removal_callback(const RepeatingClosure& callback) { - removal_callback_ = callback; - } - - // Returns true if there are no subscriptions. This is only valid to call when - // not looping through the list. - bool empty() { - DCHECK_EQ(0, active_iterator_count_); - return callbacks_.empty(); - } - - protected: - // An iterator class that can be used to access the list of callbacks. - class Iterator { - public: - explicit Iterator(CallbackListBase<CallbackType>* list) - : list_(list), list_iter_(list_->callbacks_.begin()) { - ++list_->active_iterator_count_; - } - - Iterator(const Iterator& iter) - : list_(iter.list_), list_iter_(iter.list_iter_) { - ++list_->active_iterator_count_; - } - - ~Iterator() { - if (list_ && --list_->active_iterator_count_ == 0) { - list_->Compact(); - } - } - - CallbackType* GetNext() { - while ((list_iter_ != list_->callbacks_.end()) && list_iter_->is_null()) - ++list_iter_; - - CallbackType* cb = nullptr; - if (list_iter_ != list_->callbacks_.end()) { - cb = &(*list_iter_); - ++list_iter_; - } - return cb; - } - - private: - CallbackListBase<CallbackType>* list_; - typename std::list<CallbackType>::iterator list_iter_; - }; - - CallbackListBase() : active_iterator_count_(0) {} - - ~CallbackListBase() { - DCHECK_EQ(0, active_iterator_count_); - DCHECK_EQ(0U, callbacks_.size()); - } - - // Returns an instance of a CallbackListBase::Iterator which can be used - // to run callbacks. - Iterator GetIterator() { return Iterator(this); } - - // Compact the list: remove any entries which were nulled out during - // iteration. - void Compact() { - auto it = callbacks_.begin(); - bool updated = false; - while (it != callbacks_.end()) { - if ((*it).is_null()) { - updated = true; - it = callbacks_.erase(it); - } else { - ++it; - } - } - - if (updated && !removal_callback_.is_null()) - removal_callback_.Run(); - } - - private: - std::list<CallbackType> callbacks_; - int active_iterator_count_; - RepeatingClosure removal_callback_; - - DISALLOW_COPY_AND_ASSIGN(CallbackListBase); -}; - -} // namespace internal - -template <typename Sig> -class CallbackList; - -template <typename... Args> -class CallbackList<void(Args...)> - : public internal::CallbackListBase<RepeatingCallback<void(Args...)>> { - public: - using CallbackType = RepeatingCallback<void(Args...)>; - - CallbackList() = default; - - template <typename... RunArgs> - void Notify(RunArgs&&... args) { - auto it = this->GetIterator(); - CallbackType* cb; - while ((cb = it.GetNext()) != nullptr) { - cb->Run(args...); - } - } - - private: - DISALLOW_COPY_AND_ASSIGN(CallbackList); -}; - -} // namespace base - -#endif // BASE_CALLBACK_LIST_H_
diff --git a/base/json/json_file_value_serializer.cc b/base/json/json_file_value_serializer.cc deleted file mode 100644 index f87019d..0000000 --- a/base/json/json_file_value_serializer.cc +++ /dev/null
@@ -1,114 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/json/json_file_value_serializer.h" - -#include "base/files/file_util.h" -#include "base/json/json_string_value_serializer.h" -#include "base/logging.h" -#include "util/build_config.h" - -using base::FilePath; - -const char JSONFileValueDeserializer::kAccessDenied[] = "Access denied."; -const char JSONFileValueDeserializer::kCannotReadFile[] = "Can't read file."; -const char JSONFileValueDeserializer::kFileLocked[] = "File locked."; -const char JSONFileValueDeserializer::kNoSuchFile[] = "File doesn't exist."; - -JSONFileValueSerializer::JSONFileValueSerializer( - const base::FilePath& json_file_path) - : json_file_path_(json_file_path) {} - -JSONFileValueSerializer::~JSONFileValueSerializer() = default; - -bool JSONFileValueSerializer::Serialize(const base::Value& root) { - return SerializeInternal(root, false); -} - -bool JSONFileValueSerializer::SerializeAndOmitBinaryValues( - const base::Value& root) { - return SerializeInternal(root, true); -} - -bool JSONFileValueSerializer::SerializeInternal(const base::Value& root, - bool omit_binary_values) { - std::string json_string; - JSONStringValueSerializer serializer(&json_string); - serializer.set_pretty_print(true); - bool result = omit_binary_values - ? serializer.SerializeAndOmitBinaryValues(root) - : serializer.Serialize(root); - if (!result) - return false; - - int data_size = static_cast<int>(json_string.size()); - if (base::WriteFile(json_file_path_, json_string.data(), data_size) != - data_size) - return false; - - return true; -} - -JSONFileValueDeserializer::JSONFileValueDeserializer( - const base::FilePath& json_file_path, - int options) - : json_file_path_(json_file_path), options_(options), last_read_size_(0U) {} - -JSONFileValueDeserializer::~JSONFileValueDeserializer() = default; - -int JSONFileValueDeserializer::ReadFileToString(std::string* json_string) { - DCHECK(json_string); - if (!base::ReadFileToString(json_file_path_, json_string)) { -#if defined(OS_WIN) - int error = ::GetLastError(); - if (error == ERROR_SHARING_VIOLATION || error == ERROR_LOCK_VIOLATION) { - return JSON_FILE_LOCKED; - } else if (error == ERROR_ACCESS_DENIED) { - return JSON_ACCESS_DENIED; - } -#endif - if (!base::PathExists(json_file_path_)) - return JSON_NO_SUCH_FILE; - else - return JSON_CANNOT_READ_FILE; - } - - last_read_size_ = json_string->size(); - return JSON_NO_ERROR; -} - -const char* JSONFileValueDeserializer::GetErrorMessageForCode(int error_code) { - switch (error_code) { - case JSON_NO_ERROR: - return ""; - case JSON_ACCESS_DENIED: - return kAccessDenied; - case JSON_CANNOT_READ_FILE: - return kCannotReadFile; - case JSON_FILE_LOCKED: - return kFileLocked; - case JSON_NO_SUCH_FILE: - return kNoSuchFile; - default: - NOTREACHED(); - return ""; - } -} - -std::unique_ptr<base::Value> JSONFileValueDeserializer::Deserialize( - int* error_code, - std::string* error_str) { - std::string json_string; - int error = ReadFileToString(&json_string); - if (error != JSON_NO_ERROR) { - if (error_code) - *error_code = error; - if (error_str) - *error_str = GetErrorMessageForCode(error); - return nullptr; - } - - JSONStringValueDeserializer deserializer(json_string, options_); - return deserializer.Deserialize(error_code, error_str); -}
diff --git a/base/json/json_file_value_serializer.h b/base/json/json_file_value_serializer.h deleted file mode 100644 index b260543..0000000 --- a/base/json/json_file_value_serializer.h +++ /dev/null
@@ -1,101 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_ -#define BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_ - -#include <stddef.h> - -#include <string> - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/values.h" - -class JSONFileValueSerializer : public base::ValueSerializer { - public: - // |json_file_path_| is the path of a file that will be destination of the - // serialization. The serializer will attempt to create the file at the - // specified location. - explicit JSONFileValueSerializer(const base::FilePath& json_file_path); - - ~JSONFileValueSerializer() override; - - // DO NOT USE except in unit tests to verify the file was written properly. - // We should never serialize directly to a file since this will block the - // thread. Instead, serialize to a string and write to the file you want on - // the file thread. - // - // Attempt to serialize the data structure represented by Value into - // JSON. If the return value is true, the result will have been written - // into the file whose name was passed into the constructor. - bool Serialize(const base::Value& root) override; - - // Equivalent to Serialize(root) except binary values are omitted from the - // output. - bool SerializeAndOmitBinaryValues(const base::Value& root); - - private: - bool SerializeInternal(const base::Value& root, bool omit_binary_values); - - const base::FilePath json_file_path_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); -}; - -class JSONFileValueDeserializer : public base::ValueDeserializer { - public: - // |json_file_path_| is the path of a file that will be source of the - // deserialization. |options| is a bitmask of JSONParserOptions. - explicit JSONFileValueDeserializer(const base::FilePath& json_file_path, - int options = 0); - - ~JSONFileValueDeserializer() override; - - // Attempt to deserialize the data structure encoded in the file passed - // in to the constructor into a structure of Value objects. If the return - // value is NULL, and if |error_code| is non-null, |error_code| will - // contain an integer error code (either JsonFileError or JsonParseError). - // If |error_message| is non-null, it will be filled in with a formatted - // error message including the location of the error if appropriate. - // The caller takes ownership of the returned value. - std::unique_ptr<base::Value> Deserialize(int* error_code, - std::string* error_message) override; - - // This enum is designed to safely overlap with JSONReader::JsonParseError. - enum JsonFileError { - JSON_NO_ERROR = 0, - JSON_ACCESS_DENIED = 1000, - JSON_CANNOT_READ_FILE, - JSON_FILE_LOCKED, - JSON_NO_SUCH_FILE - }; - - // File-specific error messages that can be returned. - static const char kAccessDenied[]; - static const char kCannotReadFile[]; - static const char kFileLocked[]; - static const char kNoSuchFile[]; - - // Convert an error code into an error message. |error_code| is assumed to - // be a JsonFileError. - static const char* GetErrorMessageForCode(int error_code); - - // Returns the size (in bytes) of JSON string read from disk in the last - // successful |Deserialize()| call. - size_t get_last_read_size() const { return last_read_size_; } - - private: - // A wrapper for ReadFileToString which returns a non-zero JsonFileError if - // there were file errors. - int ReadFileToString(std::string* json_string); - - const base::FilePath json_file_path_; - const int options_; - size_t last_read_size_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueDeserializer); -}; - -#endif // BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_
diff --git a/base/json/json_string_value_serializer.cc b/base/json/json_string_value_serializer.cc deleted file mode 100644 index 0c979b7..0000000 --- a/base/json/json_string_value_serializer.cc +++ /dev/null
@@ -1,53 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/json/json_string_value_serializer.h" - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/logging.h" - -using base::Value; - -JSONStringValueSerializer::JSONStringValueSerializer(std::string* json_string) - : json_string_(json_string), pretty_print_(false) {} - -JSONStringValueSerializer::~JSONStringValueSerializer() = default; - -bool JSONStringValueSerializer::Serialize(const Value& root) { - return SerializeInternal(root, false); -} - -bool JSONStringValueSerializer::SerializeAndOmitBinaryValues( - const Value& root) { - return SerializeInternal(root, true); -} - -bool JSONStringValueSerializer::SerializeInternal(const Value& root, - bool omit_binary_values) { - if (!json_string_) - return false; - - int options = 0; - if (omit_binary_values) - options |= base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES; - if (pretty_print_) - options |= base::JSONWriter::OPTIONS_PRETTY_PRINT; - - return base::JSONWriter::WriteWithOptions(root, options, json_string_); -} - -JSONStringValueDeserializer::JSONStringValueDeserializer( - const base::StringPiece& json_string, - int options) - : json_string_(json_string), options_(options) {} - -JSONStringValueDeserializer::~JSONStringValueDeserializer() = default; - -std::unique_ptr<Value> JSONStringValueDeserializer::Deserialize( - int* error_code, - std::string* error_str) { - return base::JSONReader::ReadAndReturnError(json_string_, options_, - error_code, error_str); -}
diff --git a/base/json/json_string_value_serializer.h b/base/json/json_string_value_serializer.h deleted file mode 100644 index 1a34484..0000000 --- a/base/json/json_string_value_serializer.h +++ /dev/null
@@ -1,74 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_ -#define BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_ - -#include <string> - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/strings/string_piece.h" -#include "base/values.h" - -class JSONStringValueSerializer : public base::ValueSerializer { - public: - // |json_string| is the string that will be the destination of the - // serialization. The caller of the constructor retains ownership of the - // string. |json_string| must not be null. - explicit JSONStringValueSerializer(std::string* json_string); - - ~JSONStringValueSerializer() override; - - // Attempt to serialize the data structure represented by Value into - // JSON. If the return value is true, the result will have been written - // into the string passed into the constructor. - bool Serialize(const base::Value& root) override; - - // Equivalent to Serialize(root) except binary values are omitted from the - // output. - bool SerializeAndOmitBinaryValues(const base::Value& root); - - void set_pretty_print(bool new_value) { pretty_print_ = new_value; } - bool pretty_print() { return pretty_print_; } - - private: - bool SerializeInternal(const base::Value& root, bool omit_binary_values); - - // Owned by the caller of the constructor. - std::string* json_string_; - bool pretty_print_; // If true, serialization will span multiple lines. - - DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer); -}; - -class JSONStringValueDeserializer : public base::ValueDeserializer { - public: - // This retains a reference to the contents of |json_string|, so the data - // must outlive the JSONStringValueDeserializer. |options| is a bitmask of - // JSONParserOptions. - explicit JSONStringValueDeserializer(const base::StringPiece& json_string, - int options = 0); - - ~JSONStringValueDeserializer() override; - - // Attempt to deserialize the data structure encoded in the string passed - // in to the constructor into a structure of Value objects. If the return - // value is null, and if |error_code| is non-null, |error_code| will - // contain an integer error code (a JsonParseError in this case). - // If |error_message| is non-null, it will be filled in with a formatted - // error message including the location of the error if appropriate. - // The caller takes ownership of the returned value. - std::unique_ptr<base::Value> Deserialize(int* error_code, - std::string* error_message) override; - - private: - // Data is owned by the caller of the constructor. - base::StringPiece json_string_; - const int options_; - - DISALLOW_COPY_AND_ASSIGN(JSONStringValueDeserializer); -}; - -#endif // BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
diff --git a/base/mac/availability.h b/base/mac/availability.h deleted file mode 100644 index 6d0bcc7..0000000 --- a/base/mac/availability.h +++ /dev/null
@@ -1,35 +0,0 @@ -// Copyright (c) 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Provides the definition of API_AVAILABLE while we're on an SDK that doesn't -// contain it yet. -// TODO(thakis): Remove this file once we're on the 10.12 SDK. - -#ifndef BASE_MAC_AVAILABILITY_H_ -#define BASE_MAC_AVAILABILITY_H_ - -#include <AvailabilityMacros.h> - -#if !defined(MAC_OS_X_VERSION_10_12) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 -#define __API_AVAILABLE_PLATFORM_macos(x) macos, introduced = x -#define __API_AVAILABLE_PLATFORM_macosx(x) macosx, introduced = x -#define __API_AVAILABLE_PLATFORM_ios(x) ios, introduced = x -#define __API_AVAILABLE_PLATFORM_watchos(x) watchos, introduced = x -#define __API_AVAILABLE_PLATFORM_tvos(x) tvos, introduced = x -#define __API_A(x) __attribute__((availability(__API_AVAILABLE_PLATFORM_##x))) -#define __API_AVAILABLE1(x) __API_A(x) -#define __API_AVAILABLE2(x, y) __API_A(x) __API_A(y) -#define __API_AVAILABLE3(x, y, z) __API_A(x) __API_A(y) __API_A(z) -#define __API_AVAILABLE4(x, y, z, t) __API_A(x) __API_A(y) __API_A(z) __API_A(t) -#define __API_AVAILABLE_GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME -#define API_AVAILABLE(...) \ - __API_AVAILABLE_GET_MACRO(__VA_ARGS__, __API_AVAILABLE4, __API_AVAILABLE3, \ - __API_AVAILABLE2, __API_AVAILABLE1) \ - (__VA_ARGS__) -#else -#import <os/availability.h> -#endif // MAC_OS_X_VERSION_10_12 - -#endif // BASE_MAC_AVAILABILITY_H_
diff --git a/base/mac/bind_objc_block.h b/base/mac/bind_objc_block.h deleted file mode 100644 index 87d38bf..0000000 --- a/base/mac/bind_objc_block.h +++ /dev/null
@@ -1,79 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_BIND_OBJC_BLOCK_H_ -#define BASE_MAC_BIND_OBJC_BLOCK_H_ - -#include <Block.h> - -#include "base/bind.h" -#include "base/callback_forward.h" -#include "base/compiler_specific.h" -#include "base/mac/scoped_block.h" - -// BindBlock builds a callback from an Objective-C block. Example usages: -// -// Closure closure = BindBlock(^{DoSomething();}); -// -// Callback<int(void)> callback = BindBlock(^{return 42;}); -// -// Callback<void(const std::string&, const std::string&)> callback = -// BindBlock(^(const std::string& arg0, const std::string& arg1) { -// ... -// }); -// -// These variadic templates will accommodate any number of arguments, however -// the underlying templates in bind_internal.h and callback.h are limited to -// seven total arguments, and the bound block itself is used as one of these -// arguments, so functionally the templates are limited to binding blocks with -// zero through six arguments. -// -// For code compiled with ARC (automatic reference counting), use BindBlockArc. -// This is because the method has a different implementation (to avoid over- -// retaining the block) and need to have a different name not to break the ODR -// (one definition rule). Another subtle difference is that the implementation -// will call a different version of ScopedBlock constructor thus the linker must -// not merge both functions. - -namespace base { - -namespace internal { - -// Helper function to run the block contained in the parameter. -template <typename R, typename... Args> -R RunBlock(base::mac::ScopedBlock<R (^)(Args...)> block, Args... args) { - R (^extracted_block)(Args...) = block.get(); - return extracted_block(args...); -} - -} // namespace internal - -#if !defined(__has_feature) || !__has_feature(objc_arc) - -// Construct a callback from an objective-C block with up to six arguments (see -// note above). -template <typename R, typename... Args> -base::Callback<R(Args...)> BindBlock(R (^block)(Args...)) { - return base::Bind( - &base::internal::RunBlock<R, Args...>, - base::mac::ScopedBlock<R (^)(Args...)>( - base::mac::internal::ScopedBlockTraits<R (^)(Args...)>::Retain( - block))); -} - -#else - -// Construct a callback from an objective-C block with up to six arguments (see -// note above). -template <typename R, typename... Args> -base::Callback<R(Args...)> BindBlockArc(R (^block)(Args...)) { - return base::Bind(&base::internal::RunBlock<R, Args...>, - base::mac::ScopedBlock<R (^)(Args...)>(block)); -} - -#endif - -} // namespace base - -#endif // BASE_MAC_BIND_OBJC_BLOCK_H_
diff --git a/base/mac/dispatch_source_mach.cc b/base/mac/dispatch_source_mach.cc deleted file mode 100644 index 50da7e4..0000000 --- a/base/mac/dispatch_source_mach.cc +++ /dev/null
@@ -1,50 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/dispatch_source_mach.h" - -namespace base { - -DispatchSourceMach::DispatchSourceMach(const char* name, - mach_port_t port, - void (^event_handler)()) - // TODO(rsesek): Specify DISPATCH_QUEUE_SERIAL, in the 10.7 SDK. NULL - // means the same thing but is not symbolically clear. - : DispatchSourceMach(dispatch_queue_create(name, NULL), - port, - event_handler) { - // Since the queue was created above in the delegated constructor, and it was - // subsequently retained, release it here. - dispatch_release(queue_); -} - -DispatchSourceMach::DispatchSourceMach(dispatch_queue_t queue, - mach_port_t port, - void (^event_handler)()) - : queue_(queue, base::scoped_policy::RETAIN), - source_(dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, - port, - 0, - queue_)), - source_canceled_(dispatch_semaphore_create(0)) { - dispatch_source_set_event_handler(source_, event_handler); - dispatch_source_set_cancel_handler(source_, ^{ - dispatch_semaphore_signal(source_canceled_); - }); -} - -DispatchSourceMach::~DispatchSourceMach() { - // Cancel the source and wait for the semaphore to be signaled. This will - // ensure the source managed by this class is not used after it is freed. - dispatch_source_cancel(source_); - source_.reset(); - - dispatch_semaphore_wait(source_canceled_, DISPATCH_TIME_FOREVER); -} - -void DispatchSourceMach::Resume() { - dispatch_resume(source_); -} - -} // namespace base
diff --git a/base/mac/dispatch_source_mach.h b/base/mac/dispatch_source_mach.h deleted file mode 100644 index 84af3b3..0000000 --- a/base/mac/dispatch_source_mach.h +++ /dev/null
@@ -1,57 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_DISPATCH_SOURCE_MACH_H_ -#define BASE_MAC_DISPATCH_SOURCE_MACH_H_ - -#include <dispatch/dispatch.h> - -#include "base/mac/scoped_dispatch_object.h" -#include "base/macros.h" - -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 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, - // the |event_handler| will be called. - DispatchSourceMach(const char* name, - mach_port_t port, - void (^event_handler)()); - - // Creates a new dispatch source with the same semantics as above, but rather - // than creating a new queue, it schedules the source on |queue|. - DispatchSourceMach(dispatch_queue_t queue, - mach_port_t port, - void (^event_handler)()); - - // Cancels the source and waits for it to become fully cancelled before - // releasing the source. - ~DispatchSourceMach(); - - // Resumes the source. This must be called before any Mach messages will - // be received. - void Resume(); - - private: - // The dispatch queue used to service the source_. - ScopedDispatchObject<dispatch_queue_t> queue_; - - // A MACH_RECV dispatch source. - ScopedDispatchObject<dispatch_source_t> source_; - - // Semaphore used to wait on the |source_|'s cancellation in the destructor. - ScopedDispatchObject<dispatch_semaphore_t> source_canceled_; - - DISALLOW_COPY_AND_ASSIGN(DispatchSourceMach); -}; - -} // namespace base - -#endif // BASE_MAC_DISPATCH_SOURCE_MACH_H_
diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h deleted file mode 100644 index c4fcd33..0000000 --- a/base/mac/mac_util.h +++ /dev/null
@@ -1,179 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_MAC_UTIL_H_ -#define BASE_MAC_MAC_UTIL_H_ - -#include <stdint.h> -#include <string> - -#import <CoreGraphics/CoreGraphics.h> - -namespace base { - -class FilePath; - -namespace mac { - -// Full screen modes, in increasing order of priority. More permissive modes -// take predecence. -enum FullScreenMode { - kFullScreenModeHideAll = 0, - kFullScreenModeHideDock = 1, - kFullScreenModeAutoHideAll = 2, - kNumFullScreenModes = 3, - - // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to - // other classes, so we include it here. - kFullScreenModeNormal = 10, -}; - -// Returns an sRGB color space. The return value is a static value; do not -// release it! -CGColorSpaceRef GetSRGBColorSpace(); - -// Returns the generic RGB color space. The return value is a static value; do -// not release it! -CGColorSpaceRef GetGenericRGBColorSpace(); - -// Returns the color space being used by the main display. The return value -// is a static value; do not release it! -CGColorSpaceRef GetSystemColorSpace(); - -// Add a full screen request for the given |mode|. Must be paired with a -// ReleaseFullScreen() call for the same |mode|. This does not by itself create -// a fullscreen window; rather, it manages per-application state related to -// hiding the dock and menubar. Must be called on the main thread. -void RequestFullScreen(FullScreenMode mode); - -// Release a request for full screen mode. Must be matched with a -// RequestFullScreen() call for the same |mode|. As with RequestFullScreen(), -// this does not affect windows directly, but rather manages per-application -// state. For example, if there are no other outstanding -// |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar. Must -// be called on main thread. -void ReleaseFullScreen(FullScreenMode mode); - -// Convenience method to switch the current fullscreen mode. This has the same -// net effect as a ReleaseFullScreen(from_mode) call followed immediately by a -// RequestFullScreen(to_mode). Must be called on the main thread. -void SwitchFullScreenModes(FullScreenMode from_mode, FullScreenMode to_mode); - -// Excludes the file given by |file_path| from being backed up by Time Machine. -bool SetFileBackupExclusion(const FilePath& file_path); - -// Checks if the current application is set as a Login Item, so it will launch -// on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also -// is queried for the 'hide on launch' flag. -bool CheckLoginItemStatus(bool* is_hidden); - -// Adds current application to the set of Login Items with specified "hide" -// flag. This has the same effect as adding/removing the application in -// SystemPreferences->Accounts->LoginItems or marking Application in the Dock -// as "Options->Open on Login". -// Does nothing if the application is already set up as Login Item with -// specified hide flag. -void AddToLoginItems(bool hide_on_startup); - -// Removes the current application from the list Of Login Items. -void RemoveFromLoginItems(); - -// Returns true if the current process was automatically launched as a -// 'Login Item' or via Lion's Resume. Used to suppress opening windows. -bool WasLaunchedAsLoginOrResumeItem(); - -// Returns true if the current process was automatically launched as a -// 'Login Item' or via Resume, and the 'Reopen windows when logging back in' -// checkbox was selected by the user. This indicates that the previous -// session should be restored. -bool WasLaunchedAsLoginItemRestoreState(); - -// Returns true if the current process was automatically launched as a -// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows. -bool WasLaunchedAsHiddenLoginItem(); - -// Remove the quarantine xattr from the given file. Returns false if there was -// an error, or true otherwise. -bool RemoveQuarantineAttribute(const FilePath& file_path); - -namespace internal { - -// Returns the system's Mac OS X minor version. This is the |y| value -// in 10.y or 10.y.z. -int MacOSXMinorVersion(); - -} // namespace internal - -// Run-time OS version checks. Use these instead of -// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "AtLeast" and -// "AtMost" variants to those that check for a specific version, unless you -// know for sure that you need to check for a specific version. - -#define DEFINE_IS_OS_FUNCS(V, TEST_DEPLOYMENT_TARGET) \ - inline bool IsOS10_##V() { \ - TEST_DEPLOYMENT_TARGET(>, V, false) \ - return internal::MacOSXMinorVersion() == V; \ - } \ - inline bool IsAtLeastOS10_##V() { \ - TEST_DEPLOYMENT_TARGET(>=, V, true) \ - return internal::MacOSXMinorVersion() >= V; \ - } \ - inline bool IsAtMostOS10_##V() { \ - TEST_DEPLOYMENT_TARGET(>, V, false) \ - return internal::MacOSXMinorVersion() <= V; \ - } - -#define TEST_DEPLOYMENT_TARGET(OP, V, RET) \ - if (MAC_OS_X_VERSION_MIN_REQUIRED OP MAC_OS_X_VERSION_10_##V) \ - return RET; -#define IGNORE_DEPLOYMENT_TARGET(OP, V, RET) - -DEFINE_IS_OS_FUNCS(9, TEST_DEPLOYMENT_TARGET) -DEFINE_IS_OS_FUNCS(10, TEST_DEPLOYMENT_TARGET) - -#ifdef MAC_OS_X_VERSION_10_11 -DEFINE_IS_OS_FUNCS(11, TEST_DEPLOYMENT_TARGET) -#else -DEFINE_IS_OS_FUNCS(11, IGNORE_DEPLOYMENT_TARGET) -#endif - -#ifdef MAC_OS_X_VERSION_10_12 -DEFINE_IS_OS_FUNCS(12, TEST_DEPLOYMENT_TARGET) -#else -DEFINE_IS_OS_FUNCS(12, IGNORE_DEPLOYMENT_TARGET) -#endif - -#ifdef MAC_OS_X_VERSION_10_13 -DEFINE_IS_OS_FUNCS(13, TEST_DEPLOYMENT_TARGET) -#else -DEFINE_IS_OS_FUNCS(13, IGNORE_DEPLOYMENT_TARGET) -#endif - -#undef IGNORE_DEPLOYMENT_TARGET -#undef TEST_DEPLOYMENT_TARGET -#undef DEFINE_IS_OS_FUNCS - -// This should be infrequently used. It only makes sense to use this to avoid -// codepaths that are very likely to break on future (unreleased, untested, -// unborn) OS releases, or to log when the OS is newer than any known version. -inline bool IsOSLaterThan10_13_DontCallThis() { - return !IsAtMostOS10_13(); -} - -// Retrieve the system's model identifier string from the IOKit registry: -// for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon -// failure. -std::string GetModelIdentifier(); - -// Parse a model identifier string; for example, into ("MacBookPro", 6, 1). -// If any error occurs, none of the input pointers are touched. -bool ParseModelIdentifier(const std::string& ident, - std::string* type, - int32_t* major, - int32_t* minor); - -} // namespace mac -} // namespace base - -#endif // BASE_MAC_MAC_UTIL_H_
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm deleted file mode 100644 index bb8797d..0000000 --- a/base/mac/mac_util.mm +++ /dev/null
@@ -1,480 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/mac_util.h" - -#import <Cocoa/Cocoa.h> -#import <IOKit/IOKitLib.h> -#include <errno.h> -#include <stddef.h> -#include <string.h> -#include <sys/utsname.h> -#include <sys/xattr.h> - -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/mac/bundle_locations.h" -#include "base/mac/foundation_util.h" -#include "base/mac/mac_logging.h" -#include "base/mac/scoped_cftyperef.h" -#include "base/mac/scoped_ioobject.h" -#include "base/mac/scoped_nsobject.h" -#include "base/mac/sdk_forward_declarations.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_piece.h" -#include "base/strings/sys_string_conversions.h" - -namespace base { -namespace mac { - -namespace { - -// The current count of outstanding requests for full screen mode from browser -// windows, plugins, etc. -int g_full_screen_requests[kNumFullScreenModes] = {0}; - -// Sets the appropriate application presentation option based on the current -// full screen requests. Since only one presentation option can be active at a -// given time, full screen requests are ordered by priority. If there are no -// outstanding full screen requests, reverts to normal mode. If the correct -// presentation option is already set, does nothing. -void SetUIMode() { - NSApplicationPresentationOptions current_options = - [NSApp presentationOptions]; - - // Determine which mode should be active, based on which requests are - // currently outstanding. More permissive requests take precedence. For - // example, plugins request |kFullScreenModeAutoHideAll|, while browser - // windows request |kFullScreenModeHideDock| when the fullscreen overlay is - // down. Precedence goes to plugins in this case, so AutoHideAll wins over - // HideDock. - NSApplicationPresentationOptions desired_options = - NSApplicationPresentationDefault; - if (g_full_screen_requests[kFullScreenModeAutoHideAll] > 0) { - desired_options = NSApplicationPresentationHideDock | - NSApplicationPresentationAutoHideMenuBar; - } else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) { - desired_options = NSApplicationPresentationHideDock; - } else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) { - desired_options = NSApplicationPresentationHideDock | - NSApplicationPresentationHideMenuBar; - } - - // Mac OS X bug: if the window is fullscreened (Lion-style) and - // NSApplicationPresentationDefault is requested, the result is that the menu - // bar doesn't auto-hide. rdar://13576498 http://www.openradar.me/13576498 - // - // As a workaround, in that case, explicitly set the presentation options to - // the ones that are set by the system as it fullscreens a window. - if (desired_options == NSApplicationPresentationDefault && - current_options & NSApplicationPresentationFullScreen) { - desired_options |= NSApplicationPresentationFullScreen | - NSApplicationPresentationAutoHideMenuBar | - NSApplicationPresentationAutoHideDock; - } - - if (current_options != desired_options) - [NSApp setPresentationOptions:desired_options]; -} - -// Looks into Shared File Lists corresponding to Login Items for the item -// representing the current application. If such an item is found, returns a -// retained reference to it. Caller is responsible for releasing the reference. -LSSharedFileListItemRef GetLoginItemForApp() { - ScopedCFTypeRef<LSSharedFileListRef> login_items( - LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL)); - - if (!login_items.get()) { - DLOG(ERROR) << "Couldn't get a Login Items list."; - return NULL; - } - - base::scoped_nsobject<NSArray> login_items_array( - CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL))); - - NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]]; - - for (NSUInteger i = 0; i < [login_items_array count]; ++i) { - LSSharedFileListItemRef item = - reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]); - CFURLRef item_url_ref = NULL; - - // It seems that LSSharedFileListItemResolve() can return NULL in - // item_url_ref even if the function itself returns noErr. See - // https://crbug.com/760989 - if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr && - item_url_ref) { - ScopedCFTypeRef<CFURLRef> item_url(item_url_ref); - if (CFEqual(item_url, url)) { - CFRetain(item); - return item; - } - } - } - - return NULL; -} - -bool IsHiddenLoginItem(LSSharedFileListItemRef item) { - ScopedCFTypeRef<CFBooleanRef> hidden( - reinterpret_cast<CFBooleanRef>(LSSharedFileListItemCopyProperty( - item, - reinterpret_cast<CFStringRef>(kLSSharedFileListLoginItemHidden)))); - - return hidden && hidden == kCFBooleanTrue; -} - -} // namespace - -CGColorSpaceRef GetGenericRGBColorSpace() { - // Leaked. That's OK, it's scoped to the lifetime of the application. - static CGColorSpaceRef g_color_space_generic_rgb( - CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); - DLOG_IF(ERROR, !g_color_space_generic_rgb) - << "Couldn't get the generic RGB color space"; - return g_color_space_generic_rgb; -} - -CGColorSpaceRef GetSRGBColorSpace() { - // Leaked. That's OK, it's scoped to the lifetime of the application. - static CGColorSpaceRef g_color_space_sRGB = - CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - DLOG_IF(ERROR, !g_color_space_sRGB) << "Couldn't get the sRGB color space"; - return g_color_space_sRGB; -} - -CGColorSpaceRef GetSystemColorSpace() { - // Leaked. That's OK, it's scoped to the lifetime of the application. - // Try to get the main display's color space. - static CGColorSpaceRef g_system_color_space = - CGDisplayCopyColorSpace(CGMainDisplayID()); - - if (!g_system_color_space) { - // Use a generic RGB color space. This is better than nothing. - g_system_color_space = CGColorSpaceCreateDeviceRGB(); - - if (g_system_color_space) { - DLOG(WARNING) - << "Couldn't get the main display's color space, using generic"; - } else { - DLOG(ERROR) << "Couldn't get any color space"; - } - } - - return g_system_color_space; -} - -// Add a request for full screen mode. Must be called on the main thread. -void RequestFullScreen(FullScreenMode mode) { - DCHECK_LT(mode, kNumFullScreenModes); - if (mode >= kNumFullScreenModes) - return; - - DCHECK_GE(g_full_screen_requests[mode], 0); - if (mode < 0) - return; - - g_full_screen_requests[mode] = std::max(g_full_screen_requests[mode] + 1, 1); - SetUIMode(); -} - -// Release a request for full screen mode. Must be called on the main thread. -void ReleaseFullScreen(FullScreenMode mode) { - DCHECK_LT(mode, kNumFullScreenModes); - if (mode >= kNumFullScreenModes) - return; - - DCHECK_GE(g_full_screen_requests[mode], 0); - if (mode < 0) - return; - - g_full_screen_requests[mode] = std::max(g_full_screen_requests[mode] - 1, 0); - SetUIMode(); -} - -// Switches full screen modes. Releases a request for |from_mode| and adds a -// new request for |to_mode|. Must be called on the main thread. -void SwitchFullScreenModes(FullScreenMode from_mode, FullScreenMode to_mode) { - DCHECK_LT(from_mode, kNumFullScreenModes); - DCHECK_LT(to_mode, kNumFullScreenModes); - if (from_mode >= kNumFullScreenModes || to_mode >= kNumFullScreenModes) - return; - - DCHECK_GT(g_full_screen_requests[from_mode], 0); - DCHECK_GE(g_full_screen_requests[to_mode], 0); - g_full_screen_requests[from_mode] = - std::max(g_full_screen_requests[from_mode] - 1, 0); - g_full_screen_requests[to_mode] = - std::max(g_full_screen_requests[to_mode] + 1, 1); - SetUIMode(); -} - -bool SetFileBackupExclusion(const FilePath& file_path) { - NSString* file_path_ns = - [NSString stringWithUTF8String:file_path.value().c_str()]; - NSURL* file_url = [NSURL fileURLWithPath:file_path_ns]; - - // When excludeByPath is true the application must be running with root - // privileges (admin for 10.6 and earlier) but the URL does not have to - // already exist. When excludeByPath is false the URL must already exist but - // can be used in non-root (or admin as above) mode. We use false so that - // non-root (or admin) users don't get their TimeMachine drive filled up with - // unnecessary backups. - OSStatus os_err = - CSBackupSetItemExcluded(base::mac::NSToCFCast(file_url), TRUE, FALSE); - if (os_err != noErr) { - OSSTATUS_DLOG(WARNING, os_err) - << "Failed to set backup exclusion for file '" - << file_path.value().c_str() << "'"; - } - return os_err == noErr; -} - -bool CheckLoginItemStatus(bool* is_hidden) { - ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); - if (!item.get()) - return false; - - if (is_hidden) - *is_hidden = IsHiddenLoginItem(item); - - return true; -} - -void AddToLoginItems(bool hide_on_startup) { - ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); - if (item.get() && (IsHiddenLoginItem(item) == hide_on_startup)) { - return; // Already is a login item with required hide flag. - } - - ScopedCFTypeRef<LSSharedFileListRef> login_items( - LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL)); - - if (!login_items.get()) { - DLOG(ERROR) << "Couldn't get a Login Items list."; - return; - } - - // Remove the old item, it has wrong hide flag, we'll create a new one. - if (item.get()) { - LSSharedFileListItemRemove(login_items, item); - } - - NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]]; - - BOOL hide = hide_on_startup ? YES : NO; - NSDictionary* properties = [NSDictionary - dictionaryWithObject:[NSNumber numberWithBool:hide] - forKey:(NSString*)kLSSharedFileListLoginItemHidden]; - - ScopedCFTypeRef<LSSharedFileListItemRef> new_item; - new_item.reset(LSSharedFileListInsertItemURL( - login_items, kLSSharedFileListItemLast, NULL, NULL, - reinterpret_cast<CFURLRef>(url), - reinterpret_cast<CFDictionaryRef>(properties), NULL)); - - if (!new_item.get()) { - DLOG(ERROR) << "Couldn't insert current app into Login Items list."; - } -} - -void RemoveFromLoginItems() { - ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); - if (!item.get()) - return; - - ScopedCFTypeRef<LSSharedFileListRef> login_items( - LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL)); - - if (!login_items.get()) { - DLOG(ERROR) << "Couldn't get a Login Items list."; - return; - } - - LSSharedFileListItemRemove(login_items, item); -} - -bool WasLaunchedAsLoginOrResumeItem() { - ProcessSerialNumber psn = {0, kCurrentProcess}; - ProcessInfoRec info = {}; - info.processInfoLength = sizeof(info); - -// GetProcessInformation has been deprecated since macOS 10.9, but there is no -// replacement that provides the information we need. See -// https://crbug.com/650854. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - if (GetProcessInformation(&psn, &info) == noErr) { -#pragma clang diagnostic pop - ProcessInfoRec parent_info = {}; - parent_info.processInfoLength = sizeof(parent_info); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - if (GetProcessInformation(&info.processLauncher, &parent_info) == noErr) { -#pragma clang diagnostic pop - return parent_info.processSignature == 'lgnw'; - } - } - return false; -} - -bool WasLaunchedAsLoginItemRestoreState() { - // "Reopen windows..." option was added for Lion. Prior OS versions should - // not have this behavior. - if (!WasLaunchedAsLoginOrResumeItem()) - return false; - - CFStringRef app = CFSTR("com.apple.loginwindow"); - CFStringRef save_state = CFSTR("TALLogoutSavesState"); - ScopedCFTypeRef<CFPropertyListRef> plist( - CFPreferencesCopyAppValue(save_state, app)); - // According to documentation, com.apple.loginwindow.plist does not exist on a - // fresh installation until the user changes a login window setting. The - // "reopen windows" option is checked by default, so the plist would exist had - // the user unchecked it. - // https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/CustomLogin.html - if (!plist) - return true; - - if (CFBooleanRef restore_state = base::mac::CFCast<CFBooleanRef>(plist)) - return CFBooleanGetValue(restore_state); - - return false; -} - -bool WasLaunchedAsHiddenLoginItem() { - if (!WasLaunchedAsLoginOrResumeItem()) - return false; - - ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); - if (!item.get()) { - // OS X can launch items for the resume feature. - return false; - } - return IsHiddenLoginItem(item); -} - -bool RemoveQuarantineAttribute(const FilePath& file_path) { - const char kQuarantineAttrName[] = "com.apple.quarantine"; - int status = removexattr(file_path.value().c_str(), kQuarantineAttrName, 0); - return status == 0 || errno == ENOATTR; -} - -namespace { - -// Returns the running system's Darwin major version. Don't call this, it's -// an implementation detail and its result is meant to be cached by -// MacOSXMinorVersion. -int DarwinMajorVersionInternal() { - // base::OperatingSystemVersionNumbers calls Gestalt, which is a - // higher-level operation than is needed. It might perform unnecessary - // operations. On 10.6, it was observed to be able to spawn threads (see - // http://crbug.com/53200). It might also read files or perform other - // blocking operations. Actually, nobody really knows for sure just what - // Gestalt might do, or what it might be taught to do in the future. - // - // uname, on the other hand, is implemented as a simple series of sysctl - // system calls to obtain the relevant data from the kernel. The data is - // compiled right into the kernel, so no threads or blocking or other - // funny business is necessary. - - struct utsname uname_info; - if (uname(&uname_info) != 0) { - DPLOG(ERROR) << "uname"; - return 0; - } - - if (strcmp(uname_info.sysname, "Darwin") != 0) { - DLOG(ERROR) << "unexpected uname sysname " << uname_info.sysname; - return 0; - } - - int darwin_major_version = 0; - char* dot = strchr(uname_info.release, '.'); - if (dot) { - if (!base::StringToInt( - base::StringPiece(uname_info.release, dot - uname_info.release), - &darwin_major_version)) { - dot = NULL; - } - } - - if (!dot) { - DLOG(ERROR) << "could not parse uname release " << uname_info.release; - return 0; - } - - return darwin_major_version; -} - -// Returns the running system's Mac OS X minor version. This is the |y| value -// in 10.y or 10.y.z. Don't call this, it's an implementation detail and the -// result is meant to be cached by MacOSXMinorVersion. -int MacOSXMinorVersionInternal() { - int darwin_major_version = DarwinMajorVersionInternal(); - - // The Darwin major version is always 4 greater than the Mac OS X minor - // version for Darwin versions beginning with 6, corresponding to Mac OS X - // 10.2. Since this correspondence may change in the future, warn when - // encountering a version higher than anything seen before. Older Darwin - // versions, or versions that can't be determined, result in - // immediate death. - CHECK(darwin_major_version >= 6); - int mac_os_x_minor_version = darwin_major_version - 4; - DLOG_IF(WARNING, darwin_major_version > 17) - << "Assuming Darwin " << base::IntToString(darwin_major_version) - << " is macOS 10." << base::IntToString(mac_os_x_minor_version); - - return mac_os_x_minor_version; -} - -} // namespace - -namespace internal { -int MacOSXMinorVersion() { - static int mac_os_x_minor_version = MacOSXMinorVersionInternal(); - return mac_os_x_minor_version; -} -} // namespace internal - -std::string GetModelIdentifier() { - std::string return_string; - ScopedIOObject<io_service_t> platform_expert(IOServiceGetMatchingService( - kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))); - if (platform_expert) { - ScopedCFTypeRef<CFDataRef> model_data( - static_cast<CFDataRef>(IORegistryEntryCreateCFProperty( - platform_expert, CFSTR("model"), kCFAllocatorDefault, 0))); - if (model_data) { - return_string = - reinterpret_cast<const char*>(CFDataGetBytePtr(model_data)); - } - } - return return_string; -} - -bool ParseModelIdentifier(const std::string& ident, - std::string* type, - int32_t* major, - int32_t* minor) { - size_t number_loc = ident.find_first_of("0123456789"); - if (number_loc == std::string::npos) - return false; - size_t comma_loc = ident.find(',', number_loc); - if (comma_loc == std::string::npos) - return false; - int32_t major_tmp, minor_tmp; - std::string::const_iterator begin = ident.begin(); - if (!StringToInt(StringPiece(begin + number_loc, begin + comma_loc), - &major_tmp) || - !StringToInt(StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) - return false; - *type = ident.substr(0, number_loc); - *major = major_tmp; - *minor = minor_tmp; - return true; -} - -} // namespace mac -} // namespace base
diff --git a/base/mac/mach_logging.cc b/base/mac/mach_logging.cc deleted file mode 100644 index 4237f01..0000000 --- a/base/mac/mach_logging.cc +++ /dev/null
@@ -1,82 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/mach_logging.h" - -#include <iomanip> -#include <string> - -#include "base/strings/stringprintf.h" -#include "util/build_config.h" - -#if !defined(OS_IOS) -#include <servers/bootstrap.h> -#endif // !OS_IOS - -namespace { - -std::string FormatMachErrorNumber(mach_error_t mach_err) { - // For the os/kern subsystem, give the error number in decimal as in - // <mach/kern_return.h>. Otherwise, give it in hexadecimal to make it easier - // to visualize the various bits. See <mach/error.h>. - if (mach_err >= 0 && mach_err < KERN_RETURN_MAX) { - return base::StringPrintf(" (%d)", mach_err); - } - return base::StringPrintf(" (0x%08x)", mach_err); -} - -} // namespace - -namespace logging { - -MachLogMessage::MachLogMessage(const char* file_path, - int line, - LogSeverity severity, - mach_error_t mach_err) - : LogMessage(file_path, line, severity), mach_err_(mach_err) {} - -MachLogMessage::~MachLogMessage() { - stream() << ": " << mach_error_string(mach_err_) - << FormatMachErrorNumber(mach_err_); -} - -#if !defined(OS_IOS) - -BootstrapLogMessage::BootstrapLogMessage(const char* file_path, - int line, - LogSeverity severity, - kern_return_t bootstrap_err) - : LogMessage(file_path, line, severity), bootstrap_err_(bootstrap_err) {} - -BootstrapLogMessage::~BootstrapLogMessage() { - stream() << ": " << bootstrap_strerror(bootstrap_err_); - - switch (bootstrap_err_) { - case BOOTSTRAP_SUCCESS: - case BOOTSTRAP_NOT_PRIVILEGED: - case BOOTSTRAP_NAME_IN_USE: - case BOOTSTRAP_UNKNOWN_SERVICE: - case BOOTSTRAP_SERVICE_ACTIVE: - case BOOTSTRAP_BAD_COUNT: - case BOOTSTRAP_NO_MEMORY: - case BOOTSTRAP_NO_CHILDREN: { - // Show known bootstrap errors in decimal because that's how they're - // defined in <servers/bootstrap.h>. - stream() << " (" << bootstrap_err_ << ")"; - break; - } - - default: { - // bootstrap_strerror passes unknown errors to mach_error_string, so - // format them as they would be if they were handled by - // MachErrorMessage. - stream() << FormatMachErrorNumber(bootstrap_err_); - break; - } - } -} - -#endif // !OS_IOS - -} // namespace logging
diff --git a/base/mac/mach_logging.h b/base/mac/mach_logging.h deleted file mode 100644 index a69d7fe..0000000 --- a/base/mac/mach_logging.h +++ /dev/null
@@ -1,122 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_MACH_LOGGING_H_ -#define BASE_MAC_MACH_LOGGING_H_ - -#include <mach/mach.h> - -#include "base/logging.h" -#include "base/macros.h" -#include "util/build_config.h" - -// Use the MACH_LOG family of macros along with a mach_error_t (kern_return_t) -// containing a Mach error. The error value will be decoded so that logged -// messages explain the error. -// -// Use the BOOTSTRAP_LOG family of macros specifically for errors that occur -// while interoperating with the bootstrap subsystem. These errors will first -// be looked up as bootstrap error messages. If no match is found, they will -// be treated as generic Mach errors, as in MACH_LOG. -// -// Examples: -// -// kern_return_t kr = mach_timebase_info(&info); -// if (kr != KERN_SUCCESS) { -// MACH_LOG(ERROR, kr) << "mach_timebase_info"; -// } -// -// kr = vm_deallocate(task, address, size); -// MACH_DCHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate"; - -namespace logging { - -class MachLogMessage : public logging::LogMessage { - public: - MachLogMessage(const char* file_path, - int line, - LogSeverity severity, - mach_error_t mach_err); - ~MachLogMessage(); - - private: - mach_error_t mach_err_; - - DISALLOW_COPY_AND_ASSIGN(MachLogMessage); -}; - -} // namespace logging - -#define MACH_LOG_STREAM(severity, mach_err) \ - COMPACT_GOOGLE_LOG_EX_##severity(MachLogMessage, mach_err).stream() - -#define MACH_LOG(severity, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), LOG_IS_ON(severity)) -#define MACH_LOG_IF(severity, condition, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), \ - LOG_IS_ON(severity) && (condition)) - -#define MACH_CHECK(condition, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), !(condition)) \ - << "Check failed: " #condition << ". " - -#define MACH_DLOG(severity, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), DLOG_IS_ON(severity)) -#define MACH_DLOG_IF(severity, condition, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), \ - DLOG_IS_ON(severity) && (condition)) - -#define MACH_DCHECK(condition, mach_err) \ - LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), \ - DCHECK_IS_ON() && !(condition)) \ - << "Check failed: " #condition << ". " - -#if !defined(OS_IOS) - -namespace logging { - -class BootstrapLogMessage : public logging::LogMessage { - public: - BootstrapLogMessage(const char* file_path, - int line, - LogSeverity severity, - kern_return_t bootstrap_err); - ~BootstrapLogMessage(); - - private: - kern_return_t bootstrap_err_; - - DISALLOW_COPY_AND_ASSIGN(BootstrapLogMessage); -}; - -} // namespace logging - -#define BOOTSTRAP_LOG_STREAM(severity, bootstrap_err) \ - COMPACT_GOOGLE_LOG_EX_##severity(BootstrapLogMessage, bootstrap_err).stream() -#define BOOTSTRAP_LOG(severity, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \ - LOG_IS_ON(severity)) -#define BOOTSTRAP_LOG_IF(severity, condition, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \ - LOG_IS_ON(severity) && (condition)) - -#define BOOTSTRAP_CHECK(condition, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), !(condition)) \ - << "Check failed: " #condition << ". " - -#define BOOTSTRAP_DLOG(severity, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \ - DLOG_IS_ON(severity)) -#define BOOTSTRAP_DLOG_IF(severity, condition, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \ - DLOG_IS_ON(severity) && (condition)) - -#define BOOTSTRAP_DCHECK(condition, bootstrap_err) \ - LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), \ - DCHECK_IS_ON() && !(condition)) \ - << "Check failed: " #condition << ". " - -#endif // !OS_IOS - -#endif // BASE_MAC_MACH_LOGGING_H_
diff --git a/base/mac/scoped_block.h b/base/mac/scoped_block.h deleted file mode 100644 index 10ab4b4..0000000 --- a/base/mac/scoped_block.h +++ /dev/null
@@ -1,72 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_SCOPED_BLOCK_H_ -#define BASE_MAC_SCOPED_BLOCK_H_ - -#include <Block.h> - -#include "base/mac/scoped_typeref.h" - -#if defined(__has_feature) && __has_feature(objc_arc) -#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) (__bridge TYPE)(VALUE) -#else -#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) VALUE -#endif - -namespace base { -namespace mac { - -namespace internal { - -template <typename B> -struct ScopedBlockTraits { - static B InvalidValue() { return nullptr; } - static B Retain(B block) { - return BASE_MAC_BRIDGE_CAST( - B, Block_copy(BASE_MAC_BRIDGE_CAST(const void*, block))); - } - static void Release(B block) { - Block_release(BASE_MAC_BRIDGE_CAST(const void*, block)); - } -}; - -} // namespace internal - -// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and -// Block_release() instead of CFRetain() and CFRelease(). -template <typename B> -class ScopedBlock : public ScopedTypeRef<B, internal::ScopedBlockTraits<B>> { - public: - using Traits = internal::ScopedBlockTraits<B>; - -#if !defined(__has_feature) || !__has_feature(objc_arc) - explicit ScopedBlock( - B block = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) - : ScopedTypeRef<B, Traits>(block, policy) {} -#else - explicit ScopedBlock(B block = Traits::InvalidValue()) - : ScopedTypeRef<B, Traits>(block, base::scoped_policy::RETAIN) {} -#endif - -#if !defined(__has_feature) || !__has_feature(objc_arc) - void reset(B block = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = - base::scoped_policy::ASSUME) { - ScopedTypeRef<B, Traits>::reset(block, policy); - } -#else - void reset(B block = Traits::InvalidValue()) { - ScopedTypeRef<B, Traits>::reset(block, base::scoped_policy::RETAIN); - } -#endif -}; - -} // namespace mac -} // namespace base - -#undef BASE_MAC_BRIDGE_CAST - -#endif // BASE_MAC_SCOPED_BLOCK_H_
diff --git a/base/mac/scoped_dispatch_object.h b/base/mac/scoped_dispatch_object.h deleted file mode 100644 index 43d057b..0000000 --- a/base/mac/scoped_dispatch_object.h +++ /dev/null
@@ -1,34 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_SCOPED_DISPATCH_OBJECT_H_ -#define BASE_MAC_SCOPED_DISPATCH_OBJECT_H_ - -#include <dispatch/dispatch.h> - -#include "base/mac/scoped_typeref.h" - -namespace base { - -namespace internal { - -template <typename T> -struct ScopedDispatchObjectTraits { - static constexpr T InvalidValue() { return nullptr; } - static T Retain(T object) { - dispatch_retain(object); - return object; - } - static void Release(T object) { dispatch_release(object); } -}; - -} // namespace internal - -template <typename T> -using ScopedDispatchObject = - ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>; - -} // namespace base - -#endif // BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
diff --git a/base/mac/scoped_ioobject.h b/base/mac/scoped_ioobject.h deleted file mode 100644 index d656175..0000000 --- a/base/mac/scoped_ioobject.h +++ /dev/null
@@ -1,36 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_SCOPED_IOOBJECT_H_ -#define BASE_MAC_SCOPED_IOOBJECT_H_ - -#include <IOKit/IOKitLib.h> - -#include "base/mac/scoped_typeref.h" - -namespace base { -namespace mac { - -namespace internal { - -template <typename IOT> -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); } -}; - -} // namespace internal - -// Just like ScopedCFTypeRef but for io_object_t and subclasses. -template <typename IOT> -using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>; - -} // namespace mac -} // namespace base - -#endif // BASE_MAC_SCOPED_IOOBJECT_H_
diff --git a/base/mac/scoped_mach_port.cc b/base/mac/scoped_mach_port.cc deleted file mode 100644 index 13307f2..0000000 --- a/base/mac/scoped_mach_port.cc +++ /dev/null
@@ -1,38 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/scoped_mach_port.h" - -#include "base/mac/mach_logging.h" - -namespace base { -namespace mac { -namespace internal { - -// static -void SendRightTraits::Free(mach_port_t port) { - kern_return_t kr = mach_port_deallocate(mach_task_self(), port); - MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) - << "ScopedMachSendRight mach_port_deallocate"; -} - -// static -void ReceiveRightTraits::Free(mach_port_t port) { - kern_return_t kr = - mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1); - MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) - << "ScopedMachReceiveRight mach_port_mod_refs"; -} - -// static -void PortSetTraits::Free(mach_port_t port) { - kern_return_t kr = - mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_PORT_SET, -1); - MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) - << "ScopedMachPortSet mach_port_mod_refs"; -} - -} // namespace internal -} // namespace mac -} // namespace base
diff --git a/base/mac/scoped_mach_port.h b/base/mac/scoped_mach_port.h deleted file mode 100644 index 64d6765..0000000 --- a/base/mac/scoped_mach_port.h +++ /dev/null
@@ -1,60 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_SCOPED_MACH_PORT_H_ -#define BASE_MAC_SCOPED_MACH_PORT_H_ - -#include <mach/mach.h> - -#include "base/scoped_generic.h" - -namespace base { -namespace mac { - -namespace internal { - -struct SendRightTraits { - static mach_port_t InvalidValue() { return MACH_PORT_NULL; } - - static void Free(mach_port_t port); -}; - -struct ReceiveRightTraits { - static mach_port_t InvalidValue() { return MACH_PORT_NULL; } - - static void Free(mach_port_t port); -}; - -struct PortSetTraits { - static mach_port_t InvalidValue() { return MACH_PORT_NULL; } - - static void Free(mach_port_t port); -}; - -} // namespace internal - -// A scoper for handling a Mach port that names a send right. Send rights are -// reference counted, and this takes ownership of the right on construction -// and then removes a reference to the right on destruction. If the reference -// is the last one on the right, the right is deallocated. -using ScopedMachSendRight = - ScopedGeneric<mach_port_t, internal::SendRightTraits>; - -// A scoper for handling a Mach port's receive right. There is only one -// receive right per port. This takes ownership of the receive right on -// construction and then destroys the right on destruction, turning all -// outstanding send rights into dead names. -using ScopedMachReceiveRight = - ScopedGeneric<mach_port_t, internal::ReceiveRightTraits>; - -// A scoper for handling a Mach port set. A port set can have only one -// reference. This takes ownership of that single reference on construction and -// destroys the port set on destruction. Destroying a port set does not destroy -// the receive rights that are members of the port set. -using ScopedMachPortSet = ScopedGeneric<mach_port_t, internal::PortSetTraits>; - -} // namespace mac -} // namespace base - -#endif // BASE_MAC_SCOPED_MACH_PORT_H_
diff --git a/base/mac/scoped_nsautorelease_pool.h b/base/mac/scoped_nsautorelease_pool.h deleted file mode 100644 index fd4ae66..0000000 --- a/base/mac/scoped_nsautorelease_pool.h +++ /dev/null
@@ -1,45 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ -#define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ - -#include "base/macros.h" - -#if defined(__OBJC__) -@class NSAutoreleasePool; -#else // __OBJC__ -class NSAutoreleasePool; -#endif // __OBJC__ - -namespace base { -namespace mac { - -// ScopedNSAutoreleasePool allocates an NSAutoreleasePool when instantiated and -// sends it a -drain message when destroyed. This allows an autorelease pool to -// be maintained in ordinary C++ code without bringing in any direct Objective-C -// dependency. - -class ScopedNSAutoreleasePool { - public: - ScopedNSAutoreleasePool(); - ~ScopedNSAutoreleasePool(); - - // Clear out the pool in case its position on the stack causes it to be - // alive for long periods of time (such as the entire length of the app). - // Only use then when you're certain the items currently in the pool are - // no longer needed. - void Recycle(); - - private: - NSAutoreleasePool* autorelease_pool_; - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); -}; - -} // namespace mac -} // namespace base - -#endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
diff --git a/base/mac/scoped_nsautorelease_pool.mm b/base/mac/scoped_nsautorelease_pool.mm deleted file mode 100644 index e542ca8..0000000 --- a/base/mac/scoped_nsautorelease_pool.mm +++ /dev/null
@@ -1,32 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/scoped_nsautorelease_pool.h" - -#import <Foundation/Foundation.h> - -#include "base/logging.h" - -namespace base { -namespace mac { - -ScopedNSAutoreleasePool::ScopedNSAutoreleasePool() - : autorelease_pool_([[NSAutoreleasePool alloc] init]) { - DCHECK(autorelease_pool_); -} - -ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() { - [autorelease_pool_ drain]; -} - -// Cycle the internal pool, allowing everything there to get cleaned up and -// start anew. -void ScopedNSAutoreleasePool::Recycle() { - [autorelease_pool_ drain]; - autorelease_pool_ = [[NSAutoreleasePool alloc] init]; - DCHECK(autorelease_pool_); -} - -} // namespace mac -} // namespace base
diff --git a/base/mac/scoped_nsobject.h b/base/mac/scoped_nsobject.h deleted file mode 100644 index a5da218..0000000 --- a/base/mac/scoped_nsobject.h +++ /dev/null
@@ -1,239 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef 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. -// (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. -#import <Foundation/NSObject.h> - -#include "base/compiler_specific.h" -#include "base/mac/scoped_typeref.h" - -#if !defined(__has_feature) || !__has_feature(objc_arc) -@class NSAutoreleasePool; -#endif - -namespace base { - -// scoped_nsobject<> is patterned after std::unique_ptr<>, but maintains -// ownership of an NSObject subclass object. Style deviations here are solely -// for compatibility with std::unique_ptr<>'s interface, with which everyone is -// already familiar. -// -// scoped_nsobject<> takes ownership of an object (in the constructor or in -// reset()) by taking over the caller's existing ownership claim. The caller -// must own the object it gives to scoped_nsobject<>, and relinquishes an -// ownership claim to that object. scoped_nsobject<> does not call -retain, -// callers have to call this manually if appropriate. -// -// scoped_nsprotocol<> has the same behavior as scoped_nsobject, but can be used -// with protocols. -// -// scoped_nsobject<> is not to be used for NSAutoreleasePools. For -// NSAutoreleasePools use ScopedNSAutoreleasePool from -// scoped_nsautorelease_pool.h instead. -// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile -// time with a template specialization (see below). -// -// If Automatic Reference Counting (aka ARC) is enabled then the ownership -// policy is not controllable by the user as ARC make it really difficult to -// transfer ownership (the reference passed to scoped_nsobject constructor is -// sunk by ARC and __attribute((ns_consumed)) appears to not work correctly -// with Objective-C++ see https://llvm.org/bugs/show_bug.cgi?id=27887). Due to -// that, the policy is always to |RETAIN| when using ARC. - -namespace internal { - -id ScopedNSProtocolTraitsRetain(__unsafe_unretained id obj) - __attribute((ns_returns_not_retained)); -id ScopedNSProtocolTraitsAutoRelease(__unsafe_unretained id obj) - __attribute((ns_returns_not_retained)); -void ScopedNSProtocolTraitsRelease(__unsafe_unretained id obj); - -// Traits for ScopedTypeRef<>. As this class may be compiled from file with -// Automatic Reference Counting enable or not all methods have annotation to -// enforce the same code generation in both case (in particular, the Retain -// method uses ns_returns_not_retained to prevent ARC to insert a -release -// call on the returned value and thus defeating the -retain). -template <typename NST> -struct ScopedNSProtocolTraits { - static NST InvalidValue() __attribute((ns_returns_not_retained)) { - return nil; - } - static NST Retain(__unsafe_unretained NST nst) - __attribute((ns_returns_not_retained)) { - return ScopedNSProtocolTraitsRetain(nst); - } - static void Release(__unsafe_unretained NST nst) { - ScopedNSProtocolTraitsRelease(nst); - } -}; - -} // namespace internal - -template <typename NST> -class scoped_nsprotocol - : public ScopedTypeRef<NST, internal::ScopedNSProtocolTraits<NST>> { - public: - using Traits = internal::ScopedNSProtocolTraits<NST>; - -#if !defined(__has_feature) || !__has_feature(objc_arc) - explicit constexpr scoped_nsprotocol( - NST object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) - : ScopedTypeRef<NST, Traits>(object, policy) {} -#else - explicit constexpr scoped_nsprotocol(NST object = Traits::InvalidValue()) - : ScopedTypeRef<NST, Traits>(object, base::scoped_policy::RETAIN) {} -#endif - - scoped_nsprotocol(const scoped_nsprotocol<NST>& that) - : ScopedTypeRef<NST, Traits>(that) {} - - template <typename NSR> - explicit scoped_nsprotocol(const scoped_nsprotocol<NSR>& that_as_subclass) - : ScopedTypeRef<NST, Traits>(that_as_subclass) {} - - scoped_nsprotocol(scoped_nsprotocol<NST>&& that) - : ScopedTypeRef<NST, Traits>(std::move(that)) {} - - scoped_nsprotocol& operator=(const scoped_nsprotocol<NST>& that) { - ScopedTypeRef<NST, Traits>::operator=(that); - return *this; - } - -#if !defined(__has_feature) || !__has_feature(objc_arc) - void reset(NST object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = - base::scoped_policy::ASSUME) { - ScopedTypeRef<NST, Traits>::reset(object, policy); - } -#else - void reset(NST object = Traits::InvalidValue()) { - ScopedTypeRef<NST, Traits>::reset(object, base::scoped_policy::RETAIN); - } -#endif - - // Shift reference to the autorelease pool to be released later. - NST autorelease() __attribute((ns_returns_not_retained)) { - return internal::ScopedNSProtocolTraitsAutoRelease(this->release()); - } -}; - -// Free functions -template <class C> -void swap(scoped_nsprotocol<C>& p1, scoped_nsprotocol<C>& p2) { - p1.swap(p2); -} - -template <class C> -bool operator==(C p1, const scoped_nsprotocol<C>& p2) { - return p1 == p2.get(); -} - -template <class C> -bool operator!=(C p1, const scoped_nsprotocol<C>& p2) { - return p1 != p2.get(); -} - -template <typename NST> -class scoped_nsobject : public scoped_nsprotocol<NST*> { - public: - using Traits = typename scoped_nsprotocol<NST*>::Traits; - -#if !defined(__has_feature) || !__has_feature(objc_arc) - explicit constexpr scoped_nsobject( - NST* object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) - : scoped_nsprotocol<NST*>(object, policy) {} -#else - explicit constexpr scoped_nsobject(NST* object = Traits::InvalidValue()) - : scoped_nsprotocol<NST*>(object) {} -#endif - - scoped_nsobject(const scoped_nsobject<NST>& that) - : scoped_nsprotocol<NST*>(that) {} - - template <typename NSR> - explicit scoped_nsobject(const scoped_nsobject<NSR>& that_as_subclass) - : scoped_nsprotocol<NST*>(that_as_subclass) {} - - scoped_nsobject(scoped_nsobject<NST>&& that) - : scoped_nsprotocol<NST*>(std::move(that)) {} - - scoped_nsobject& operator=(const scoped_nsobject<NST>& that) { - scoped_nsprotocol<NST*>::operator=(that); - return *this; - } - -#if !defined(__has_feature) || !__has_feature(objc_arc) - void reset(NST* object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = - base::scoped_policy::ASSUME) { - scoped_nsprotocol<NST*>::reset(object, policy); - } -#else - void reset(NST* object = Traits::InvalidValue()) { - scoped_nsprotocol<NST*>::reset(object); - } -#endif - -#if !defined(__has_feature) || !__has_feature(objc_arc) - static_assert(std::is_same<NST, NSAutoreleasePool>::value == false, - "Use ScopedNSAutoreleasePool instead"); -#endif -}; - -// Specialization to make scoped_nsobject<id> work. -template <> -class scoped_nsobject<id> : public scoped_nsprotocol<id> { - public: - using Traits = typename scoped_nsprotocol<id>::Traits; - -#if !defined(__has_feature) || !__has_feature(objc_arc) - explicit constexpr scoped_nsobject( - id object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) - : scoped_nsprotocol<id>(object, policy) {} -#else - explicit constexpr scoped_nsobject(id object = Traits::InvalidValue()) - : scoped_nsprotocol<id>(object) {} -#endif - - scoped_nsobject(const scoped_nsobject<id>& that) - : scoped_nsprotocol<id>(that) {} - - template <typename NSR> - explicit scoped_nsobject(const scoped_nsobject<NSR>& that_as_subclass) - : scoped_nsprotocol<id>(that_as_subclass) {} - - scoped_nsobject(scoped_nsobject<id>&& that) - : scoped_nsprotocol<id>(std::move(that)) {} - - scoped_nsobject& operator=(const scoped_nsobject<id>& that) { - scoped_nsprotocol<id>::operator=(that); - return *this; - } - -#if !defined(__has_feature) || !__has_feature(objc_arc) - void reset(id object = Traits::InvalidValue(), - base::scoped_policy::OwnershipPolicy policy = - base::scoped_policy::ASSUME) { - scoped_nsprotocol<id>::reset(object, policy); - } -#else - void reset(id object = Traits::InvalidValue()) { - scoped_nsprotocol<id>::reset(object); - } -#endif -}; - -} // namespace base - -#endif // BASE_MAC_SCOPED_NSOBJECT_H_
diff --git a/base/mac/scoped_nsobject.mm b/base/mac/scoped_nsobject.mm deleted file mode 100644 index 65b4031..0000000 --- a/base/mac/scoped_nsobject.mm +++ /dev/null
@@ -1,23 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "base/mac/scoped_nsobject.h" - -namespace base { -namespace internal { - -id ScopedNSProtocolTraitsRetain(id obj) { - return [obj retain]; -} - -id ScopedNSProtocolTraitsAutoRelease(id obj) { - return [obj autorelease]; -} - -void ScopedNSProtocolTraitsRelease(id obj) { - return [obj release]; -} - -} // namespace internal -} // namespace base
diff --git a/base/mac/sdk_forward_declarations.h b/base/mac/sdk_forward_declarations.h deleted file mode 100644 index 5bcb3b3..0000000 --- a/base/mac/sdk_forward_declarations.h +++ /dev/null
@@ -1,333 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file contains forward declarations for items in later SDKs than the -// default one with which Chromium is built (currently 10.10). -// If you call any function from this header, be sure to check at runtime for -// respondsToSelector: before calling these functions (else your code will crash -// on older OS X versions that chrome still supports). - -#ifndef BASE_MAC_SDK_FORWARD_DECLARATIONS_H_ -#define BASE_MAC_SDK_FORWARD_DECLARATIONS_H_ - -#import <AppKit/AppKit.h> -#import <CoreBluetooth/CoreBluetooth.h> -#import <CoreWLAN/CoreWLAN.h> -#import <IOBluetooth/IOBluetooth.h> -#import <ImageCaptureCore/ImageCaptureCore.h> -#import <QuartzCore/QuartzCore.h> -#include <stdint.h> - -#include "base/mac/availability.h" - -// ---------------------------------------------------------------------------- -// Define typedefs, enums, and protocols not available in the version of the -// OSX SDK being compiled against. -// ---------------------------------------------------------------------------- - -#if !defined(MAC_OS_X_VERSION_10_11) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11 - -enum { - NSPressureBehaviorUnknown = -1, - NSPressureBehaviorPrimaryDefault = 0, - NSPressureBehaviorPrimaryClick = 1, - NSPressureBehaviorPrimaryGeneric = 2, - NSPressureBehaviorPrimaryAccelerator = 3, - NSPressureBehaviorPrimaryDeepClick = 5, - NSPressureBehaviorPrimaryDeepDrag = 6 -}; -typedef NSInteger NSPressureBehavior; - -@interface NSPressureConfiguration : NSObject -- (instancetype)initWithPressureBehavior:(NSPressureBehavior)pressureBehavior; -@end - -enum { - NSSpringLoadingHighlightNone = 0, - NSSpringLoadingHighlightStandard, - NSSpringLoadingHighlightEmphasized -}; -typedef NSUInteger NSSpringLoadingHighlight; - -#endif // MAC_OS_X_VERSION_10_11 - -#if !defined(MAC_OS_X_VERSION_10_12) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 - -// The protocol was formalized by the 10.12 SDK, but it was informally used -// before. -@protocol CAAnimationDelegate -- (void)animationDidStart:(CAAnimation*)animation; -- (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished; -@end - -@protocol CALayerDelegate -@end - -#endif // MAC_OS_X_VERSION_10_12 - -// ---------------------------------------------------------------------------- -// Define NSStrings only available in newer versions of the OSX SDK to force -// them to be statically linked. -// ---------------------------------------------------------------------------- - -extern "C" { -#if !defined(MAC_OS_X_VERSION_10_10) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 -extern NSString* const CIDetectorTypeQRCode; -extern NSString* const NSUserActivityTypeBrowsingWeb; -extern NSString* const NSAppearanceNameVibrantDark; -extern NSString* const NSAppearanceNameVibrantLight; -#endif // MAC_OS_X_VERSION_10_10 -} // extern "C" - -// ---------------------------------------------------------------------------- -// If compiling against an older version of the OSX SDK, declare classes and -// functions that are available in newer versions of the OSX SDK. If compiling -// against a newer version of the OSX SDK, redeclare those same classes and -// functions to suppress -Wpartial-availability warnings. -// ---------------------------------------------------------------------------- - -// Once Chrome no longer supports OSX 10.9, everything within this preprocessor -// block can be removed. -#if !defined(MAC_OS_X_VERSION_10_10) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 - -@interface NSUserActivity (YosemiteSDK) -@property(readonly, copy) NSString* activityType; -@property(copy) NSDictionary* userInfo; -@property(copy) NSURL* webpageURL; -@property(copy) NSString* title; -- (instancetype)initWithActivityType:(NSString*)activityType; -- (void)becomeCurrent; -- (void)invalidate; -@end - -@interface CBUUID (YosemiteSDK) -- (NSString*)UUIDString; -@end - -@interface NSViewController (YosemiteSDK) -- (void)viewDidLoad; -@end - -@interface NSWindow (YosemiteSDK) -- (void)setTitlebarAppearsTransparent:(BOOL)flag; -@end - -@interface NSProcessInfo (YosemiteSDK) -@property(readonly) NSOperatingSystemVersion operatingSystemVersion; -@end - -@interface NSLayoutConstraint (YosemiteSDK) -@property(getter=isActive) BOOL active; -+ (void)activateConstraints:(NSArray*)constraints; -@end - -@interface NSVisualEffectView (YosemiteSDK) -- (void)setState:(NSVisualEffectState)state; -@end - -@class NSVisualEffectView; - -@interface CIQRCodeFeature (YosemiteSDK) -@property(readonly) CGRect bounds; -@property(readonly) CGPoint topLeft; -@property(readonly) CGPoint topRight; -@property(readonly) CGPoint bottomLeft; -@property(readonly) CGPoint bottomRight; -@property(readonly, copy) NSString* messageString; -@end - -@class CIQRCodeFeature; - -@interface NSView (YosemiteSDK) -- (BOOL)isAccessibilitySelectorAllowed:(SEL)selector; -@property(copy) NSString* accessibilityLabel; -@end - -#endif // MAC_OS_X_VERSION_10_10 - -// Once Chrome no longer supports OSX 10.10.2, everything within this -// preprocessor block can be removed. -#if !defined(MAC_OS_X_VERSION_10_10_3) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10_3 - -@interface NSEvent (Yosemite_3_SDK) -@property(readonly) NSInteger stage; -@end - -#endif // MAC_OS_X_VERSION_10_10 - -// ---------------------------------------------------------------------------- -// Define NSStrings only available in newer versions of the OSX SDK to force -// them to be statically linked. -// ---------------------------------------------------------------------------- - -extern "C" { -#if !defined(MAC_OS_X_VERSION_10_11) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 -extern NSString* const CIDetectorTypeText; -#endif // MAC_OS_X_VERSION_10_11 -} // extern "C" - -// Once Chrome no longer supports OSX 10.10, everything within this -// preprocessor block can be removed. -#if !defined(MAC_OS_X_VERSION_10_11) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 - -@class NSLayoutDimension; -@class NSLayoutXAxisAnchor; -@class NSLayoutYAxisAnchor; - -@interface NSObject (ElCapitanSDK) -- (NSLayoutConstraint*)constraintEqualToConstant:(CGFloat)c; -- (NSLayoutConstraint*)constraintGreaterThanOrEqualToConstant:(CGFloat)c; -@end - -@interface NSView (ElCapitanSDK) -- (void)setPressureConfiguration:(NSPressureConfiguration*)aConfiguration - API_AVAILABLE(macos(10.11)); -@property(readonly, strong) - NSLayoutXAxisAnchor* leftAnchor API_AVAILABLE(macos(10.11)); -@property(readonly, strong) - NSLayoutXAxisAnchor* rightAnchor API_AVAILABLE(macos(10.11)); -@property(readonly, strong) - NSLayoutYAxisAnchor* bottomAnchor API_AVAILABLE(macos(10.11)); -@property(readonly, strong) - NSLayoutDimension* widthAnchor API_AVAILABLE(macos(10.11)); -@end - -@interface NSWindow (ElCapitanSDK) -- (void)performWindowDragWithEvent:(NSEvent*)event; -@end - -@interface CIRectangleFeature (ElCapitanSDK) -@property(readonly) CGRect bounds; -@end - -@class CIRectangleFeature; - -#endif // MAC_OS_X_VERSION_10_11 - -// Once Chrome no longer supports OSX 10.11, everything within this -// preprocessor block can be removed. -#if !defined(MAC_OS_X_VERSION_10_12) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 - -@interface NSWindow (SierraSDK) -@property(class) BOOL allowsAutomaticWindowTabbing; -@end - -#endif // MAC_OS_X_VERSION_10_12 - -// Once Chrome no longer supports OSX 10.12.0, everything within this -// preprocessor block can be removed. -#if !defined(MAC_OS_X_VERSION_10_12_1) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12_1 - -@interface NSButton (SierraPointOneSDK) -@property(copy) NSColor* bezelColor; -@property BOOL imageHugsTitle; -+ (instancetype)buttonWithTitle:(NSString*)title - target:(id)target - action:(SEL)action; -+ (instancetype)buttonWithImage:(NSImage*)image - target:(id)target - action:(SEL)action; -+ (instancetype)buttonWithTitle:(NSString*)title - image:(NSImage*)image - target:(id)target - action:(SEL)action; -@end - -@interface NSSegmentedControl (SierraPointOneSDK) -+ (instancetype)segmentedControlWithImages:(NSArray*)images - trackingMode:(NSSegmentSwitchTracking)trackingMode - target:(id)target - action:(SEL)action; -@end - -@interface NSTextField (SierraPointOneSDK) -+ (instancetype)labelWithAttributedString: - (NSAttributedString*)attributedStringValue; -@end - -#endif // MAC_OS_X_VERSION_10_12_1 - -// Once Chrome no longer supports OSX 10.12, everything within this -// preprocessor block can be removed. -#if !defined(MAC_OS_X_VERSION_10_13) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_13 - -// VNRequest forward declarations. -@class VNRequest; -typedef void (^VNRequestCompletionHandler)(VNRequest* request, NSError* error); - -@interface VNRequest : NSObject <NSCopying> -- (instancetype)initWithCompletionHandler: - (VNRequestCompletionHandler)completionHandler NS_DESIGNATED_INITIALIZER; -@property(readonly, nonatomic, copy) NSArray* results; -@end - -// VNDetectFaceLandmarksRequest forward declarations. -@interface VNImageBasedRequest : VNRequest -@end - -@protocol VNFaceObservationAccepting <NSObject> -@end - -@interface VNDetectFaceLandmarksRequest - : VNImageBasedRequest <VNFaceObservationAccepting> -@end - -// VNImageRequestHandler forward declarations. -typedef NSString* VNImageOption NS_STRING_ENUM; - -@interface VNImageRequestHandler : NSObject -- (instancetype)initWithCIImage:(CIImage*)image - options:(NSDictionary<VNImageOption, id>*)options; -- (BOOL)performRequests:(NSArray<VNRequest*>*)requests error:(NSError**)error; -@end - -// VNFaceLandmarks2D forward declarations. -@interface VNFaceLandmarkRegion : NSObject -@property(readonly) NSUInteger pointCount; -@end - -@interface VNFaceLandmarkRegion2D : VNFaceLandmarkRegion -@property(readonly, assign) - const CGPoint* normalizedPoints NS_RETURNS_INNER_POINTER; -@end - -@interface VNFaceLandmarks2D : NSObject -@property(readonly) VNFaceLandmarkRegion2D* leftEye; -@property(readonly) VNFaceLandmarkRegion2D* rightEye; -@property(readonly) VNFaceLandmarkRegion2D* outerLips; -@property(readonly) VNFaceLandmarkRegion2D* nose; -@end - -// VNFaceObservation forward declarations. -@interface VNObservation : NSObject <NSCopying, NSSecureCoding> -@end - -@interface VNDetectedObjectObservation : VNObservation -@property(readonly, nonatomic, assign) CGRect boundingBox; -@end - -@interface VNFaceObservation : VNDetectedObjectObservation -@property(readonly, nonatomic, strong) VNFaceLandmarks2D* landmarks; -@end - -#endif // MAC_OS_X_VERSION_10_13 -// ---------------------------------------------------------------------------- -// The symbol for kCWSSIDDidChangeNotification is available in the -// CoreWLAN.framework for OSX versions 10.6 through 10.10. The symbol is not -// declared in the OSX 10.9+ SDK, so when compiling against an OSX 10.9+ SDK, -// declare the symbol. -// ---------------------------------------------------------------------------- -extern "C" NSString* const kCWSSIDDidChangeNotification; - -#endif // BASE_MAC_SDK_FORWARD_DECLARATIONS_H_
diff --git a/base/mac/sdk_forward_declarations.mm b/base/mac/sdk_forward_declarations.mm deleted file mode 100644 index c624dae..0000000 --- a/base/mac/sdk_forward_declarations.mm +++ /dev/null
@@ -1,20 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/mac/sdk_forward_declarations.h" - -#if !defined(MAC_OS_X_VERSION_10_10) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 -NSString* const CIDetectorTypeQRCode = @"CIDetectorTypeQRCode"; - -NSString* const NSUserActivityTypeBrowsingWeb = - @"NSUserActivityTypeBrowsingWeb"; - -NSString* const NSAppearanceNameVibrantDark = @"NSAppearanceNameVibrantDark"; -#endif // MAC_OS_X_VERSION_10_10 - -#if !defined(MAC_OS_X_VERSION_10_11) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 -NSString* const CIDetectorTypeText = @"CIDetectorTypeText"; -#endif // MAC_OS_X_VERSION_10_11
diff --git a/base/no_destructor.h b/base/no_destructor.h deleted file mode 100644 index aabc6e6..0000000 --- a/base/no_destructor.h +++ /dev/null
@@ -1,99 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_NO_DESTRUCTOR_H_ -#define BASE_NO_DESTRUCTOR_H_ - -#include <new> -#include <utility> - -namespace base { - -// A wrapper that makes it easy to create an object of type T with static -// storage duration that: -// - is only constructed on first access -// - never invokes the destructor -// in order to satisfy the styleguide ban on global constructors and -// destructors. -// -// Runtime constant example: -// const std::string& GetLineSeparator() { -// // Forwards to std::string(size_t, char, const Allocator&) constructor. -// static const base::NoDestructor<std::string> s(5, '-'); -// return *s; -// } -// -// More complex initialization with a lambda: -// const std::string& GetSessionNonce() { -// static const base::NoDestructor<std::string> nonce([] { -// std::string s(16); -// crypto::RandString(s.data(), s.size()); -// return s; -// }()); -// return *nonce; -// } -// -// NoDestructor<T> stores the object inline, so it also avoids a pointer -// indirection and a malloc. Also note that since C++11 static local variable -// initialization is thread-safe and so is this pattern. Code should prefer to -// use NoDestructor<T> over: -// - The CR_DEFINE_STATIC_LOCAL() helper macro. -// - A function scoped static T* or T& that is dynamically initialized. -// - A global base::LazyInstance<T>. -// -// Note that since the destructor is never run, this *will* leak memory if used -// as a stack or member variable. Furthermore, a NoDestructor<T> should never -// have global scope as that may require a static initializer. -template <typename T> -class NoDestructor { - public: - // Not constexpr; just write static constexpr T x = ...; if the value should - // be a constexpr. - template <typename... Args> - explicit NoDestructor(Args&&... args) { - new (storage_) T(std::forward<Args>(args)...); - } - - // Allows copy and move construction of the contained type, to allow - // construction from an initializer list, e.g. for std::vector. - explicit NoDestructor(const T& x) { new (storage_) T(x); } - explicit NoDestructor(T&& x) { new (storage_) T(std::move(x)); } - - NoDestructor(const NoDestructor&) = delete; - NoDestructor& operator=(const NoDestructor&) = delete; - - ~NoDestructor() = default; - - const T& operator*() const { return *get(); } - T& operator*() { return *get(); } - - const T* operator->() const { return get(); } - T* operator->() { return get(); } - - const T* get() const { return reinterpret_cast<const T*>(storage_); } - T* get() { return reinterpret_cast<T*>(storage_); } - - private: - alignas(T) char storage_[sizeof(T)]; - -#if defined(LEAK_SANITIZER) - // TODO(https://crbug.com/812277): This is a hack to work around the fact - // that LSan doesn't seem to treat NoDestructor as a root for reachability - // analysis. This means that code like this: - // static base::NoDestructor<std::vector<int>> v({1, 2, 3}); - // is considered a leak. Using the standard leak sanitizer annotations to - // suppress leaks doesn't work: std::vector is implicitly constructed before - // calling the base::NoDestructor constructor. - // - // Unfortunately, I haven't been able to demonstrate this issue in simpler - // reproductions: until that's resolved, hold an explicit pointer to the - // placement-new'd object in leak sanitizer mode to help LSan realize that - // objects allocated by the contained type are still reachable. - T* storage_ptr_ = reinterpret_cast<T*>(storage_); -#endif // defined(LEAK_SANITIZER) -}; - -} // namespace base - -#endif // BASE_NO_DESTRUCTOR_H_
diff --git a/base/numerics/safe_conversions_arm_impl.h b/base/numerics/safe_conversions_arm_impl.h deleted file mode 100644 index da5813f..0000000 --- a/base/numerics/safe_conversions_arm_impl.h +++ /dev/null
@@ -1,51 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_ -#define BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_ - -#include <cassert> -#include <limits> -#include <type_traits> - -#include "base/numerics/safe_conversions_impl.h" - -namespace base { -namespace internal { - -// Fast saturation to a destination type. -template <typename Dst, typename Src> -struct SaturateFastAsmOp { - static const bool is_supported = - std::is_signed<Src>::value && std::is_integral<Dst>::value && - std::is_integral<Src>::value && - IntegerBitsPlusSign<Src>::value <= IntegerBitsPlusSign<int32_t>::value && - IntegerBitsPlusSign<Dst>::value <= IntegerBitsPlusSign<int32_t>::value && - !IsTypeInRangeForNumericType<Dst, Src>::value; - - __attribute__((always_inline)) static Dst Do(Src value) { - int32_t src = value; - typename std::conditional<std::is_signed<Dst>::value, int32_t, - uint32_t>::type result; - if (std::is_signed<Dst>::value) { - asm("ssat %[dst], %[shift], %[src]" - : [dst] "=r"(result) - : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value <= 32 - ? IntegerBitsPlusSign<Dst>::value - : 32)); - } else { - asm("usat %[dst], %[shift], %[src]" - : [dst] "=r"(result) - : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value < 32 - ? IntegerBitsPlusSign<Dst>::value - : 31)); - } - return static_cast<Dst>(result); - } -}; - -} // namespace internal -} // namespace base - -#endif // BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
diff --git a/base/numerics/safe_math_arm_impl.h b/base/numerics/safe_math_arm_impl.h deleted file mode 100644 index a7cda1b..0000000 --- a/base/numerics/safe_math_arm_impl.h +++ /dev/null
@@ -1,122 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_ -#define BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_ - -#include <cassert> -#include <limits> -#include <type_traits> - -#include "base/numerics/safe_conversions.h" - -namespace base { -namespace internal { - -template <typename T, typename U> -struct CheckedMulFastAsmOp { - static const bool is_supported = - FastIntegerArithmeticPromotion<T, U>::is_contained; - - // The following is much more efficient than the Clang and GCC builtins for - // performing overflow-checked multiplication when a twice wider type is - // available. The below compiles down to 2-3 instructions, depending on the - // width of the types in use. - // As an example, an int32_t multiply compiles to: - // smull r0, r1, r0, r1 - // cmp r1, r1, asr #31 - // And an int16_t multiply compiles to: - // smulbb r1, r1, r0 - // asr r2, r1, #16 - // cmp r2, r1, asr #15 - template <typename V> - __attribute__((always_inline)) static bool Do(T x, U y, V* result) { - using Promotion = typename FastIntegerArithmeticPromotion<T, U>::type; - Promotion presult; - - presult = static_cast<Promotion>(x) * static_cast<Promotion>(y); - *result = static_cast<V>(presult); - return IsValueInRangeForNumericType<V>(presult); - } -}; - -template <typename T, typename U> -struct ClampedAddFastAsmOp { - static const bool is_supported = - BigEnoughPromotion<T, U>::is_contained && - IsTypeInRangeForNumericType< - int32_t, - typename BigEnoughPromotion<T, U>::type>::value; - - template <typename V> - __attribute__((always_inline)) static V Do(T x, U y) { - // This will get promoted to an int, so let the compiler do whatever is - // clever and rely on the saturated cast to bounds check. - if (IsIntegerArithmeticSafe<int, T, U>::value) - return saturated_cast<V>(x + y); - - int32_t result; - int32_t x_i32 = x; - int32_t y_i32 = y; - - asm("qadd %[result], %[first], %[second]" - : [result] "=r"(result) - : [first] "r"(x_i32), [second] "r"(y_i32)); - return saturated_cast<V>(result); - } -}; - -template <typename T, typename U> -struct ClampedSubFastAsmOp { - static const bool is_supported = - BigEnoughPromotion<T, U>::is_contained && - IsTypeInRangeForNumericType< - int32_t, - typename BigEnoughPromotion<T, U>::type>::value; - - template <typename V> - __attribute__((always_inline)) static V Do(T x, U y) { - // This will get promoted to an int, so let the compiler do whatever is - // clever and rely on the saturated cast to bounds check. - if (IsIntegerArithmeticSafe<int, T, U>::value) - return saturated_cast<V>(x - y); - - int32_t result; - int32_t x_i32 = x; - int32_t y_i32 = y; - - asm("qsub %[result], %[first], %[second]" - : [result] "=r"(result) - : [first] "r"(x_i32), [second] "r"(y_i32)); - return saturated_cast<V>(result); - } -}; - -template <typename T, typename U> -struct ClampedMulFastAsmOp { - static const bool is_supported = CheckedMulFastAsmOp<T, U>::is_supported; - - template <typename V> - __attribute__((always_inline)) static V Do(T x, U y) { - // Use the CheckedMulFastAsmOp for full-width 32-bit values, because - // it's fewer instructions than promoting and then saturating. - if (!IsIntegerArithmeticSafe<int32_t, T, U>::value && - !IsIntegerArithmeticSafe<uint32_t, T, U>::value) { - V result; - if (CheckedMulFastAsmOp<T, U>::Do(x, y, &result)) - return result; - return CommonMaxOrMin<V>(IsValueNegative(x) ^ IsValueNegative(y)); - } - - assert((FastIntegerArithmeticPromotion<T, U>::is_contained)); - using Promotion = typename FastIntegerArithmeticPromotion<T, U>::type; - return saturated_cast<V>(static_cast<Promotion>(x) * - static_cast<Promotion>(y)); - } -}; - -} // namespace internal -} // namespace base - -#endif // BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_
diff --git a/base/win/scoped_propvariant.h b/base/win/scoped_propvariant.h deleted file mode 100644 index 0f1d5c8..0000000 --- a/base/win/scoped_propvariant.h +++ /dev/null
@@ -1,54 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_WIN_SCOPED_PROPVARIANT_H_ -#define BASE_WIN_SCOPED_PROPVARIANT_H_ - -#include <propidl.h> - -#include "base/logging.h" -#include "base/macros.h" - -namespace base { -namespace win { - -// A PROPVARIANT that is automatically initialized and cleared upon respective -// construction and destruction of this class. -class ScopedPropVariant { - public: - ScopedPropVariant() { PropVariantInit(&pv_); } - - ~ScopedPropVariant() { Reset(); } - - // Returns a pointer to the underlying PROPVARIANT for use as an out param in - // a function call. - PROPVARIANT* Receive() { - DCHECK_EQ(pv_.vt, VT_EMPTY); - return &pv_; - } - - // Clears the instance to prepare it for re-use (e.g., via Receive). - void Reset() { - if (pv_.vt != VT_EMPTY) { - HRESULT result = PropVariantClear(&pv_); - DCHECK_EQ(result, S_OK); - } - } - - const PROPVARIANT& get() const { return pv_; } - const PROPVARIANT* ptr() const { return &pv_; } - - private: - PROPVARIANT pv_; - - // Comparison operators for ScopedPropVariant are not supported at this point. - bool operator==(const ScopedPropVariant&) const; - bool operator!=(const ScopedPropVariant&) const; - DISALLOW_COPY_AND_ASSIGN(ScopedPropVariant); -}; - -} // namespace win -} // namespace base - -#endif // BASE_WIN_SCOPED_PROPVARIANT_H_
diff --git a/base/win/scoped_select_object.h b/base/win/scoped_select_object.h deleted file mode 100644 index d4b1a81..0000000 --- a/base/win/scoped_select_object.h +++ /dev/null
@@ -1,42 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_WIN_SCOPED_SELECT_OBJECT_H_ -#define BASE_WIN_SCOPED_SELECT_OBJECT_H_ - -#include <windows.h> - -#include "base/logging.h" -#include "base/macros.h" - -namespace base { -namespace win { - -// Helper class for deselecting object from DC. -class ScopedSelectObject { - public: - ScopedSelectObject(HDC hdc, HGDIOBJ object) - : hdc_(hdc), oldobj_(SelectObject(hdc, object)) { - DCHECK(hdc_); - DCHECK(object); - DCHECK(oldobj_ != NULL && oldobj_ != HGDI_ERROR); - } - - ~ScopedSelectObject() { - HGDIOBJ object = SelectObject(hdc_, oldobj_); - DCHECK((GetObjectType(oldobj_) != OBJ_REGION && object != NULL) || - (GetObjectType(oldobj_) == OBJ_REGION && object != HGDI_ERROR)); - } - - private: - HDC hdc_; - HGDIOBJ oldobj_; - - DISALLOW_COPY_AND_ASSIGN(ScopedSelectObject); -}; - -} // namespace win -} // namespace base - -#endif // BASE_WIN_SCOPED_SELECT_OBJECT_H_
diff --git a/base/win/scoped_windows_thread_environment.h b/base/win/scoped_windows_thread_environment.h deleted file mode 100644 index 51f2a0d..0000000 --- a/base/win/scoped_windows_thread_environment.h +++ /dev/null
@@ -1,28 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_WIN_SCOPED_WINDOWS_THREAD_ENVIRONMENT_H_ -#define BASE_WIN_SCOPED_WINDOWS_THREAD_ENVIRONMENT_H_ - -#include "base/macros.h" - -namespace base { -namespace win { - -// Serves as a root class for ScopedCOMInitializer and ScopedWinrtInitializer. -class ScopedWindowsThreadEnvironment { - public: - ScopedWindowsThreadEnvironment() {} - virtual ~ScopedWindowsThreadEnvironment() {} - - virtual bool Succeeded() const = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedWindowsThreadEnvironment); -}; - -} // namespace win -} // namespace base - -#endif // BASE_WIN_SCOPED_WINDOWS_THREAD_ENVIRONMENT_H_
diff --git a/base/win/typed_event_handler.h b/base/win/typed_event_handler.h deleted file mode 100644 index fd62782..0000000 --- a/base/win/typed_event_handler.h +++ /dev/null
@@ -1,49 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_WIN_TYPED_EVENT_HANDLER_H_ -#define BASE_WIN_TYPED_EVENT_HANDLER_H_ - -#include <windows.foundation.collections.h> -#include <wrl/implements.h> - -#include <utility> - -#include "base/callback.h" - -namespace base { -namespace win { - -// This file provides an implementation of Windows::Foundation's -// ITypedEventHandler. It serves as a thin wrapper around a RepeatingCallback, -// that forwards the arguments to its |Invoke| method to the callback's |Run| -// method. -template <typename SenderT, typename ArgsT> -class TypedEventHandler - : public Microsoft::WRL::RuntimeClass< - Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, - ABI::Windows::Foundation::ITypedEventHandler<SenderT, ArgsT>> { - public: - using SenderAbiT = - typename ABI::Windows::Foundation::Internal::GetAbiType<SenderT>::type; - using ArgsAbiT = - typename ABI::Windows::Foundation::Internal::GetAbiType<ArgsT>::type; - - using Handler = base::RepeatingCallback<HRESULT(SenderAbiT, ArgsAbiT)>; - - explicit TypedEventHandler(Handler handler) : handler_(std::move(handler)) {} - - // ABI::Windows::Foundation::ITypedEventHandler: - IFACEMETHODIMP Invoke(SenderAbiT sender, ArgsAbiT args) override { - return handler_.Run(std::move(sender), std::move(args)); - } - - private: - Handler handler_; -}; - -} // namespace win -} // namespace base - -#endif // BASE_WIN_TYPED_EVENT_HANDLER_H_
diff --git a/build/gen.py b/build/gen.py index 44435f6..9f43290 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -237,7 +237,6 @@ 'base/files/scoped_temp_dir.cc', 'base/json/json_parser.cc', 'base/json/json_reader.cc', - 'base/json/json_string_value_serializer.cc', 'base/json/json_writer.cc', 'base/json/string_escape.cc', 'base/logging.cc', @@ -487,11 +486,7 @@ static_libraries['base']['sources'].extend([ 'base/files/file_util_mac.mm', 'base/mac/bundle_locations.mm', - 'base/mac/dispatch_source_mach.cc', 'base/mac/foundation_util.mm', - 'base/mac/mach_logging.cc', - 'base/mac/scoped_mach_port.cc', - 'base/mac/scoped_nsautorelease_pool.mm', 'base/strings/sys_string_conversions_mac.mm', ])