diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2016-05-20 23:09:12 -0700 |
---|---|---|
committer | Luis Hector Chavez <lhchavez@google.com> | 2016-05-27 20:33:51 +0000 |
commit | 637be7990843742d7ac6910ea909dcb09e9df175 (patch) | |
tree | f6c3acf0a40a22d05c8f58a06edf689a06c5d791 /third_party/chromium | |
parent | d1f98a07056edc27b2b5b8b780f761796a1d8b1d (diff) | |
download | libweave-637be7990843742d7ac6910ea909dcb09e9df175.tar.gz |
libweave: Update libchrome APIs to r395517
The new libchrome has been ported from Chromium and some APIs have
changed. Make necessary changes at call sites.
BUG: 28985443
TEST: All tests in libweave_test pass on dragonboard-eng build
TEST: make testall
Change-Id: Iccc8acbd968bc104af44a9053570edf028323cf5
Reviewed-on: https://weave-review.googlesource.com/3611
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'third_party/chromium')
21 files changed, 440 insertions, 597 deletions
diff --git a/third_party/chromium/base/bind_unittest.cc b/third_party/chromium/base/bind_unittest.cc index 76d158b..4c4f3e6 100644 --- a/third_party/chromium/base/bind_unittest.cc +++ b/third_party/chromium/base/bind_unittest.cc @@ -13,8 +13,8 @@ #include "base/callback.h" #include "base/macros.h" +#include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "build/build_config.h" @@ -823,7 +823,7 @@ struct CustomDeleter { }; using MoveOnlyTypesToTest = - ::testing::Types<scoped_ptr<DeleteCounter>, + ::testing::Types<std::unique_ptr<DeleteCounter>, std::unique_ptr<DeleteCounter>, std::unique_ptr<DeleteCounter, CustomDeleter>>; TYPED_TEST_CASE(BindMoveOnlyTypeTest, MoveOnlyTypesToTest); @@ -880,23 +880,23 @@ TYPED_TEST(BindMoveOnlyTypeTest, UnboundForwarding) { EXPECT_EQ(1, deletes); } -void VerifyVector(const std::vector<scoped_ptr<int>>& v) { +void VerifyVector(const std::vector<std::unique_ptr<int>>& v) { ASSERT_EQ(1u, v.size()); EXPECT_EQ(12345, *v[0]); } -std::vector<scoped_ptr<int>> AcceptAndReturnMoveOnlyVector( - std::vector<scoped_ptr<int>> v) { +std::vector<std::unique_ptr<int>> AcceptAndReturnMoveOnlyVector( + std::vector<std::unique_ptr<int>> v) { VerifyVector(v); return v; } // Test that a vector containing move-only types can be used with Callback. TEST_F(BindTest, BindMoveOnlyVector) { - using MoveOnlyVector = std::vector<scoped_ptr<int>>; + using MoveOnlyVector = std::vector<std::unique_ptr<int>>; MoveOnlyVector v; - v.push_back(make_scoped_ptr(new int(12345))); + v.push_back(base::MakeUnique<int>(12345)); // Early binding should work: base::Callback<MoveOnlyVector()> bound_cb = diff --git a/third_party/chromium/base/callback_internal.h b/third_party/chromium/base/callback_internal.h index 3682bf9..d700794 100644 --- a/third_party/chromium/base/callback_internal.h +++ b/third_party/chromium/base/callback_internal.h @@ -8,17 +8,12 @@ #ifndef BASE_CALLBACK_INTERNAL_H_ #define BASE_CALLBACK_INTERNAL_H_ -#include <stddef.h> -#include <map> -#include <memory> -#include <type_traits> -#include <vector> +#include <atomic> #include "base/base_export.h" #include "base/callback_forward.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" namespace base { namespace internal { @@ -117,129 +112,6 @@ class BASE_EXPORT CallbackBase<CopyMode::Copyable> extern template class CallbackBase<CopyMode::MoveOnly>; extern template class CallbackBase<CopyMode::Copyable>; -// A helper template to determine if given type is non-const move-only-type, -// i.e. if a value of the given type should be passed via std::move() in a -// destructive way. Types are considered to be move-only if they have a -// sentinel MoveOnlyTypeForCPP03 member: a class typically gets this from using -// the DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND macro. -// It would be easy to generalize this trait to all move-only types... but this -// confuses template deduction in VS2013 with certain types such as -// std::unique_ptr. -// TODO(dcheng): Revisit this when Windows switches to VS2015 by default. - -template <typename T> struct IsMoveOnlyType { - // Types YesType and NoType are guaranteed such that sizeof(YesType) < - // sizeof(NoType). - using YesType = char; - struct NoType { YesType dummy[2]; }; - - template <typename U> - static YesType Test(const typename U::MoveOnlyTypeForCPP03*); - - template <typename U> - static NoType Test(...); - - static const bool value = sizeof((Test<T>(0))) == sizeof(YesType) && - !std::is_const<T>::value; -}; - -// Specialization of IsMoveOnlyType so that std::unique_ptr is still considered -// move-only, even without the sentinel member. -template <typename T, typename D> -struct IsMoveOnlyType<std::unique_ptr<T, D>> : std::true_type {}; - -// Specialization of std::vector, so that it's considered move-only if the -// element type is move-only. Allocator is explicitly ignored when determining -// move-only status of the std::vector. -template <typename T, typename Allocator> -struct IsMoveOnlyType<std::vector<T, Allocator>> : IsMoveOnlyType<T> {}; - -template <typename> -struct CallbackParamTraitsForMoveOnlyType; - -template <typename> -struct CallbackParamTraitsForNonMoveOnlyType; - -// TODO(tzik): Use a default parameter once MSVS supports variadic templates -// with default values. -// http://connect.microsoft.com/VisualStudio/feedbackdetail/view/957801/compilation-error-with-variadic-templates -// -// This is a typetraits object that's used to take an argument type, and -// extract a suitable type for forwarding arguments. -template <typename T> -struct CallbackParamTraits - : std::conditional<IsMoveOnlyType<T>::value, - CallbackParamTraitsForMoveOnlyType<T>, - CallbackParamTraitsForNonMoveOnlyType<T>>::type { -}; - -template <typename T> -struct CallbackParamTraitsForNonMoveOnlyType { - using ForwardType = const T&; -}; - -// Note that for array types, we implicitly add a const in the conversion. This -// means that it is not possible to bind array arguments to functions that take -// a non-const pointer. Trying to specialize the template based on a "const -// T[n]" does not seem to match correctly, so we are stuck with this -// restriction. -template <typename T, size_t n> -struct CallbackParamTraitsForNonMoveOnlyType<T[n]> { - using ForwardType = const T*; -}; - -// See comment for CallbackParamTraits<T[n]>. -template <typename T> -struct CallbackParamTraitsForNonMoveOnlyType<T[]> { - using ForwardType = const T*; -}; - -// Parameter traits for movable-but-not-copyable scopers. -// -// Callback<>/Bind() understands movable-but-not-copyable semantics where -// the type cannot be copied but can still have its state destructively -// transferred (aka. moved) to another instance of the same type by calling a -// helper function. When used with Bind(), this signifies transferal of the -// object's state to the target function. -// -// For these types, the ForwardType must not be a const reference, or a -// reference. A const reference is inappropriate, and would break const -// correctness, because we are implementing a destructive move. A non-const -// reference cannot be used with temporaries which means the result of a -// function or a cast would not be usable with Callback<> or Bind(). -template <typename T> -struct CallbackParamTraitsForMoveOnlyType { - using ForwardType = T; -}; - -// CallbackForward() is a very limited simulation of C++11's std::forward() -// used by the Callback/Bind system for a set of movable-but-not-copyable -// types. It is needed because forwarding a movable-but-not-copyable -// argument to another function requires us to invoke the proper move -// operator to create a rvalue version of the type. The supported types are -// whitelisted below as overloads of the CallbackForward() function. The -// default template compiles out to be a no-op. -// -// In C++11, std::forward would replace all uses of this function. However, it -// is impossible to implement a general std::forward without C++11 due to a lack -// of rvalue references. -// -// In addition to Callback/Bind, this is used by PostTaskAndReplyWithResult to -// simulate std::forward() and forward the result of one Callback as a -// parameter to another callback. This is to support Callbacks that return -// the movable-but-not-copyable types whitelisted above. -template <typename T> -typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& CallbackForward( - T& t) { - return t; -} - -template <typename T> -typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward( - T& t) { - return std::move(t); -} - } // namespace internal } // namespace base diff --git a/third_party/chromium/base/callback_list.h b/third_party/chromium/base/callback_list.h index 7d6a478..7ab79dd 100644 --- a/third_party/chromium/base/callback_list.h +++ b/third_party/chromium/base/callback_list.h @@ -6,13 +6,12 @@ #define BASE_CALLBACK_LIST_H_ #include <list> +#include <memory> #include "base/callback.h" -#include "base/callback_internal.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" // OVERVIEW: // @@ -29,7 +28,7 @@ // // typedef base::Callback<void(const Foo&)> OnFooCallback; // -// scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> +// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription> // RegisterCallback(const OnFooCallback& cb) { // return callback_list_.Add(cb); // } @@ -62,7 +61,7 @@ // // Do something. // } // -// scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> +// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription> // foo_subscription_; // // DISALLOW_COPY_AND_ASSIGN(MyWidgetListener); @@ -103,9 +102,9 @@ class CallbackListBase { // 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. - scoped_ptr<Subscription> Add(const CallbackType& cb) WARN_UNUSED_RESULT { + std::unique_ptr<Subscription> Add(const CallbackType& cb) WARN_UNUSED_RESULT { DCHECK(!cb.is_null()); - return scoped_ptr<Subscription>( + return std::unique_ptr<Subscription>( new Subscription(this, callbacks_.insert(callbacks_.end(), cb))); } @@ -211,8 +210,8 @@ class CallbackList<void(Args...)> CallbackList() {} - void Notify( - typename internal::CallbackParamTraits<Args>::ForwardType... args) { + template <typename... RunArgs> + void Notify(RunArgs&&... args) { typename internal::CallbackListBase<CallbackType>::Iterator it = this->GetIterator(); CallbackType* cb; diff --git a/third_party/chromium/base/callback_list_unittest.cc b/third_party/chromium/base/callback_list_unittest.cc index 937910e..bd6634d 100644 --- a/third_party/chromium/base/callback_list_unittest.cc +++ b/third_party/chromium/base/callback_list_unittest.cc @@ -5,12 +5,12 @@ #include "base/callback_list.h" #include <gtest/gtest.h> +#include <memory> #include <utility> #include "base/bind.h" #include "base/bind_helpers.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" namespace base { namespace { @@ -38,7 +38,7 @@ class Remover { removal_subscription_.reset(); } void SetSubscriptionToRemove( - scoped_ptr<CallbackList<void(void)>::Subscription> sub) { + std::unique_ptr<CallbackList<void(void)>::Subscription> sub) { removal_subscription_ = std::move(sub); } @@ -46,7 +46,7 @@ class Remover { private: int total_; - scoped_ptr<CallbackList<void(void)>::Subscription> removal_subscription_; + std::unique_ptr<CallbackList<void(void)>::Subscription> removal_subscription_; DISALLOW_COPY_AND_ASSIGN(Remover); }; @@ -74,7 +74,7 @@ class Adder { bool added_; int total_; CallbackList<void(void)>* cb_reg_; - scoped_ptr<CallbackList<void(void)>::Subscription> subscription_; + std::unique_ptr<CallbackList<void(void)>::Subscription> subscription_; DISALLOW_COPY_AND_ASSIGN(Adder); }; @@ -118,42 +118,43 @@ TEST(CallbackListTest, ArityTest) { Summer s; CallbackList<void(int)> c1; - scoped_ptr<CallbackList<void(int)>::Subscription> subscription1 = + std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 = c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); c1.Notify(1); EXPECT_EQ(1, s.value()); CallbackList<void(int, int)> c2; - scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = + std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); c2.Notify(1, 2); EXPECT_EQ(3, s.value()); CallbackList<void(int, int, int)> c3; - scoped_ptr<CallbackList<void(int, int, int)>::Subscription> + std::unique_ptr<CallbackList<void(int, int, int)>::Subscription> subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); c3.Notify(1, 2, 3); EXPECT_EQ(6, s.value()); CallbackList<void(int, int, int, int)> c4; - scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription> + std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription> subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); c4.Notify(1, 2, 3, 4); EXPECT_EQ(10, s.value()); CallbackList<void(int, int, int, int, int)> c5; - scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> + std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); c5.Notify(1, 2, 3, 4, 5); EXPECT_EQ(15, s.value()); CallbackList<void(int, int, int, int, int, int)> c6; - scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription> + std::unique_ptr< + CallbackList<void(int, int, int, int, int, int)>::Subscription> subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s))); c6.Notify(1, 2, 3, 4, 5, 6); @@ -166,9 +167,9 @@ TEST(CallbackListTest, BasicTest) { CallbackList<void(void)> cb_reg; Listener a, b, c; - scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); - scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); EXPECT_TRUE(a_subscription.get()); @@ -181,7 +182,7 @@ TEST(CallbackListTest, BasicTest) { b_subscription.reset(); - scoped_ptr<CallbackList<void(void)>::Subscription> c_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c))); cb_reg.Notify(); @@ -201,9 +202,9 @@ TEST(CallbackListTest, BasicTestWithParams) { CallbackList<void(int)> cb_reg; Listener a(1), b(-1), c(1); - scoped_ptr<CallbackList<void(int)>::Subscription> a_subscription = + std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a))); - scoped_ptr<CallbackList<void(int)>::Subscription> b_subscription = + std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription = cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b))); EXPECT_TRUE(a_subscription.get()); @@ -216,7 +217,7 @@ TEST(CallbackListTest, BasicTestWithParams) { b_subscription.reset(); - scoped_ptr<CallbackList<void(int)>::Subscription> c_subscription = + std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription = cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c))); cb_reg.Notify(10); @@ -237,15 +238,15 @@ TEST(CallbackListTest, RemoveCallbacksDuringIteration) { Listener a, b; Remover remover_1, remover_2; - scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_1))); - scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_2))); - scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); + std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); + std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); - scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); // |remover_1| will remove itself. @@ -278,9 +279,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) { CallbackList<void(void)> cb_reg; Adder a(&cb_reg); Listener b; - scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a))); - scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); cb_reg.Notify(); @@ -308,7 +309,7 @@ TEST(CallbackList, RemovalCallback) { cb_reg.set_removal_callback( Bind(&Counter::Increment, Unretained(&remove_count))); - scoped_ptr<CallbackList<void(void)>::Subscription> subscription = + std::unique_ptr<CallbackList<void(void)>::Subscription> subscription = cb_reg.Add(Bind(&DoNothing)); // Removing a subscription outside of iteration signals the callback. @@ -318,12 +319,12 @@ TEST(CallbackList, RemovalCallback) { // Configure two subscriptions to remove themselves. Remover remover_1, remover_2; - scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_1))); - scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_2))); + std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); + std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); remover_2.SetSubscriptionToRemove(std::move(remover_2_sub)); diff --git a/third_party/chromium/base/callback_unittest.cc b/third_party/chromium/base/callback_unittest.cc index bf9d76f..0d35a9d 100644 --- a/third_party/chromium/base/callback_unittest.cc +++ b/third_party/chromium/base/callback_unittest.cc @@ -5,11 +5,11 @@ #include "base/callback.h" #include <gtest/gtest.h> +#include <memory> #include "base/bind.h" #include "base/callback_internal.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" namespace base { diff --git a/third_party/chromium/base/json/json_parser.cc b/third_party/chromium/base/json/json_parser.cc index 304a7bd..708965a 100644 --- a/third_party/chromium/base/json/json_parser.cc +++ b/third_party/chromium/base/json/json_parser.cc @@ -5,10 +5,11 @@ #include "base/json/json_parser.h" #include <cmath> +#include <utility> #include "base/logging.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" +#include "base/memory/ptr_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" @@ -26,16 +27,19 @@ const int kStackMaxDepth = 100; const int32_t kExtendedASCIIStart = 0x80; -// This and the class below are used to own the JSON input string for when -// string tokens are stored as StringPiece instead of std::string. This -// optimization avoids about 2/3rds of string memory copies. The constructor -// takes ownership of the input string. The real root value is Swap()ed into -// the new instance. +// DictionaryHiddenRootValue and ListHiddenRootValue are used in conjunction +// with JSONStringValue as an optimization for reducing the number of string +// copies. When this optimization is active, the parser uses a hidden root to +// keep the original JSON input string live and creates JSONStringValue children +// holding StringPiece references to the input string, avoiding about 2/3rds of +// string memory copies. The real root value is Swap()ed into the new instance. class DictionaryHiddenRootValue : public DictionaryValue { public: - DictionaryHiddenRootValue(std::string* json, Value* root) : json_(json) { + DictionaryHiddenRootValue(std::unique_ptr<std::string> json, + std::unique_ptr<Value> root) + : json_(std::move(json)) { DCHECK(root->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue::Swap(static_cast<DictionaryValue*>(root)); + DictionaryValue::Swap(static_cast<DictionaryValue*>(root.get())); } void Swap(DictionaryValue* other) override { @@ -43,7 +47,7 @@ class DictionaryHiddenRootValue : public DictionaryValue { // First deep copy to convert JSONStringValue to std::string and swap that // copy with |other|, which contains the new contents of |this|. - scoped_ptr<DictionaryValue> copy(DeepCopy()); + std::unique_ptr<DictionaryValue> copy(CreateDeepCopy()); copy->Swap(other); // Then erase the contents of the current dictionary and swap in the @@ -57,7 +61,7 @@ class DictionaryHiddenRootValue : public DictionaryValue { // the method below. bool RemoveWithoutPathExpansion(const std::string& key, - scoped_ptr<Value>* out) override { + std::unique_ptr<Value>* out) override { // If the caller won't take ownership of the removed value, just call up. if (!out) return DictionaryValue::RemoveWithoutPathExpansion(key, out); @@ -66,26 +70,28 @@ class DictionaryHiddenRootValue : public DictionaryValue { // Otherwise, remove the value while its still "owned" by this and copy it // to convert any JSONStringValues to std::string. - scoped_ptr<Value> out_owned; + std::unique_ptr<Value> out_owned; if (!DictionaryValue::RemoveWithoutPathExpansion(key, &out_owned)) return false; - out->reset(out_owned->DeepCopy()); + *out = out_owned->CreateDeepCopy(); return true; } private: - scoped_ptr<std::string> json_; + std::unique_ptr<std::string> json_; DISALLOW_COPY_AND_ASSIGN(DictionaryHiddenRootValue); }; class ListHiddenRootValue : public ListValue { public: - ListHiddenRootValue(std::string* json, Value* root) : json_(json) { + ListHiddenRootValue(std::unique_ptr<std::string> json, + std::unique_ptr<Value> root) + : json_(std::move(json)) { DCHECK(root->IsType(Value::TYPE_LIST)); - ListValue::Swap(static_cast<ListValue*>(root)); + ListValue::Swap(static_cast<ListValue*>(root.get())); } void Swap(ListValue* other) override { @@ -93,7 +99,7 @@ class ListHiddenRootValue : public ListValue { // First deep copy to convert JSONStringValue to std::string and swap that // copy with |other|, which contains the new contents of |this|. - scoped_ptr<ListValue> copy(DeepCopy()); + std::unique_ptr<ListValue> copy(CreateDeepCopy()); copy->Swap(other); // Then erase the contents of the current list and swap in the new contents, @@ -103,7 +109,7 @@ class ListHiddenRootValue : public ListValue { ListValue::Swap(copy.get()); } - bool Remove(size_t index, scoped_ptr<Value>* out) override { + bool Remove(size_t index, std::unique_ptr<Value>* out) override { // If the caller won't take ownership of the removed value, just call up. if (!out) return ListValue::Remove(index, out); @@ -112,17 +118,17 @@ class ListHiddenRootValue : public ListValue { // Otherwise, remove the value while its still "owned" by this and copy it // to convert any JSONStringValues to std::string. - scoped_ptr<Value> out_owned; + std::unique_ptr<Value> out_owned; if (!ListValue::Remove(index, &out_owned)) return false; - out->reset(out_owned->DeepCopy()); + *out = out_owned->CreateDeepCopy(); return true; } private: - scoped_ptr<std::string> json_; + std::unique_ptr<std::string> json_; DISALLOW_COPY_AND_ASSIGN(ListHiddenRootValue); }; @@ -132,10 +138,8 @@ class ListHiddenRootValue : public ListValue { // otherwise the referenced string will not be guaranteed to outlive it. class JSONStringValue : public Value { public: - explicit JSONStringValue(const StringPiece& piece) - : Value(TYPE_STRING), - string_piece_(piece) { - } + explicit JSONStringValue(StringPiece piece) + : Value(TYPE_STRING), string_piece_(piece) {} // Overridden from Value: bool GetAsString(std::string* out_value) const override { @@ -198,13 +202,13 @@ JSONParser::JSONParser(int options) JSONParser::~JSONParser() { } -Value* JSONParser::Parse(const StringPiece& input) { - scoped_ptr<std::string> input_copy; +std::unique_ptr<Value> JSONParser::Parse(StringPiece input) { + std::unique_ptr<std::string> input_copy; // If the children of a JSON root can be detached, then hidden roots cannot // be used, so do not bother copying the input because StringPiece will not // be used anywhere. if (!(options_ & JSON_DETACHABLE_CHILDREN)) { - input_copy.reset(new std::string(input.as_string())); + input_copy = WrapUnique(new std::string(input.as_string())); start_pos_ = input_copy->data(); } else { start_pos_ = input.data(); @@ -230,15 +234,15 @@ Value* JSONParser::Parse(const StringPiece& input) { } // Parse the first and any nested tokens. - scoped_ptr<Value> root(ParseNextToken()); - if (!root.get()) - return NULL; + std::unique_ptr<Value> root(ParseNextToken()); + if (!root) + return nullptr; // Make sure the input stream is at an end. if (GetNextToken() != T_END_OF_INPUT) { if (!CanConsume(1) || (NextChar() && GetNextToken() != T_END_OF_INPUT)) { ReportError(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, 1); - return NULL; + return nullptr; } } @@ -246,19 +250,21 @@ Value* JSONParser::Parse(const StringPiece& input) { // hidden root. if (!(options_ & JSON_DETACHABLE_CHILDREN)) { if (root->IsType(Value::TYPE_DICTIONARY)) { - return new DictionaryHiddenRootValue(input_copy.release(), root.get()); + return WrapUnique(new DictionaryHiddenRootValue(std::move(input_copy), + std::move(root))); } else if (root->IsType(Value::TYPE_LIST)) { - return new ListHiddenRootValue(input_copy.release(), root.get()); + return WrapUnique( + new ListHiddenRootValue(std::move(input_copy), std::move(root))); } else if (root->IsType(Value::TYPE_STRING)) { // A string type could be a JSONStringValue, but because there's no // corresponding HiddenRootValue, the memory will be lost. Deep copy to // preserve it. - return root->DeepCopy(); + return root->CreateDeepCopy(); } } // All other values can be returned directly. - return root.release(); + return root; } JSONReader::JsonParseError JSONParser::error_code() const { @@ -304,7 +310,7 @@ JSONParser::StringBuilder::~StringBuilder() { void JSONParser::StringBuilder::Append(const char& c) { DCHECK_GE(c, 0); - DCHECK_LT(c, 128); + DCHECK_LT(static_cast<unsigned char>(c), 128); if (string_) string_->push_back(c); @@ -494,7 +500,7 @@ Value* JSONParser::ConsumeDictionary() { return NULL; } - scoped_ptr<DictionaryValue> dict(new DictionaryValue); + std::unique_ptr<DictionaryValue> dict(new DictionaryValue); NextChar(); Token token = GetNextToken(); @@ -558,7 +564,7 @@ Value* JSONParser::ConsumeList() { return NULL; } - scoped_ptr<ListValue> list(new ListValue); + std::unique_ptr<ListValue> list(new ListValue); NextChar(); Token token = GetNextToken(); diff --git a/third_party/chromium/base/json/json_parser.h b/third_party/chromium/base/json/json_parser.h index fc04594..5bdec58 100644 --- a/third_party/chromium/base/json/json_parser.h +++ b/third_party/chromium/base/json/json_parser.h @@ -8,6 +8,7 @@ #include <stddef.h> #include <stdint.h> +#include <memory> #include <string> #include "base/base_export.h" @@ -50,7 +51,7 @@ class BASE_EXPORT JSONParser { // Parses the input string according to the set options and returns the // result as a Value owned by the caller. - Value* Parse(const StringPiece& input); + std::unique_ptr<Value> Parse(StringPiece input); // Returns the error code. JSONReader::JsonParseError error_code() const; @@ -133,7 +134,7 @@ class BASE_EXPORT JSONParser { size_t length_; // The copied string representation. NULL until Convert() is called. - // Strong. scoped_ptr<T> has too much of an overhead here. + // Strong. std::unique_ptr<T> has too much of an overhead here. std::string* string_; }; diff --git a/third_party/chromium/base/json/json_parser_unittest.cc b/third_party/chromium/base/json/json_parser_unittest.cc index 956e277..a6c360d 100644 --- a/third_party/chromium/base/json/json_parser_unittest.cc +++ b/third_party/chromium/base/json/json_parser_unittest.cc @@ -6,10 +6,11 @@ #include <stddef.h> +#include <memory> + #include <gtest/gtest.h> #include "base/json/json_reader.h" -#include "base/memory/scoped_ptr.h" #include "base/values.h" namespace base { @@ -35,7 +36,7 @@ class JSONParserTest : public testing::Test { TEST_F(JSONParserTest, NextChar) { std::string input("Hello world"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); EXPECT_EQ('H', *parser->pos_); for (size_t i = 1; i < input.length(); ++i) { @@ -46,8 +47,8 @@ TEST_F(JSONParserTest, NextChar) { TEST_F(JSONParserTest, ConsumeString) { std::string input("\"test\",|"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); - scoped_ptr<Value> value(parser->ConsumeString()); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<Value> value(parser->ConsumeString()); EXPECT_EQ('"', *parser->pos_); TestLastThree(parser.get()); @@ -60,8 +61,8 @@ TEST_F(JSONParserTest, ConsumeString) { TEST_F(JSONParserTest, ConsumeList) { std::string input("[true, false],|"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); - scoped_ptr<Value> value(parser->ConsumeList()); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<Value> value(parser->ConsumeList()); EXPECT_EQ(']', *parser->pos_); TestLastThree(parser.get()); @@ -74,8 +75,8 @@ TEST_F(JSONParserTest, ConsumeList) { TEST_F(JSONParserTest, ConsumeDictionary) { std::string input("{\"abc\":\"def\"},|"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); - scoped_ptr<Value> value(parser->ConsumeDictionary()); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<Value> value(parser->ConsumeDictionary()); EXPECT_EQ('}', *parser->pos_); TestLastThree(parser.get()); @@ -91,8 +92,8 @@ TEST_F(JSONParserTest, ConsumeDictionary) { TEST_F(JSONParserTest, ConsumeLiterals) { // Literal |true|. std::string input("true,|"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); - scoped_ptr<Value> value(parser->ConsumeLiteral()); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<Value> value(parser->ConsumeLiteral()); EXPECT_EQ('e', *parser->pos_); TestLastThree(parser.get()); @@ -129,8 +130,8 @@ TEST_F(JSONParserTest, ConsumeLiterals) { TEST_F(JSONParserTest, ConsumeNumbers) { // Integer. std::string input("1234,|"); - scoped_ptr<JSONParser> parser(NewTestParser(input)); - scoped_ptr<Value> value(parser->ConsumeNumber()); + std::unique_ptr<JSONParser> parser(NewTestParser(input)); + std::unique_ptr<Value> value(parser->ConsumeNumber()); EXPECT_EQ('4', *parser->pos_); TestLastThree(parser.get()); @@ -206,7 +207,7 @@ TEST_F(JSONParserTest, ErrorMessages) { // Error strings should not be modified in case of success. std::string error_message; int error_code = 0; - scoped_ptr<Value> root = JSONReader::ReadAndReturnError( + std::unique_ptr<Value> root = JSONReader::ReadAndReturnError( "[42]", JSON_PARSE_RFC, &error_code, &error_message); EXPECT_TRUE(error_message.empty()); EXPECT_EQ(0, error_code); @@ -310,7 +311,7 @@ TEST_F(JSONParserTest, Decode4ByteUtf8Char) { "[\"😇\",[],[],[],{\"google:suggesttype\":[]}]"; std::string error_message; int error_code = 0; - scoped_ptr<Value> root = JSONReader::ReadAndReturnError( + std::unique_ptr<Value> root = JSONReader::ReadAndReturnError( kUtf8Data, JSON_PARSE_RFC, &error_code, &error_message); EXPECT_TRUE(root.get()) << error_message; } diff --git a/third_party/chromium/base/json/json_reader.cc b/third_party/chromium/base/json/json_reader.cc index 3ab5f75..4ff7496 100644 --- a/third_party/chromium/base/json/json_reader.cc +++ b/third_party/chromium/base/json/json_reader.cc @@ -43,27 +43,28 @@ JSONReader::~JSONReader() { } // static -scoped_ptr<Value> JSONReader::Read(const StringPiece& json) { +std::unique_ptr<Value> JSONReader::Read(StringPiece json) { internal::JSONParser parser(JSON_PARSE_RFC); - return make_scoped_ptr(parser.Parse(json)); + return parser.Parse(json); } // static -scoped_ptr<Value> JSONReader::Read(const StringPiece& json, int options) { +std::unique_ptr<Value> JSONReader::Read(StringPiece json, int options) { internal::JSONParser parser(options); - return make_scoped_ptr(parser.Parse(json)); + return parser.Parse(json); } // static -scoped_ptr<Value> JSONReader::ReadAndReturnError(const StringPiece& json, - int options, - int* error_code_out, - std::string* error_msg_out, - int* error_line_out, - int* error_column_out) { +std::unique_ptr<Value> JSONReader::ReadAndReturnError( + const StringPiece& json, + int options, + int* error_code_out, + std::string* error_msg_out, + int* error_line_out, + int* error_column_out) { internal::JSONParser parser(options); - scoped_ptr<Value> root(parser.Parse(json)); + std::unique_ptr<Value> root(parser.Parse(json)); if (!root) { if (error_code_out) *error_code_out = parser.error_code(); @@ -105,8 +106,8 @@ std::string JSONReader::ErrorCodeToString(JsonParseError error_code) { } } -scoped_ptr<Value> JSONReader::ReadToValue(const std::string& json) { - return make_scoped_ptr(parser_->Parse(json)); +std::unique_ptr<Value> JSONReader::ReadToValue(StringPiece json) { + return parser_->Parse(json); } JSONReader::JsonParseError JSONReader::error_code() const { diff --git a/third_party/chromium/base/json/json_reader.h b/third_party/chromium/base/json/json_reader.h index c6bcb52..f647724 100644 --- a/third_party/chromium/base/json/json_reader.h +++ b/third_party/chromium/base/json/json_reader.h @@ -28,10 +28,10 @@ #ifndef BASE_JSON_JSON_READER_H_ #define BASE_JSON_JSON_READER_H_ +#include <memory> #include <string> #include "base/base_export.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/string_piece.h" namespace base { @@ -93,30 +93,31 @@ class BASE_EXPORT JSONReader { // Reads and parses |json|, returning a Value. The caller owns the returned // instance. If |json| is not a properly formed JSON string, returns NULL. - static scoped_ptr<Value> Read(const StringPiece& json); + static std::unique_ptr<Value> Read(StringPiece json); // Reads and parses |json|, returning a Value owned by the caller. The // parser respects the given |options|. If the input is not properly formed, // returns NULL. - static scoped_ptr<Value> Read(const StringPiece& json, int options); + static std::unique_ptr<Value> Read(StringPiece json, int options); // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out| // are optional. If specified and NULL is returned, they will be populated // an error code and a formatted error message (including error location if // appropriate). Otherwise, they will be unmodified. - static scoped_ptr<Value> ReadAndReturnError(const StringPiece& json, - int options, // JSONParserOptions - int* error_code_out, - std::string* error_msg_out, - int* error_line_out = nullptr, - int* error_column_out = nullptr); + static std::unique_ptr<Value> ReadAndReturnError( + const StringPiece& json, + int options, // JSONParserOptions + int* error_code_out, + std::string* error_msg_out, + int* error_line_out = nullptr, + int* error_column_out = nullptr); // Converts a JSON parse error code into a human readable message. // Returns an empty string if error_code is JSON_NO_ERROR. static std::string ErrorCodeToString(JsonParseError error_code); // Parses an input string into a Value that is owned by the caller. - scoped_ptr<Value> ReadToValue(const std::string& json); + std::unique_ptr<Value> ReadToValue(StringPiece json); // Returns the error code if the last call to ReadToValue() failed. // Returns JSON_NO_ERROR otherwise. @@ -127,7 +128,7 @@ class BASE_EXPORT JSONReader { std::string GetErrorMessage() const; private: - scoped_ptr<internal::JSONParser> parser_; + std::unique_ptr<internal::JSONParser> parser_; }; } // namespace base diff --git a/third_party/chromium/base/json/json_reader_unittest.cc b/third_party/chromium/base/json/json_reader_unittest.cc index 2bfd10e..b1ad46e 100644 --- a/third_party/chromium/base/json/json_reader_unittest.cc +++ b/third_party/chromium/base/json/json_reader_unittest.cc @@ -7,10 +7,10 @@ #include <stddef.h> #include <gtest/gtest.h> +#include <memory> #include "base/logging.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/string_piece.h" #include "base/strings/utf_string_conversion_utils.h" #include "base/values.h" @@ -20,7 +20,7 @@ namespace base { TEST(JSONReaderTest, Reading) { // some whitespace checking - scoped_ptr<Value> root = JSONReader().ReadToValue(" null "); + std::unique_ptr<Value> root = JSONReader().ReadToValue(" null "); ASSERT_TRUE(root.get()); EXPECT_TRUE(root->IsType(Value::TYPE_NULL)); @@ -249,7 +249,7 @@ TEST(JSONReaderTest, Reading) { EXPECT_EQ(3U, list->GetSize()); // Test with trailing comma. Should be parsed the same as above. - scoped_ptr<Value> root2 = + std::unique_ptr<Value> root2 = JSONReader::Read("[true, false, null, ]", JSON_ALLOW_TRAILING_COMMAS); EXPECT_TRUE(root->Equals(root2.get())); @@ -543,15 +543,15 @@ TEST(JSONReaderTest, Reading) { // Tests that the root of a JSON object can be deleted safely while its // children outlive it. TEST(JSONReaderTest, StringOptimizations) { - scoped_ptr<Value> dict_literal_0; - scoped_ptr<Value> dict_literal_1; - scoped_ptr<Value> dict_string_0; - scoped_ptr<Value> dict_string_1; - scoped_ptr<Value> list_value_0; - scoped_ptr<Value> list_value_1; + std::unique_ptr<Value> dict_literal_0; + std::unique_ptr<Value> dict_literal_1; + std::unique_ptr<Value> dict_string_0; + std::unique_ptr<Value> dict_string_1; + std::unique_ptr<Value> list_value_0; + std::unique_ptr<Value> list_value_1; { - scoped_ptr<Value> root = JSONReader::Read( + std::unique_ptr<Value> root = JSONReader::Read( "{" " \"test\": {" " \"foo\": true," diff --git a/third_party/chromium/base/json/json_writer_unittest.cc b/third_party/chromium/base/json/json_writer_unittest.cc index ca99f4d..7aaa78b 100644 --- a/third_party/chromium/base/json/json_writer_unittest.cc +++ b/third_party/chromium/base/json/json_writer_unittest.cc @@ -6,6 +6,7 @@ #include <gtest/gtest.h> +#include "base/memory/ptr_util.h" #include "base/values.h" #include "build/build_config.h" @@ -57,11 +58,11 @@ TEST(JSONWriterTest, NestedTypes) { // Writer unittests like empty list/dict nesting, // list list nesting, etc. DictionaryValue root_dict; - scoped_ptr<ListValue> list(new ListValue()); - scoped_ptr<DictionaryValue> inner_dict(new DictionaryValue()); + std::unique_ptr<ListValue> list(new ListValue()); + std::unique_ptr<DictionaryValue> inner_dict(new DictionaryValue()); inner_dict->SetInteger("inner int", 10); list->Append(std::move(inner_dict)); - list->Append(make_scoped_ptr(new ListValue())); + list->Append(WrapUnique(new ListValue())); list->AppendBoolean(true); root_dict.Set("list", std::move(list)); @@ -93,7 +94,7 @@ TEST(JSONWriterTest, KeysWithPeriods) { DictionaryValue period_dict; period_dict.SetIntegerWithoutPathExpansion("a.b", 3); period_dict.SetIntegerWithoutPathExpansion("c", 2); - scoped_ptr<DictionaryValue> period_dict2(new DictionaryValue()); + std::unique_ptr<DictionaryValue> period_dict2(new DictionaryValue()); period_dict2->SetIntegerWithoutPathExpansion("g.h.i.j", 1); period_dict.SetWithoutPathExpansion("d.e.f", std::move(period_dict2)); EXPECT_TRUE(JSONWriter::Write(period_dict, &output_js)); @@ -111,7 +112,7 @@ TEST(JSONWriterTest, BinaryValues) { // Binary values should return errors unless suppressed via the // OPTIONS_OMIT_BINARY_VALUES flag. - scoped_ptr<Value> root(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); + std::unique_ptr<Value> root(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); EXPECT_FALSE(JSONWriter::Write(*root, &output_js)); EXPECT_TRUE(JSONWriter::WriteWithOptions( *root, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js)); @@ -119,9 +120,9 @@ TEST(JSONWriterTest, BinaryValues) { ListValue binary_list; binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); - binary_list.Append(make_scoped_ptr(new FundamentalValue(5))); + binary_list.Append(WrapUnique(new FundamentalValue(5))); binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); - binary_list.Append(make_scoped_ptr(new FundamentalValue(2))); + binary_list.Append(WrapUnique(new FundamentalValue(2))); binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); EXPECT_FALSE(JSONWriter::Write(binary_list, &output_js)); EXPECT_TRUE(JSONWriter::WriteWithOptions( @@ -130,13 +131,13 @@ TEST(JSONWriterTest, BinaryValues) { DictionaryValue binary_dict; binary_dict.Set( - "a", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); + "a", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); binary_dict.SetInteger("b", 5); binary_dict.Set( - "c", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); + "c", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); binary_dict.SetInteger("d", 2); binary_dict.Set( - "e", make_scoped_ptr(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); + "e", WrapUnique(BinaryValue::CreateWithCopiedBuffer("asdf", 4))); EXPECT_FALSE(JSONWriter::Write(binary_dict, &output_js)); EXPECT_TRUE(JSONWriter::WriteWithOptions( binary_dict, JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &output_js)); diff --git a/third_party/chromium/base/memory/ptr_util.h b/third_party/chromium/base/memory/ptr_util.h new file mode 100644 index 0000000..8747ac9 --- /dev/null +++ b/third_party/chromium/base/memory/ptr_util.h @@ -0,0 +1,74 @@ +// Copyright 2015 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_MEMORY_PTR_UTIL_H_ +#define BASE_MEMORY_PTR_UTIL_H_ + +#include <memory> +#include <utility> + +namespace base { + +// Helper to transfer ownership of a raw pointer to a std::unique_ptr<T>. +// Note that std::unique_ptr<T> has very different semantics from +// std::unique_ptr<T[]>: do not use this helper for array allocations. +template <typename T> +std::unique_ptr<T> WrapUnique(T* ptr) { + return std::unique_ptr<T>(ptr); +} + +namespace internal { + +template <typename T> +struct MakeUniqueResult { + using Scalar = std::unique_ptr<T>; +}; + +template <typename T> +struct MakeUniqueResult<T[]> { + using Array = std::unique_ptr<T[]>; +}; + +template <typename T, size_t N> +struct MakeUniqueResult<T[N]> { + using Invalid = void; +}; + +} // namespace internal + +// Helper to construct an object wrapped in a std::unique_ptr. This is an +// implementation of C++14's std::make_unique that can be used in Chrome. +// +// MakeUnique<T>(args) should be preferred over WrapUnique(new T(args)): bare +// calls to `new` should be treated with scrutiny. +// +// Usage: +// // ptr is a std::unique_ptr<std::string> +// auto ptr = MakeUnique<std::string>("hello world!"); +// +// // arr is a std::unique_ptr<int[]> +// auto arr = MakeUnique<int[]>(5); + +// Overload for non-array types. Arguments are forwarded to T's constructor. +template <typename T, typename... Args> +typename internal::MakeUniqueResult<T>::Scalar MakeUnique(Args&&... args) { + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} + +// Overload for array types of unknown bound, e.g. T[]. The array is allocated +// with `new T[n]()` and value-initialized: note that this is distinct from +// `new T[n]`, which default-initializes. +template <typename T> +typename internal::MakeUniqueResult<T>::Array MakeUnique(size_t size) { + return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]()); +} + +// Overload to reject array types of known bound, e.g. T[n]. +template <typename T, typename... Args> +typename internal::MakeUniqueResult<T>::Invalid MakeUnique(Args&&... args) = + delete; + +} // namespace base + +#endif // BASE_MEMORY_PTR_UTIL_H_ diff --git a/third_party/chromium/base/memory/scoped_ptr.h b/third_party/chromium/base/memory/scoped_ptr.h deleted file mode 100644 index 2d2c0ec..0000000 --- a/third_party/chromium/base/memory/scoped_ptr.h +++ /dev/null @@ -1,135 +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. - -// Scopers help you manage ownership of a pointer, helping you easily manage a -// pointer within a scope, and automatically destroying the pointer at the end -// of a scope. There are two main classes you will use, which correspond to the -// operators new/delete and new[]/delete[]. -// -// Example usage (scoped_ptr<T>): -// { -// scoped_ptr<Foo> foo(new Foo("wee")); -// } // foo goes out of scope, releasing the pointer with it. -// -// { -// scoped_ptr<Foo> foo; // No pointer managed. -// foo.reset(new Foo("wee")); // Now a pointer is managed. -// foo.reset(new Foo("wee2")); // Foo("wee") was destroyed. -// foo.reset(new Foo("wee3")); // Foo("wee2") was destroyed. -// foo->Method(); // Foo::Method() called. -// foo.get()->Method(); // Foo::Method() called. -// SomeFunc(foo.release()); // SomeFunc takes ownership, foo no longer -// // manages a pointer. -// foo.reset(new Foo("wee4")); // foo manages a pointer again. -// foo.reset(); // Foo("wee4") destroyed, foo no longer -// // manages a pointer. -// } // foo wasn't managing a pointer, so nothing was destroyed. -// -// Example usage (scoped_ptr<T[]>): -// { -// scoped_ptr<Foo[]> foo(new Foo[100]); -// foo.get()->Method(); // Foo::Method on the 0th element. -// foo[10].Method(); // Foo::Method on the 10th element. -// } -// -// Scopers are testable as booleans: -// { -// scoped_ptr<Foo> foo; -// if (!foo) -// foo.reset(new Foo()); -// if (foo) -// LOG(INFO) << "This code is reached." -// } -// -// These scopers also implement part of the functionality of C++11 unique_ptr -// in that they are "movable but not copyable." You can use the scopers in -// the parameter and return types of functions to signify ownership transfer -// in to and out of a function. When calling a function that has a scoper -// as the argument type, it must be called with an rvalue of a scoper, which -// can be created by using std::move(), or the result of another function that -// generates a temporary; passing by copy will NOT work. Here is an example -// using scoped_ptr: -// -// void TakesOwnership(scoped_ptr<Foo> arg) { -// // Do something with arg. -// } -// scoped_ptr<Foo> CreateFoo() { -// // No need for calling std::move() for returning a move-only value, or -// // when you already have an rvalue as we do here. -// return scoped_ptr<Foo>(new Foo("new")); -// } -// scoped_ptr<Foo> PassThru(scoped_ptr<Foo> arg) { -// return arg; -// } -// -// { -// scoped_ptr<Foo> ptr(new Foo("yay")); // ptr manages Foo("yay"). -// TakesOwnership(std::move(ptr)); // ptr no longer owns Foo("yay"). -// scoped_ptr<Foo> ptr2 = CreateFoo(); // ptr2 owns the return Foo. -// scoped_ptr<Foo> ptr3 = // ptr3 now owns what was in ptr2. -// PassThru(std::move(ptr2)); // ptr2 is correspondingly nullptr. -// } -// -// Notice that if you do not call std::move() when returning from PassThru(), or -// when invoking TakesOwnership(), the code will not compile because scopers -// are not copyable; they only implement move semantics which require calling -// the std::move() function to signify a destructive transfer of state. -// CreateFoo() is different though because we are constructing a temporary on -// the return line and thus can avoid needing to call std::move(). -// -// The conversion move-constructor properly handles upcast in initialization, -// i.e. you can use a scoped_ptr<Child> to initialize a scoped_ptr<Parent>: -// -// scoped_ptr<Foo> foo(new Foo()); -// scoped_ptr<FooParent> parent(std::move(foo)); - -#ifndef BASE_MEMORY_SCOPED_PTR_H_ -#define BASE_MEMORY_SCOPED_PTR_H_ - -// This is an implementation designed to match the anticipated future TR2 -// implementation of the scoped_ptr class. - -// TODO(dcheng): Clean up these headers, but there are likely lots of existing -// IWYU violations. -#include <stddef.h> -#include <stdlib.h> - -#include <iosfwd> -#include <memory> -#include <type_traits> -#include <utility> - -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/move.h" -#include "build/build_config.h" - -namespace base { - -// Function object which invokes 'free' on its parameter, which must be -// a pointer. Can be used to store malloc-allocated pointers in scoped_ptr: -// -// scoped_ptr<int, base::FreeDeleter> foo_ptr( -// static_cast<int*>(malloc(sizeof(int)))); -struct FreeDeleter { - inline void operator()(void* ptr) const { - free(ptr); - } -}; - -} // namespace base - -template <typename T, typename D = std::default_delete<T>> -using scoped_ptr = std::unique_ptr<T, D>; - -// A function to convert T* into scoped_ptr<T> -// Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation -// for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) -template <typename T> -scoped_ptr<T> make_scoped_ptr(T* ptr) { - return scoped_ptr<T>(ptr); -} - -#endif // BASE_MEMORY_SCOPED_PTR_H_ diff --git a/third_party/chromium/base/memory/weak_ptr.h b/third_party/chromium/base/memory/weak_ptr.h index 601c379..2efb024 100644 --- a/third_party/chromium/base/memory/weak_ptr.h +++ b/third_party/chromium/base/memory/weak_ptr.h @@ -3,7 +3,7 @@ // found in the LICENSE file. // Weak pointers are pointers to an object that do not affect its lifetime, -// and which may be invalidated (i.e. reset to NULL) by the object, or its +// and which may be invalidated (i.e. reset to nullptr) by the object, or its // owner, at any time, most commonly when the object is about to be deleted. // Weak pointers are useful when an object needs to be accessed safely by one @@ -70,6 +70,7 @@ #ifndef BASE_MEMORY_WEAK_PTR_H_ #define BASE_MEMORY_WEAK_PTR_H_ +#include <cstddef> #include <type_traits> #include "base/base_export.h" @@ -197,8 +198,9 @@ template <typename T> class WeakPtrFactory; template <typename T> class WeakPtr : public internal::WeakPtrBase { public: - WeakPtr() : ptr_(NULL) { - } + WeakPtr() : ptr_(nullptr) {} + + WeakPtr(std::nullptr_t) : ptr_(nullptr) {} // Allow conversion from U to T provided U "is a" T. Note that this // is separate from the (implicit) copy constructor. @@ -206,20 +208,20 @@ class WeakPtr : public internal::WeakPtrBase { WeakPtr(const WeakPtr<U>& other) : WeakPtrBase(other), ptr_(other.ptr_) { } - T* get() const { return ref_.is_valid() ? ptr_ : NULL; } + T* get() const { return ref_.is_valid() ? ptr_ : nullptr; } T& operator*() const { - DCHECK(get() != NULL); + DCHECK(get() != nullptr); return *get(); } T* operator->() const { - DCHECK(get() != NULL); + DCHECK(get() != nullptr); return get(); } void reset() { ref_ = internal::WeakReference(); - ptr_ = NULL; + ptr_ = nullptr; } // Implement "Safe Bool Idiom" @@ -244,7 +246,7 @@ class WeakPtr : public internal::WeakPtrBase { typedef T* WeakPtr::*Testable; public: - operator Testable() const { return get() ? &WeakPtr::ptr_ : NULL; } + operator Testable() const { return get() ? &WeakPtr::ptr_ : nullptr; } private: // Explicitly declare comparison operators as required by the "Safe Bool @@ -263,7 +265,7 @@ class WeakPtr : public internal::WeakPtrBase { } // This pointer is only valid when ref_.is_valid() is true. Otherwise, its - // value is undefined (as opposed to NULL). + // value is undefined (as opposed to nullptr). T* ptr_; }; @@ -278,9 +280,7 @@ class WeakPtrFactory { explicit WeakPtrFactory(T* ptr) : ptr_(ptr) { } - ~WeakPtrFactory() { - ptr_ = NULL; - } + ~WeakPtrFactory() { ptr_ = nullptr; } WeakPtr<T> GetWeakPtr() { DCHECK(ptr_); diff --git a/third_party/chromium/base/memory/weak_ptr_unittest.cc b/third_party/chromium/base/memory/weak_ptr_unittest.cc index fdbb280..982becd 100644 --- a/third_party/chromium/base/memory/weak_ptr_unittest.cc +++ b/third_party/chromium/base/memory/weak_ptr_unittest.cc @@ -4,17 +4,21 @@ #include "base/memory/weak_ptr.h" +#include <memory> #include <string> #include <gtest/gtest.h> #include "base/bind.h" #include "base/location.h" -#include "base/memory/scoped_ptr.h" namespace base { namespace { +WeakPtr<int> PassThru(WeakPtr<int> ptr) { + return ptr; +} + struct Base { std::string member; }; @@ -52,13 +56,13 @@ TEST(WeakPtrFactoryTest, Comparison) { TEST(WeakPtrFactoryTest, OutOfScope) { WeakPtr<int> ptr; - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); { int data; WeakPtrFactory<int> factory(&data); ptr = factory.GetWeakPtr(); } - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); } TEST(WeakPtrFactoryTest, Multiple) { @@ -71,8 +75,8 @@ TEST(WeakPtrFactoryTest, Multiple) { EXPECT_EQ(&data, a.get()); EXPECT_EQ(&data, b.get()); } - EXPECT_EQ(NULL, a.get()); - EXPECT_EQ(NULL, b.get()); + EXPECT_EQ(nullptr, a.get()); + EXPECT_EQ(nullptr, b.get()); } TEST(WeakPtrFactoryTest, MultipleStaged) { @@ -84,9 +88,9 @@ TEST(WeakPtrFactoryTest, MultipleStaged) { { WeakPtr<int> b = factory.GetWeakPtr(); } - EXPECT_TRUE(NULL != a.get()); + EXPECT_NE(nullptr, a.get()); } - EXPECT_EQ(NULL, a.get()); + EXPECT_EQ(nullptr, a.get()); } TEST(WeakPtrFactoryTest, Dereference) { @@ -107,6 +111,11 @@ TEST(WeakPtrFactoryTest, UpCast) { EXPECT_EQ(ptr.get(), &data); } +TEST(WeakPtrTest, ConstructFromNullptr) { + WeakPtr<int> ptr = PassThru(nullptr); + EXPECT_EQ(nullptr, ptr.get()); +} + TEST(WeakPtrTest, SupportsWeakPtr) { Target target; WeakPtr<Target> ptr = target.AsWeakPtr(); @@ -157,7 +166,7 @@ TEST(WeakPtrTest, InvalidateWeakPtrs) { EXPECT_EQ(&data, ptr.get()); EXPECT_TRUE(factory.HasWeakPtrs()); factory.InvalidateWeakPtrs(); - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); EXPECT_FALSE(factory.HasWeakPtrs()); // Test that the factory can create new weak pointers after a @@ -167,7 +176,7 @@ TEST(WeakPtrTest, InvalidateWeakPtrs) { EXPECT_EQ(&data, ptr2.get()); EXPECT_TRUE(factory.HasWeakPtrs()); factory.InvalidateWeakPtrs(); - EXPECT_EQ(NULL, ptr2.get()); + EXPECT_EQ(nullptr, ptr2.get()); EXPECT_FALSE(factory.HasWeakPtrs()); } diff --git a/third_party/chromium/base/rand_util_unittest.cc b/third_party/chromium/base/rand_util_unittest.cc index fc0233d..da4023f 100644 --- a/third_party/chromium/base/rand_util_unittest.cc +++ b/third_party/chromium/base/rand_util_unittest.cc @@ -9,11 +9,11 @@ #include <algorithm> #include <limits> +#include <memory> #include <gtest/gtest.h> #include "base/logging.h" -#include "base/memory/scoped_ptr.h" #include "base/time/time.h" namespace { diff --git a/third_party/chromium/base/values.cc b/third_party/chromium/base/values.cc index 29f0301..4af9919 100644 --- a/third_party/chromium/base/values.cc +++ b/third_party/chromium/base/values.cc @@ -13,6 +13,7 @@ #include "base/json/json_writer.h" #include "base/logging.h" +#include "base/memory/ptr_util.h" #include "base/move.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversion_utils.h" @@ -21,15 +22,15 @@ namespace base { namespace { -scoped_ptr<Value> CopyWithoutEmptyChildren(const Value& node); +std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node); // Make a deep copy of |node|, but don't include empty lists or dictionaries // in the copy. It's possible for this function to return NULL and it // expects |node| to always be non-NULL. -scoped_ptr<ListValue> CopyListWithoutEmptyChildren(const ListValue& list) { - scoped_ptr<ListValue> copy; +std::unique_ptr<ListValue> CopyListWithoutEmptyChildren(const ListValue& list) { + std::unique_ptr<ListValue> copy; for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { - scoped_ptr<Value> child_copy = CopyWithoutEmptyChildren(**it); + std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(**it); if (child_copy) { if (!copy) copy.reset(new ListValue); @@ -39,11 +40,11 @@ scoped_ptr<ListValue> CopyListWithoutEmptyChildren(const ListValue& list) { return copy; } -scoped_ptr<DictionaryValue> CopyDictionaryWithoutEmptyChildren( +std::unique_ptr<DictionaryValue> CopyDictionaryWithoutEmptyChildren( const DictionaryValue& dict) { - scoped_ptr<DictionaryValue> copy; + std::unique_ptr<DictionaryValue> copy; for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { - scoped_ptr<Value> child_copy = CopyWithoutEmptyChildren(it.value()); + std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(it.value()); if (child_copy) { if (!copy) copy.reset(new DictionaryValue); @@ -53,7 +54,7 @@ scoped_ptr<DictionaryValue> CopyDictionaryWithoutEmptyChildren( return copy; } -scoped_ptr<Value> CopyWithoutEmptyChildren(const Value& node) { +std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node) { switch (node.GetType()) { case Value::TYPE_LIST: return CopyListWithoutEmptyChildren(static_cast<const ListValue&>(node)); @@ -89,47 +90,47 @@ Value::~Value() { } // static -scoped_ptr<Value> Value::CreateNullValue() { - return make_scoped_ptr(new Value(TYPE_NULL)); +std::unique_ptr<Value> Value::CreateNullValue() { + return WrapUnique(new Value(TYPE_NULL)); } -bool Value::GetAsBinary(const BinaryValue** /* out_value */) const { +bool Value::GetAsBinary(const BinaryValue**) const { return false; } -bool Value::GetAsBoolean(bool* /* out_value */) const { +bool Value::GetAsBoolean(bool*) const { return false; } -bool Value::GetAsInteger(int* /* out_value */) const { +bool Value::GetAsInteger(int*) const { return false; } -bool Value::GetAsDouble(double* /* out_value */) const { +bool Value::GetAsDouble(double*) const { return false; } -bool Value::GetAsString(std::string* /* out_value */) const { +bool Value::GetAsString(std::string*) const { return false; } -bool Value::GetAsString(const StringValue** out_value) const { +bool Value::GetAsString(const StringValue**) const { return false; } -bool Value::GetAsList(ListValue** /* out_value */) { +bool Value::GetAsList(ListValue**) { return false; } -bool Value::GetAsList(const ListValue** /* out_value */) const { +bool Value::GetAsList(const ListValue**) const { return false; } -bool Value::GetAsDictionary(DictionaryValue** /* out_value */) { +bool Value::GetAsDictionary(DictionaryValue**) { return false; } -bool Value::GetAsDictionary(const DictionaryValue** /* out_value */) const { +bool Value::GetAsDictionary(const DictionaryValue**) const { return false; } @@ -140,8 +141,8 @@ Value* Value::DeepCopy() const { return CreateNullValue().release(); } -scoped_ptr<Value> Value::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr<Value> Value::CreateDeepCopy() const { + return WrapUnique(DeepCopy()); } bool Value::Equals(const Value* other) const { @@ -298,7 +299,7 @@ BinaryValue::BinaryValue() size_(0) { } -BinaryValue::BinaryValue(scoped_ptr<char[]> buffer, size_t size) +BinaryValue::BinaryValue(std::unique_ptr<char[]> buffer, size_t size) : Value(TYPE_BINARY), buffer_(std::move(buffer)), size_(size) {} BinaryValue::~BinaryValue() { @@ -309,7 +310,7 @@ BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, size_t size) { char* buffer_copy = new char[size]; memcpy(buffer_copy, buffer, size); - scoped_ptr<char[]> scoped_buffer_copy(buffer_copy); + std::unique_ptr<char[]> scoped_buffer_copy(buffer_copy); return new BinaryValue(std::move(scoped_buffer_copy), size); } @@ -335,11 +336,12 @@ bool BinaryValue::Equals(const Value* other) const { ///////////////////// DictionaryValue //////////////////// // static -scoped_ptr<DictionaryValue> DictionaryValue::From(scoped_ptr<Value> value) { +std::unique_ptr<DictionaryValue> DictionaryValue::From( + std::unique_ptr<Value> value) { DictionaryValue* out; if (value && value->GetAsDictionary(&out)) { ignore_result(value.release()); - return make_scoped_ptr(out); + return WrapUnique(out); } return nullptr; } @@ -381,7 +383,8 @@ void DictionaryValue::Clear() { dictionary_.clear(); } -void DictionaryValue::Set(const std::string& path, scoped_ptr<Value> in_value) { +void DictionaryValue::Set(const std::string& path, + std::unique_ptr<Value> in_value) { DCHECK(IsStringUTF8(path)); DCHECK(in_value); @@ -407,7 +410,7 @@ void DictionaryValue::Set(const std::string& path, scoped_ptr<Value> in_value) { } void DictionaryValue::Set(const std::string& path, Value* in_value) { - Set(path, make_scoped_ptr(in_value)); + Set(path, WrapUnique(in_value)); } void DictionaryValue::SetBoolean(const std::string& path, bool in_value) { @@ -428,7 +431,7 @@ void DictionaryValue::SetString(const std::string& path, } void DictionaryValue::SetWithoutPathExpansion(const std::string& key, - scoped_ptr<Value> in_value) { + std::unique_ptr<Value> in_value) { Value* bare_ptr = in_value.release(); // If there's an existing value here, we need to delete it, because // we own all our children. @@ -443,7 +446,7 @@ void DictionaryValue::SetWithoutPathExpansion(const std::string& key, void DictionaryValue::SetWithoutPathExpansion(const std::string& key, Value* in_value) { - SetWithoutPathExpansion(key, make_scoped_ptr(in_value)); + SetWithoutPathExpansion(key, WrapUnique(in_value)); } void DictionaryValue::SetBooleanWithoutPathExpansion( @@ -709,7 +712,7 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, } bool DictionaryValue::Remove(const std::string& path, - scoped_ptr<Value>* out_value) { + std::unique_ptr<Value>* out_value) { DCHECK(IsStringUTF8(path)); std::string current_path(path); DictionaryValue* current_dictionary = this; @@ -725,8 +728,9 @@ bool DictionaryValue::Remove(const std::string& path, out_value); } -bool DictionaryValue::RemoveWithoutPathExpansion(const std::string& key, - scoped_ptr<Value>* out_value) { +bool DictionaryValue::RemoveWithoutPathExpansion( + const std::string& key, + std::unique_ptr<Value>* out_value) { DCHECK(IsStringUTF8(key)); ValueMap::iterator entry_iterator = dictionary_.find(key); if (entry_iterator == dictionary_.end()) @@ -742,7 +746,7 @@ bool DictionaryValue::RemoveWithoutPathExpansion(const std::string& key, } bool DictionaryValue::RemovePath(const std::string& path, - scoped_ptr<Value>* out_value) { + std::unique_ptr<Value>* out_value) { bool result = false; size_t delimiter_position = path.find('.'); @@ -761,9 +765,10 @@ bool DictionaryValue::RemovePath(const std::string& path, return result; } -scoped_ptr<DictionaryValue> DictionaryValue::DeepCopyWithoutEmptyChildren() +std::unique_ptr<DictionaryValue> DictionaryValue::DeepCopyWithoutEmptyChildren() const { - scoped_ptr<DictionaryValue> copy = CopyDictionaryWithoutEmptyChildren(*this); + std::unique_ptr<DictionaryValue> copy = + CopyDictionaryWithoutEmptyChildren(*this); if (!copy) copy.reset(new DictionaryValue); return copy; @@ -810,8 +815,8 @@ DictionaryValue* DictionaryValue::DeepCopy() const { return result; } -scoped_ptr<DictionaryValue> DictionaryValue::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr<DictionaryValue> DictionaryValue::CreateDeepCopy() const { + return WrapUnique(DeepCopy()); } bool DictionaryValue::Equals(const Value* other) const { @@ -839,11 +844,11 @@ bool DictionaryValue::Equals(const Value* other) const { ///////////////////// ListValue //////////////////// // static -scoped_ptr<ListValue> ListValue::From(scoped_ptr<Value> value) { +std::unique_ptr<ListValue> ListValue::From(std::unique_ptr<Value> value) { ListValue* out; if (value && value->GetAsList(&out)) { ignore_result(value.release()); - return make_scoped_ptr(out); + return WrapUnique(out); } return nullptr; } @@ -878,7 +883,7 @@ bool ListValue::Set(size_t index, Value* in_value) { return true; } -bool ListValue::Set(size_t index, scoped_ptr<Value> in_value) { +bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) { return Set(index, in_value.release()); } @@ -985,7 +990,7 @@ bool ListValue::GetList(size_t index, ListValue** out_value) { const_cast<const ListValue**>(out_value)); } -bool ListValue::Remove(size_t index, scoped_ptr<Value>* out_value) { +bool ListValue::Remove(size_t index, std::unique_ptr<Value>* out_value) { if (index >= list_.size()) return false; @@ -1014,7 +1019,7 @@ bool ListValue::Remove(const Value& value, size_t* index) { } ListValue::iterator ListValue::Erase(iterator iter, - scoped_ptr<Value>* out_value) { + std::unique_ptr<Value>* out_value) { if (out_value) out_value->reset(*iter); else @@ -1023,7 +1028,7 @@ ListValue::iterator ListValue::Erase(iterator iter, return list_.erase(iter); } -void ListValue::Append(scoped_ptr<Value> in_value) { +void ListValue::Append(std::unique_ptr<Value> in_value) { Append(in_value.release()); } @@ -1105,8 +1110,8 @@ ListValue* ListValue::DeepCopy() const { return result; } -scoped_ptr<ListValue> ListValue::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr<ListValue> ListValue::CreateDeepCopy() const { + return WrapUnique(DeepCopy()); } bool ListValue::Equals(const Value* other) const { diff --git a/third_party/chromium/base/values.h b/third_party/chromium/base/values.h index 36e24cc..fca5239 100644 --- a/third_party/chromium/base/values.h +++ b/third_party/chromium/base/values.h @@ -22,6 +22,7 @@ #include <iosfwd> #include <map> +#include <memory> #include <string> #include <utility> #include <vector> @@ -29,7 +30,6 @@ #include "base/base_export.h" #include "base/compiler_specific.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/string_piece.h" namespace base { @@ -65,7 +65,7 @@ class BASE_EXPORT Value { virtual ~Value(); - static scoped_ptr<Value> CreateNullValue(); + static std::unique_ptr<Value> CreateNullValue(); // Returns the type of the value stored by the current Value object. // Each type will be implemented by only one subclass of Value, so it's @@ -100,7 +100,7 @@ class BASE_EXPORT Value { // this works because C++ supports covariant return types. virtual Value* DeepCopy() const; // Preferred version of DeepCopy. TODO(estade): remove the above. - scoped_ptr<Value> CreateDeepCopy() const; + std::unique_ptr<Value> CreateDeepCopy() const; // Compares if two Value objects have equal contents. virtual bool Equals(const Value* other) const; @@ -172,7 +172,7 @@ class BASE_EXPORT BinaryValue : public Value { // Creates a BinaryValue, taking ownership of the bytes pointed to by // |buffer|. - BinaryValue(scoped_ptr<char[]> buffer, size_t size); + BinaryValue(std::unique_ptr<char[]> buffer, size_t size); ~BinaryValue() override; @@ -193,7 +193,7 @@ class BASE_EXPORT BinaryValue : public Value { bool Equals(const Value* other) const override; private: - scoped_ptr<char[]> buffer_; + std::unique_ptr<char[]> buffer_; size_t size_; DISALLOW_COPY_AND_ASSIGN(BinaryValue); @@ -205,7 +205,7 @@ class BASE_EXPORT BinaryValue : public Value { class BASE_EXPORT DictionaryValue : public Value { public: // Returns |value| if it is a dictionary, nullptr otherwise. - static scoped_ptr<DictionaryValue> From(scoped_ptr<Value> value); + static std::unique_ptr<DictionaryValue> From(std::unique_ptr<Value> value); DictionaryValue(); ~DictionaryValue() override; @@ -233,7 +233,7 @@ class BASE_EXPORT DictionaryValue : public Value { // If the key at any step of the way doesn't exist, or exists but isn't // a DictionaryValue, a new DictionaryValue will be created and attached // to the path in that location. |in_value| must be non-null. - void Set(const std::string& path, scoped_ptr<Value> in_value); + void Set(const std::string& path, std::unique_ptr<Value> in_value); // Deprecated version of the above. TODO(estade): remove. void Set(const std::string& path, Value* in_value); @@ -247,7 +247,7 @@ class BASE_EXPORT DictionaryValue : public Value { // Like Set(), but without special treatment of '.'. This allows e.g. URLs to // be used as paths. void SetWithoutPathExpansion(const std::string& key, - scoped_ptr<Value> in_value); + std::unique_ptr<Value> in_value); // Deprecated version of the above. TODO(estade): remove. void SetWithoutPathExpansion(const std::string& key, Value* in_value); @@ -317,21 +317,22 @@ class BASE_EXPORT DictionaryValue : public Value { // |out_value|. If |out_value| is NULL, the removed value will be deleted. // This method returns true if |path| is a valid path; otherwise it will // return false and the DictionaryValue object will be unchanged. - virtual bool Remove(const std::string& path, scoped_ptr<Value>* out_value); + virtual bool Remove(const std::string& path, + std::unique_ptr<Value>* out_value); // Like Remove(), but without special treatment of '.'. This allows e.g. URLs // to be used as paths. virtual bool RemoveWithoutPathExpansion(const std::string& key, - scoped_ptr<Value>* out_value); + std::unique_ptr<Value>* out_value); // Removes a path, clearing out all dictionaries on |path| that remain empty // after removing the value at |path|. virtual bool RemovePath(const std::string& path, - scoped_ptr<Value>* out_value); + std::unique_ptr<Value>* out_value); // Makes a copy of |this| but doesn't include empty dictionaries and lists in // the copy. This never returns NULL, even if |this| itself is empty. - scoped_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const; + std::unique_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const; // Merge |dictionary| into this dictionary. This is done recursively, i.e. any // sub-dictionaries will be merged as well. In case of key collisions, the @@ -365,7 +366,7 @@ class BASE_EXPORT DictionaryValue : public Value { // Overridden from Value: DictionaryValue* DeepCopy() const override; // Preferred version of DeepCopy. TODO(estade): remove the above. - scoped_ptr<DictionaryValue> CreateDeepCopy() const; + std::unique_ptr<DictionaryValue> CreateDeepCopy() const; bool Equals(const Value* other) const override; private: @@ -381,7 +382,7 @@ class BASE_EXPORT ListValue : public Value { typedef ValueVector::const_iterator const_iterator; // Returns |value| if it is a list, nullptr otherwise. - static scoped_ptr<ListValue> From(scoped_ptr<Value> value); + static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); ListValue(); ~ListValue() override; @@ -402,7 +403,7 @@ class BASE_EXPORT ListValue : public Value { // the value is a null pointer. bool Set(size_t index, Value* in_value); // Preferred version of the above. TODO(estade): remove the above. - bool Set(size_t index, scoped_ptr<Value> in_value); + bool Set(size_t index, std::unique_ptr<Value> in_value); // Gets the Value at the given index. Modifies |out_value| (and returns true) // only if the index falls within the current list range. @@ -433,7 +434,7 @@ class BASE_EXPORT ListValue : public Value { // passed out via |out_value|. If |out_value| is NULL, the removed value will // be deleted. This method returns true if |index| is valid; otherwise // it will return false and the ListValue object will be unchanged. - virtual bool Remove(size_t index, scoped_ptr<Value>* out_value); + virtual bool Remove(size_t index, std::unique_ptr<Value>* out_value); // Removes the first instance of |value| found in the list, if any, and // deletes it. |index| is the location where |value| was found. Returns false @@ -444,10 +445,10 @@ class BASE_EXPORT ListValue : public Value { // deleted, otherwise ownership of the value is passed back to the caller. // Returns an iterator pointing to the location of the element that // followed the erased element. - iterator Erase(iterator iter, scoped_ptr<Value>* out_value); + iterator Erase(iterator iter, std::unique_ptr<Value>* out_value); // Appends a Value to the end of the list. - void Append(scoped_ptr<Value> in_value); + void Append(std::unique_ptr<Value> in_value); // Deprecated version of the above. TODO(estade): remove. void Append(Value* in_value); @@ -489,7 +490,7 @@ class BASE_EXPORT ListValue : public Value { bool Equals(const Value* other) const override; // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. - scoped_ptr<ListValue> CreateDeepCopy() const; + std::unique_ptr<ListValue> CreateDeepCopy() const; private: ValueVector list_; diff --git a/third_party/chromium/base/values_unittest.cc b/third_party/chromium/base/values_unittest.cc index b5e47dd..5e49446 100644 --- a/third_party/chromium/base/values_unittest.cc +++ b/third_party/chromium/base/values_unittest.cc @@ -2,16 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/values.h" + #include <stddef.h> #include <limits> +#include <memory> #include <utility> #include <gtest/gtest.h> -#include "base/memory/scoped_ptr.h" +#include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversion_utils.h" -#include "base/values.h" namespace base { @@ -36,11 +38,11 @@ TEST(ValuesTest, Basic) { ASSERT_FALSE( settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); - scoped_ptr<ListValue> new_toolbar_bookmarks(new ListValue); + std::unique_ptr<ListValue> new_toolbar_bookmarks(new ListValue); settings.Set("global.toolbar.bookmarks", std::move(new_toolbar_bookmarks)); ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); - scoped_ptr<DictionaryValue> new_bookmark(new DictionaryValue); + std::unique_ptr<DictionaryValue> new_bookmark(new DictionaryValue); new_bookmark->SetString("name", "Froogle"); new_bookmark->SetString("url", "http://froogle.com"); toolbar_bookmarks->Append(std::move(new_bookmark)); @@ -59,11 +61,11 @@ TEST(ValuesTest, Basic) { } TEST(ValuesTest, List) { - scoped_ptr<ListValue> mixed_list(new ListValue()); - mixed_list->Set(0, make_scoped_ptr(new FundamentalValue(true))); - mixed_list->Set(1, make_scoped_ptr(new FundamentalValue(42))); - mixed_list->Set(2, make_scoped_ptr(new FundamentalValue(88.8))); - mixed_list->Set(3, make_scoped_ptr(new StringValue("foo"))); + std::unique_ptr<ListValue> mixed_list(new ListValue()); + mixed_list->Set(0, WrapUnique(new FundamentalValue(true))); + mixed_list->Set(1, WrapUnique(new FundamentalValue(42))); + mixed_list->Set(2, WrapUnique(new FundamentalValue(88.8))); + mixed_list->Set(3, WrapUnique(new StringValue("foo"))); ASSERT_EQ(4u, mixed_list->GetSize()); Value *value = NULL; @@ -109,13 +111,13 @@ TEST(ValuesTest, List) { TEST(ValuesTest, BinaryValue) { // Default constructor creates a BinaryValue with a null buffer and size 0. - scoped_ptr<BinaryValue> binary(new BinaryValue()); + std::unique_ptr<BinaryValue> binary(new BinaryValue()); ASSERT_TRUE(binary.get()); ASSERT_EQ(NULL, binary->GetBuffer()); ASSERT_EQ(0U, binary->GetSize()); // Test the common case of a non-empty buffer - scoped_ptr<char[]> buffer(new char[15]); + std::unique_ptr<char[]> buffer(new char[15]); char* original_buffer = buffer.get(); binary.reset(new BinaryValue(std::move(buffer), 15)); ASSERT_TRUE(binary.get()); @@ -141,7 +143,7 @@ TEST(ValuesTest, BinaryValue) { TEST(ValuesTest, StringValue) { // Test overloaded StringValue constructor. - scoped_ptr<Value> narrow_value(new StringValue("narrow")); + std::unique_ptr<Value> narrow_value(new StringValue("narrow")); ASSERT_TRUE(narrow_value.get()); ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); @@ -184,14 +186,14 @@ TEST(ValuesTest, ListDeletion) { { ListValue list; - list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + list.Append(WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); } EXPECT_TRUE(deletion_flag); { ListValue list; - list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + list.Append(WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); list.Clear(); EXPECT_TRUE(deletion_flag); @@ -199,7 +201,7 @@ TEST(ValuesTest, ListDeletion) { { ListValue list; - list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + list.Append(WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); EXPECT_TRUE(deletion_flag); @@ -208,11 +210,11 @@ TEST(ValuesTest, ListDeletion) { TEST(ValuesTest, ListRemoval) { bool deletion_flag = true; - scoped_ptr<Value> removed_item; + std::unique_ptr<Value> removed_item; { ListValue list; - list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + list.Append(WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); EXPECT_EQ(1U, list.GetSize()); EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), @@ -228,7 +230,7 @@ TEST(ValuesTest, ListRemoval) { { ListValue list; - list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + list.Append(WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); EXPECT_TRUE(list.Remove(0, NULL)); EXPECT_TRUE(deletion_flag); @@ -237,7 +239,8 @@ TEST(ValuesTest, ListRemoval) { { ListValue list; - scoped_ptr<DeletionTestValue> value(new DeletionTestValue(&deletion_flag)); + std::unique_ptr<DeletionTestValue> value( + new DeletionTestValue(&deletion_flag)); DeletionTestValue* original_value = value.get(); list.Append(std::move(value)); EXPECT_FALSE(deletion_flag); @@ -255,14 +258,14 @@ TEST(ValuesTest, DictionaryDeletion) { { DictionaryValue dict; - dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); } EXPECT_TRUE(deletion_flag); { DictionaryValue dict; - dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); dict.Clear(); EXPECT_TRUE(deletion_flag); @@ -270,7 +273,7 @@ TEST(ValuesTest, DictionaryDeletion) { { DictionaryValue dict; - dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); dict.Set(key, Value::CreateNullValue()); EXPECT_TRUE(deletion_flag); @@ -280,11 +283,11 @@ TEST(ValuesTest, DictionaryDeletion) { TEST(ValuesTest, DictionaryRemoval) { std::string key = "test"; bool deletion_flag = true; - scoped_ptr<Value> removed_item; + std::unique_ptr<Value> removed_item; { DictionaryValue dict; - dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); EXPECT_TRUE(dict.HasKey(key)); EXPECT_FALSE(dict.Remove("absent key", &removed_item)); @@ -298,7 +301,7 @@ TEST(ValuesTest, DictionaryRemoval) { { DictionaryValue dict; - dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); + dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag))); EXPECT_FALSE(deletion_flag); EXPECT_TRUE(dict.HasKey(key)); EXPECT_TRUE(dict.Remove(key, NULL)); @@ -358,7 +361,7 @@ TEST(ValuesTest, DictionaryRemovePath) { dict.SetInteger("a.long.way.down", 1); dict.SetBoolean("a.long.key.path", true); - scoped_ptr<Value> removed_item; + std::unique_ptr<Value> removed_item; EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item)); ASSERT_TRUE(removed_item); EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER)); @@ -380,45 +383,48 @@ TEST(ValuesTest, DictionaryRemovePath) { TEST(ValuesTest, DeepCopy) { DictionaryValue original_dict; - scoped_ptr<Value> scoped_null = Value::CreateNullValue(); + std::unique_ptr<Value> scoped_null = Value::CreateNullValue(); Value* original_null = scoped_null.get(); original_dict.Set("null", std::move(scoped_null)); - scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); + std::unique_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); FundamentalValue* original_bool = scoped_bool.get(); original_dict.Set("bool", std::move(scoped_bool)); - scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); + std::unique_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); FundamentalValue* original_int = scoped_int.get(); original_dict.Set("int", std::move(scoped_int)); - scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); + std::unique_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); FundamentalValue* original_double = scoped_double.get(); original_dict.Set("double", std::move(scoped_double)); - scoped_ptr<StringValue> scoped_string(new StringValue("hello")); + std::unique_ptr<StringValue> scoped_string(new StringValue("hello")); StringValue* original_string = scoped_string.get(); original_dict.Set("string", std::move(scoped_string)); - scoped_ptr<char[]> original_buffer(new char[42]); + std::unique_ptr<char[]> original_buffer(new char[42]); memset(original_buffer.get(), '!', 42); - scoped_ptr<BinaryValue> scoped_binary( + std::unique_ptr<BinaryValue> scoped_binary( new BinaryValue(std::move(original_buffer), 42)); BinaryValue* original_binary = scoped_binary.get(); original_dict.Set("binary", std::move(scoped_binary)); - scoped_ptr<ListValue> scoped_list(new ListValue()); + std::unique_ptr<ListValue> scoped_list(new ListValue()); Value* original_list = scoped_list.get(); - scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); + std::unique_ptr<FundamentalValue> scoped_list_element_0( + new FundamentalValue(0)); Value* original_list_element_0 = scoped_list_element_0.get(); scoped_list->Append(std::move(scoped_list_element_0)); - scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); + std::unique_ptr<FundamentalValue> scoped_list_element_1( + new FundamentalValue(1)); Value* original_list_element_1 = scoped_list_element_1.get(); scoped_list->Append(std::move(scoped_list_element_1)); original_dict.Set("list", std::move(scoped_list)); - scoped_ptr<DictionaryValue> scoped_nested_dictionary(new DictionaryValue()); + std::unique_ptr<DictionaryValue> scoped_nested_dictionary( + new DictionaryValue()); Value* original_nested_dictionary = scoped_nested_dictionary.get(); scoped_nested_dictionary->SetString("key", "value"); original_dict.Set("dictionary", std::move(scoped_nested_dictionary)); - scoped_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy(); + std::unique_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy(); ASSERT_TRUE(copy_dict.get()); ASSERT_NE(copy_dict.get(), &original_dict); @@ -513,8 +519,8 @@ TEST(ValuesTest, DeepCopy) { } TEST(ValuesTest, Equals) { - scoped_ptr<Value> null1(Value::CreateNullValue()); - scoped_ptr<Value> null2(Value::CreateNullValue()); + std::unique_ptr<Value> null1(Value::CreateNullValue()); + std::unique_ptr<Value> null2(Value::CreateNullValue()); EXPECT_NE(null1.get(), null2.get()); EXPECT_TRUE(null1->Equals(null2.get())); @@ -528,21 +534,21 @@ TEST(ValuesTest, Equals) { dv.SetString("d1", "string"); dv.Set("e", Value::CreateNullValue()); - scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); + std::unique_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); EXPECT_TRUE(dv.Equals(copy.get())); - scoped_ptr<ListValue> list(new ListValue); + std::unique_ptr<ListValue> list(new ListValue); ListValue* original_list = list.get(); list->Append(Value::CreateNullValue()); - list->Append(make_scoped_ptr(new DictionaryValue)); - scoped_ptr<Value> list_copy(list->CreateDeepCopy()); + list->Append(WrapUnique(new DictionaryValue)); + std::unique_ptr<Value> list_copy(list->CreateDeepCopy()); dv.Set("f", std::move(list)); EXPECT_FALSE(dv.Equals(copy.get())); copy->Set("f", std::move(list_copy)); EXPECT_TRUE(dv.Equals(copy.get())); - original_list->Append(make_scoped_ptr(new FundamentalValue(true))); + original_list->Append(WrapUnique(new FundamentalValue(true))); EXPECT_FALSE(dv.Equals(copy.get())); // Check if Equals detects differences in only the keys. @@ -554,14 +560,14 @@ TEST(ValuesTest, Equals) { } TEST(ValuesTest, StaticEquals) { - scoped_ptr<Value> null1(Value::CreateNullValue()); - scoped_ptr<Value> null2(Value::CreateNullValue()); + std::unique_ptr<Value> null1(Value::CreateNullValue()); + std::unique_ptr<Value> null2(Value::CreateNullValue()); EXPECT_TRUE(Value::Equals(null1.get(), null2.get())); EXPECT_TRUE(Value::Equals(NULL, NULL)); - scoped_ptr<Value> i42(new FundamentalValue(42)); - scoped_ptr<Value> j42(new FundamentalValue(42)); - scoped_ptr<Value> i17(new FundamentalValue(17)); + std::unique_ptr<Value> i42(new FundamentalValue(42)); + std::unique_ptr<Value> j42(new FundamentalValue(42)); + std::unique_ptr<Value> i17(new FundamentalValue(17)); EXPECT_TRUE(Value::Equals(i42.get(), i42.get())); EXPECT_TRUE(Value::Equals(j42.get(), i42.get())); EXPECT_TRUE(Value::Equals(i42.get(), j42.get())); @@ -578,45 +584,47 @@ TEST(ValuesTest, StaticEquals) { TEST(ValuesTest, DeepCopyCovariantReturnTypes) { DictionaryValue original_dict; - scoped_ptr<Value> scoped_null(Value::CreateNullValue()); + std::unique_ptr<Value> scoped_null(Value::CreateNullValue()); Value* original_null = scoped_null.get(); original_dict.Set("null", std::move(scoped_null)); - scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); + std::unique_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); Value* original_bool = scoped_bool.get(); original_dict.Set("bool", std::move(scoped_bool)); - scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); + std::unique_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); Value* original_int = scoped_int.get(); original_dict.Set("int", std::move(scoped_int)); - scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); + std::unique_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); Value* original_double = scoped_double.get(); original_dict.Set("double", std::move(scoped_double)); - scoped_ptr<StringValue> scoped_string(new StringValue("hello")); + std::unique_ptr<StringValue> scoped_string(new StringValue("hello")); Value* original_string = scoped_string.get(); original_dict.Set("string", std::move(scoped_string)); - scoped_ptr<char[]> original_buffer(new char[42]); + std::unique_ptr<char[]> original_buffer(new char[42]); memset(original_buffer.get(), '!', 42); - scoped_ptr<BinaryValue> scoped_binary( + std::unique_ptr<BinaryValue> scoped_binary( new BinaryValue(std::move(original_buffer), 42)); Value* original_binary = scoped_binary.get(); original_dict.Set("binary", std::move(scoped_binary)); - scoped_ptr<ListValue> scoped_list(new ListValue()); + std::unique_ptr<ListValue> scoped_list(new ListValue()); Value* original_list = scoped_list.get(); - scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); + std::unique_ptr<FundamentalValue> scoped_list_element_0( + new FundamentalValue(0)); scoped_list->Append(std::move(scoped_list_element_0)); - scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); + std::unique_ptr<FundamentalValue> scoped_list_element_1( + new FundamentalValue(1)); scoped_list->Append(std::move(scoped_list_element_1)); original_dict.Set("list", std::move(scoped_list)); - scoped_ptr<Value> copy_dict = original_dict.CreateDeepCopy(); - scoped_ptr<Value> copy_null = original_null->CreateDeepCopy(); - scoped_ptr<Value> copy_bool = original_bool->CreateDeepCopy(); - scoped_ptr<Value> copy_int = original_int->CreateDeepCopy(); - scoped_ptr<Value> copy_double = original_double->CreateDeepCopy(); - scoped_ptr<Value> copy_string = original_string->CreateDeepCopy(); - scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy(); - scoped_ptr<Value> copy_list = original_list->CreateDeepCopy(); + std::unique_ptr<Value> copy_dict = original_dict.CreateDeepCopy(); + std::unique_ptr<Value> copy_null = original_null->CreateDeepCopy(); + std::unique_ptr<Value> copy_bool = original_bool->CreateDeepCopy(); + std::unique_ptr<Value> copy_int = original_int->CreateDeepCopy(); + std::unique_ptr<Value> copy_double = original_double->CreateDeepCopy(); + std::unique_ptr<Value> copy_string = original_string->CreateDeepCopy(); + std::unique_ptr<Value> copy_binary = original_binary->CreateDeepCopy(); + std::unique_ptr<Value> copy_list = original_list->CreateDeepCopy(); EXPECT_TRUE(original_dict.Equals(copy_dict.get())); EXPECT_TRUE(original_null->Equals(copy_null.get())); @@ -629,18 +637,18 @@ TEST(ValuesTest, DeepCopyCovariantReturnTypes) { } TEST(ValuesTest, RemoveEmptyChildren) { - scoped_ptr<DictionaryValue> root(new DictionaryValue); + std::unique_ptr<DictionaryValue> root(new DictionaryValue); // Remove empty lists and dictionaries. - root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); - root->Set("empty_list", make_scoped_ptr(new ListValue)); + root->Set("empty_dict", WrapUnique(new DictionaryValue)); + root->Set("empty_list", WrapUnique(new ListValue)); root->SetWithoutPathExpansion("a.b.c.d.e", - make_scoped_ptr(new DictionaryValue)); + WrapUnique(new DictionaryValue)); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_TRUE(root->empty()); // Make sure we don't prune too much. root->SetBoolean("bool", true); - root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); + root->Set("empty_dict", WrapUnique(new DictionaryValue)); root->SetString("empty_string", std::string()); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_EQ(2U, root->size()); @@ -652,22 +660,22 @@ TEST(ValuesTest, RemoveEmptyChildren) { // Nested test cases. These should all reduce back to the bool and string // set above. { - root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); + root->Set("a.b.c.d.e", WrapUnique(new DictionaryValue)); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_EQ(2U, root->size()); } { - scoped_ptr<DictionaryValue> inner(new DictionaryValue); - inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); - inner->Set("empty_list", make_scoped_ptr(new ListValue)); + std::unique_ptr<DictionaryValue> inner(new DictionaryValue); + inner->Set("empty_dict", WrapUnique(new DictionaryValue)); + inner->Set("empty_list", WrapUnique(new ListValue)); root->Set("dict_with_empty_children", std::move(inner)); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_EQ(2U, root->size()); } { - scoped_ptr<ListValue> inner(new ListValue); - inner->Append(make_scoped_ptr(new DictionaryValue)); - inner->Append(make_scoped_ptr(new ListValue)); + std::unique_ptr<ListValue> inner(new ListValue); + inner->Append(WrapUnique(new DictionaryValue)); + inner->Append(WrapUnique(new ListValue)); root->Set("list_with_empty_children", std::move(inner)); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_EQ(2U, root->size()); @@ -675,13 +683,13 @@ TEST(ValuesTest, RemoveEmptyChildren) { // Nested with siblings. { - scoped_ptr<ListValue> inner(new ListValue()); - inner->Append(make_scoped_ptr(new DictionaryValue)); - inner->Append(make_scoped_ptr(new ListValue)); + std::unique_ptr<ListValue> inner(new ListValue()); + inner->Append(WrapUnique(new DictionaryValue)); + inner->Append(WrapUnique(new ListValue)); root->Set("list_with_empty_children", std::move(inner)); - scoped_ptr<DictionaryValue> inner2(new DictionaryValue); - inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); - inner2->Set("empty_list", make_scoped_ptr(new ListValue)); + std::unique_ptr<DictionaryValue> inner2(new DictionaryValue); + inner2->Set("empty_dict", WrapUnique(new DictionaryValue)); + inner2->Set("empty_list", WrapUnique(new ListValue)); root->Set("dict_with_empty_children", std::move(inner2)); root = root->DeepCopyWithoutEmptyChildren(); EXPECT_EQ(2U, root->size()); @@ -689,10 +697,10 @@ TEST(ValuesTest, RemoveEmptyChildren) { // Make sure nested values don't get pruned. { - scoped_ptr<ListValue> inner(new ListValue); - scoped_ptr<ListValue> inner2(new ListValue); - inner2->Append(make_scoped_ptr(new StringValue("hello"))); - inner->Append(make_scoped_ptr(new DictionaryValue)); + std::unique_ptr<ListValue> inner(new ListValue); + std::unique_ptr<ListValue> inner2(new ListValue); + inner2->Append(WrapUnique(new StringValue("hello"))); + inner->Append(WrapUnique(new DictionaryValue)); inner->Append(std::move(inner2)); root->Set("list_with_empty_children", std::move(inner)); root = root->DeepCopyWithoutEmptyChildren(); @@ -707,18 +715,18 @@ TEST(ValuesTest, RemoveEmptyChildren) { } TEST(ValuesTest, MergeDictionary) { - scoped_ptr<DictionaryValue> base(new DictionaryValue); + std::unique_ptr<DictionaryValue> base(new DictionaryValue); base->SetString("base_key", "base_key_value_base"); base->SetString("collide_key", "collide_key_value_base"); - scoped_ptr<DictionaryValue> base_sub_dict(new DictionaryValue); + std::unique_ptr<DictionaryValue> base_sub_dict(new DictionaryValue); base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); base->Set("sub_dict_key", std::move(base_sub_dict)); - scoped_ptr<DictionaryValue> merge(new DictionaryValue); + std::unique_ptr<DictionaryValue> merge(new DictionaryValue); merge->SetString("merge_key", "merge_key_value_merge"); merge->SetString("collide_key", "collide_key_value_merge"); - scoped_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue); + std::unique_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue); merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge"); merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge"); merge->Set("sub_dict_key", std::move(merge_sub_dict)); @@ -752,7 +760,7 @@ TEST(ValuesTest, MergeDictionary) { } TEST(ValuesTest, MergeDictionaryDeepCopy) { - scoped_ptr<DictionaryValue> child(new DictionaryValue); + std::unique_ptr<DictionaryValue> child(new DictionaryValue); DictionaryValue* original_child = child.get(); child->SetString("test", "value"); EXPECT_EQ(1U, child->size()); @@ -761,7 +769,7 @@ TEST(ValuesTest, MergeDictionaryDeepCopy) { EXPECT_TRUE(child->GetString("test", &value)); EXPECT_EQ("value", value); - scoped_ptr<DictionaryValue> base(new DictionaryValue); + std::unique_ptr<DictionaryValue> base(new DictionaryValue); base->Set("dict", std::move(child)); EXPECT_EQ(1U, base->size()); @@ -769,7 +777,7 @@ TEST(ValuesTest, MergeDictionaryDeepCopy) { EXPECT_TRUE(base->GetDictionary("dict", &ptr)); EXPECT_EQ(original_child, ptr); - scoped_ptr<DictionaryValue> merged(new DictionaryValue); + std::unique_ptr<DictionaryValue> merged(new DictionaryValue); merged->MergeDictionary(base.get()); EXPECT_EQ(1U, merged->size()); EXPECT_TRUE(merged->GetDictionary("dict", &ptr)); diff --git a/third_party/chromium/crypto/sha2.cc b/third_party/chromium/crypto/sha2.cc index 7dcef0b..1ab3fe1 100644 --- a/third_party/chromium/crypto/sha2.cc +++ b/third_party/chromium/crypto/sha2.cc @@ -7,8 +7,6 @@ #include <algorithm> #include <openssl/sha.h> -#include <base/memory/scoped_ptr.h> - namespace crypto { void SHA256HashString(const std::string& str, uint8_t* output, size_t len) { |