From 83db8f75afbb37010450a6a5607764dedf20db6b Mon Sep 17 00:00:00 2001 From: Luis Hector Chavez Date: Wed, 1 Jun 2016 20:11:15 +0000 Subject: Reland "Merge remote-tracking branch 'weave/master' into 'weave/aosp-master'" This reverts commit abfe7a063bbaebdca8703d27137c8c9aed826dac. All necessary changes are ready in AOSP for this to land. Change-Id: I9ac99ebbb292e047e6d6a7978e5748987d7f0f9d Reviewed-on: https://weave-review.googlesource.com/3720 Reviewed-by: Alex Vakulenko --- examples/daemon/oven/oven.cc | 290 --------------------- examples/daemon/speaker/speaker.cc | 178 ------------- examples/examples.mk | 12 +- examples/provider/avahi_client.cc | 1 + examples/provider/avahi_client.h | 1 + examples/provider/event_network.h | 2 + examples/provider/event_task_runner.h | 1 + include/weave/provider/test/fake_task_runner.h | 1 + include/weave/settings.h | 2 +- src/access_revocation_manager_impl.cc | 6 +- src/bind_lambda.h | 4 +- src/privet/privet_handler.cc | 3 +- src/privet/privet_handler.h | 1 + src/privet/privet_types.h | 1 + src/streams.h | 2 + tests_schema/daemon/testdevice/standard_traits.h | 30 +++ tests_schema/daemon/testdevice/testdevice.cc | 71 ++++- third_party/chromium/base/bind_unittest.cc | 14 +- third_party/chromium/base/callback_internal.h | 130 +-------- third_party/chromium/base/callback_list.h | 15 +- .../chromium/base/callback_list_unittest.cc | 67 ++--- third_party/chromium/base/callback_unittest.cc | 2 +- third_party/chromium/base/json/json_parser.cc | 82 +++--- third_party/chromium/base/json/json_parser.h | 5 +- .../chromium/base/json/json_parser_unittest.cc | 29 ++- third_party/chromium/base/json/json_reader.cc | 27 +- third_party/chromium/base/json/json_reader.h | 23 +- .../chromium/base/json/json_reader_unittest.cc | 20 +- .../chromium/base/json/json_writer_unittest.cc | 21 +- third_party/chromium/base/memory/ptr_util.h | 74 ++++++ third_party/chromium/base/memory/scoped_ptr.h | 135 ---------- third_party/chromium/base/memory/weak_ptr.h | 24 +- .../chromium/base/memory/weak_ptr_unittest.cc | 27 +- third_party/chromium/base/rand_util_unittest.cc | 2 +- third_party/chromium/base/values.cc | 97 +++---- third_party/chromium/base/values.h | 39 +-- third_party/chromium/base/values_unittest.cc | 202 +++++++------- third_party/chromium/crypto/sha2.cc | 2 - 38 files changed, 553 insertions(+), 1090 deletions(-) delete mode 100644 examples/daemon/oven/oven.cc delete mode 100644 examples/daemon/speaker/speaker.cc create mode 100644 third_party/chromium/base/memory/ptr_util.h delete mode 100644 third_party/chromium/base/memory/scoped_ptr.h diff --git a/examples/daemon/oven/oven.cc b/examples/daemon/oven/oven.cc deleted file mode 100644 index f92c838..0000000 --- a/examples/daemon/oven/oven.cc +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright 2015 The Weave Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "examples/daemon/common/daemon.h" - -#include -#include - -#include -#include - -namespace { -// Time for sensor temperature to match setting temperature -const double kWarmUpTime = 60.0; -// Oven max temp -const double kMaxTemp = 300.0; -// Oven min temp -const double kMinTemp = 20.0; - -const char kTraits[] = R"({ - "temperatureSetting": { - "commands": { - "setConfig": { - "minimalRole": "user", - "parameters": { - "units": { - "type": "string" - }, - "tempSetting": { - "type": "number" - } - }, - "errors": ["tempOutOfRange", "unsupportedUnits"] - } - }, - "state": { - "supportedUnits": { - "type": "array", - "items": { - "type": "string", - "enum": [ "celsius", "fahrenheit", "kelvin" ] - }, - "minItems": 1, - "uniqueItems": true, - "isRequired": true - }, - "units": { - "type": "string", - "enum": [ "celsius", "fahrenheit", "kelvin" ], - "isRequired": true - }, - "tempSetting": { - "type": "number", - "isRequired": true - }, - "maxTempSetting": { - "type": "number", - "isRequired": true - }, - "minTempSetting": { - "type": "number", - "isRequired": true - } - } - }, - "temperatureSensor": { - "commands": { - "setConfig": { - "minimalRole": "user", - "parameters": { - "units": { - "type": "string" - } - }, - "errors": ["unsupportedUnits"] - } - }, - "state": { - "supportedUnits": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "celsius", - "fahrenheit", - "kelvin" - ] - }, - "minItems": 1, - "uniqueItems": true, - "isRequired": true - }, - "units": { - "type": "string", - "enum": [ "celsius", "fahrenheit", "kelvin" ], - "isRequired": true - }, - "value": { - "type": "number", - "isRequired": true - } - } - }, - "brightness": { - "commands": { - "setConfig": { - "minimalRole": "user", - "parameters": { - "brightness": { - "type": "integer", - "minimum": 0, - "maximum": 100 - } - } - } - }, - "state": { - "brightness": { - "type": "integer", - "isRequired": true, - "minimum": 0, - "maximum": 100 - } - } - } -})"; - -const char kComponent[] = "oven"; -} // anonymous namespace - -// OvenHandler is a virtual oven example -// It implements the following commands from traits: -// - temperatureSetting: sets the temperature for the oven -// - brightness: sets the brightness of the oven light -// It exposes the following states from traits: -// - temperatureSetting: temperature setting for the oven -// - temperatureSensor: current oven temperature -// - brightness: current oven brightness -class OvenHandler { - public: - OvenHandler(weave::provider::TaskRunner* task_runner) - : task_runner_{task_runner} {} - - void Register(weave::Device* device) { - device_ = device; - - device->AddTraitDefinitionsFromJson(kTraits); - CHECK(device->AddComponent( - kComponent, {"temperatureSetting", "temperatureSensor", "brightness"}, - nullptr)); - - UpdateOvenState(); - - device->AddCommandHandler(kComponent, "temperatureSetting.setConfig", - base::Bind(&OvenHandler::OnSetTempCommand, - weak_ptr_factory_.GetWeakPtr())); - - device->AddCommandHandler(kComponent, "brightness.setConfig", - base::Bind(&OvenHandler::OnSetBrightnessCommand, - weak_ptr_factory_.GetWeakPtr())); - } - - private: - void OnSetTempCommand(const std::weak_ptr& command) { - auto cmd = command.lock(); - if (!cmd) - return; - LOG(INFO) << "received command: " << cmd->GetName(); - - const auto& params = cmd->GetParameters(); - std::string units; - double temp; - - if (params.GetString("units", &units) && - params.GetDouble("tempSetting", &temp)) { - units_ = units; - target_temperature_ = temp; - - UpdateOvenState(); - - cmd->Complete({}, nullptr); - LOG(INFO) << cmd->GetName() << " updated oven, matching temp"; - - if (target_temperature_ != current_temperature_ && !is_match_ticking_) { - double tickIncrement = - ((target_temperature_ - current_temperature_) / kWarmUpTime); - DoTick(tickIncrement); - } - return; - } - - weave::ErrorPtr error; - weave::Error::AddTo(&error, FROM_HERE, "invalid_parameter_value", - "Invalid parameters"); - cmd->Abort(error.get(), nullptr); - } - - void OnSetBrightnessCommand(const std::weak_ptr& command) { - auto cmd = command.lock(); - if (!cmd) - return; - LOG(INFO) << "received command: " << cmd->GetName(); - - const auto& params = cmd->GetParameters(); - - int brightness; - if (params.GetInteger("brightness", &brightness)) { - brightness_ = brightness; - - UpdateOvenState(); - - cmd->Complete({}, nullptr); - return; - } - - weave::ErrorPtr error; - weave::Error::AddTo(&error, FROM_HERE, "invalid_parameter_value", - "Invalid parameters"); - cmd->Abort(error.get(), nullptr); - } - - void UpdateOvenState() { - base::DictionaryValue state; - base::ListValue supportedUnits; - supportedUnits.AppendStrings({"celsius"}); - - state.SetString("temperatureSensor.units", units_); - state.SetDouble("temperatureSensor.value", current_temperature_); - state.Set("temperatureSensor.supportedUnits", - supportedUnits.CreateDeepCopy()); - - state.SetString("temperatureSetting.units", units_); - state.SetDouble("temperatureSetting.tempSetting", target_temperature_); - state.Set("temperatureSetting.supportedUnits", - supportedUnits.CreateDeepCopy()); - state.SetDouble("temperatureSetting.maxTempSetting", kMaxTemp); - state.SetDouble("temperatureSetting.minTempSetting", kMinTemp); - - state.SetInteger("brightness.brightness", brightness_); - - device_->SetStateProperties(kComponent, state, nullptr); - } - - void DoTick(double tickIncrement) { - LOG(INFO) << "Oven matching temp tick"; - - if (std::fabs(target_temperature_ - current_temperature_) >= - tickIncrement) { - is_match_ticking_ = true; - current_temperature_ += tickIncrement; - UpdateOvenState(); - task_runner_->PostDelayedTask( - FROM_HERE, base::Bind(&OvenHandler::DoTick, - weak_ptr_factory_.GetWeakPtr(), tickIncrement), - base::TimeDelta::FromSeconds(1)); - return; - } - - is_match_ticking_ = false; - current_temperature_ = target_temperature_; - UpdateOvenState(); - - LOG(INFO) << "Oven temp matched"; - } - - weave::Device* device_{nullptr}; - weave::provider::TaskRunner* task_runner_{nullptr}; - - std::string units_ = "celsius"; - double target_temperature_ = 0.0; - double current_temperature_ = 0.0; - int brightness_ = 0; - bool is_match_ticking_ = false; - - base::WeakPtrFactory weak_ptr_factory_{this}; -}; - -int main(int argc, char** argv) { - Daemon::Options opts; - if (!opts.Parse(argc, argv)) { - Daemon::Options::ShowUsage(argv[0]); - return 1; - } - Daemon daemon{opts}; - OvenHandler handler{daemon.GetTaskRunner()}; - handler.Register(daemon.GetDevice()); - daemon.Run(); - return 0; -} diff --git a/examples/daemon/speaker/speaker.cc b/examples/daemon/speaker/speaker.cc deleted file mode 100644 index 56da840..0000000 --- a/examples/daemon/speaker/speaker.cc +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2015 The Weave Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "examples/daemon/common/daemon.h" - -#include - -#include -#include - -namespace { - -const char kTraits[] = R"({ - "onOff": { - "commands": { - "setConfig": { - "minimalRole": "user", - "parameters": { - "state": { - "type": "string", - "enum": [ "on", "off" ] - } - } - } - }, - "state": { - "state": { - "type": "string", - "enum": [ "on", "off" ], - "isRequired": true - } - } - }, - "volume": { - "commands": { - "setConfig": { - "minimalRole": "user", - "parameters": { - "volume": { - "type": "integer", - "minimum": 0, - "maximum": 100 - }, - "isMuted": { "type": "boolean" } - } - } - }, - "state": { - "isMuted": { - "type": "boolean", - "isRequired": true - }, - "volume": { - "type": "integer", - "minimum": 0, - "maximum": 100, - "isRequired": true - } - } - } -})"; - -const char kComponent[] = "speaker"; - -} // anonymous namespace - -// SpeakerHandler is a command handler example that shows -// how to handle commands for a Weave speaker. -class SpeakerHandler { - public: - SpeakerHandler() = default; - void Register(weave::Device* device) { - device_ = device; - - device->AddTraitDefinitionsFromJson(kTraits); - CHECK(device->AddComponent(kComponent, {"onOff", "volume"}, nullptr)); - UpdateSpeakerState(); - - device->AddCommandHandler(kComponent, "onOff.setConfig", - base::Bind(&SpeakerHandler::OnOnOffSetConfig, - weak_ptr_factory_.GetWeakPtr())); - device->AddCommandHandler(kComponent, "volume.setConfig", - base::Bind(&SpeakerHandler::OnVolumeSetConfig, - weak_ptr_factory_.GetWeakPtr())); - } - - private: - void OnVolumeSetConfig(const std::weak_ptr& command) { - auto cmd = command.lock(); - if (!cmd) - return; - LOG(INFO) << "received command: " << cmd->GetName(); - - const auto& params = cmd->GetParameters(); - // Handle volume parameter - int32_t volume_value = 0; - if (params.GetInteger("volume", &volume_value)) { - // Display this command in terminal. - LOG(INFO) << cmd->GetName() << " volume: " << volume_value; - - if (volume_value_ != volume_value) { - volume_value_ = volume_value; - UpdateSpeakerState(); - } - cmd->Complete({}, nullptr); - return; - } - - // Handle isMuted parameter - bool isMuted_status = false; - if (params.GetBoolean("isMuted", &isMuted_status)) { - // Display this command in terminal. - LOG(INFO) << cmd->GetName() << " is " - << (isMuted_status ? "muted" : "not muted"); - - if (isMuted_status_ != isMuted_status) { - isMuted_status_ = isMuted_status; - - LOG(INFO) << "Speaker is now: " - << (isMuted_status ? "muted" : "not muted"); - UpdateSpeakerState(); - } - } - - cmd->Complete({}, nullptr); - } - - void OnOnOffSetConfig(const std::weak_ptr& command) { - auto cmd = command.lock(); - if (!cmd) - return; - LOG(INFO) << "received command: " << cmd->GetName(); - const auto& params = cmd->GetParameters(); - std::string requested_state; - if (params.GetString("state", &requested_state)) { - LOG(INFO) << cmd->GetName() << " state: " << requested_state; - - bool new_speaker_status = requested_state == "on"; - if (new_speaker_status != speaker_status_) { - speaker_status_ = new_speaker_status; - - LOG(INFO) << "Speaker is now: " << (speaker_status_ ? "ON" : "OFF"); - UpdateSpeakerState(); - } - } - cmd->Complete({}, nullptr); - } - - void UpdateSpeakerState() { - base::DictionaryValue state; - state.SetString("onOff.state", speaker_status_ ? "on" : "off"); - state.SetBoolean("volume.isMuted", isMuted_status_); - state.SetInteger("volume.volume", volume_value_); - device_->SetStateProperties(kComponent, state, nullptr); - } - - weave::Device* device_{nullptr}; - - // Simulate the state of the speaker. - bool speaker_status_; - bool isMuted_status_; - int32_t volume_value_; - base::WeakPtrFactory weak_ptr_factory_{this}; -}; - -int main(int argc, char** argv) { - Daemon::Options opts; - if (!opts.Parse(argc, argv)) { - Daemon::Options::ShowUsage(argv[0]); - return 1; - } - Daemon daemon{opts}; - SpeakerHandler speaker; - speaker.Register(daemon.GetDevice()); - daemon.Run(); - return 0; -} diff --git a/examples/examples.mk b/examples/examples.mk index 555322c..cb64e2b 100644 --- a/examples/examples.mk +++ b/examples/examples.mk @@ -21,9 +21,7 @@ EXAMPLES_DAEMON_SRC_FILES := \ examples/daemon/ledflasher/ledflasher.cc \ examples/daemon/light/light.cc \ examples/daemon/lock/lock.cc \ - examples/daemon/oven/oven.cc \ - examples/daemon/sample/sample.cc \ - examples/daemon/speaker/speaker.cc + examples/daemon/sample/sample.cc examples_daemon_obj_files := $(EXAMPLES_DAEMON_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o) @@ -62,16 +60,10 @@ out/$(BUILD_MODE)/weave_daemon_light : out/$(BUILD_MODE)/examples/daemon/light/l out/$(BUILD_MODE)/weave_daemon_lock : out/$(BUILD_MODE)/examples/daemon/lock/lock.o $(example_daemon_deps) $(CXX) -o $@ $^ $(CFLAGS) $(example_daemon_common_flags) -out/$(BUILD_MODE)/weave_daemon_oven : out/$(BUILD_MODE)/examples/daemon/oven/oven.o $(example_daemon_deps) - $(CXX) -o $@ $^ $(CFLAGS) $(example_daemon_common_flags) - out/$(BUILD_MODE)/weave_daemon_sample : out/$(BUILD_MODE)/examples/daemon/sample/sample.o $(example_daemon_deps) $(CXX) -o $@ $^ $(CFLAGS) $(example_daemon_common_flags) -out/$(BUILD_MODE)/weave_daemon_speaker : out/$(BUILD_MODE)/examples/daemon/speaker/speaker.o $(example_daemon_deps) - $(CXX) -o $@ $^ $(CFLAGS) $(example_daemon_common_flags) - -all-examples : out/$(BUILD_MODE)/weave_daemon_ledflasher out/$(BUILD_MODE)/weave_daemon_light out/$(BUILD_MODE)/weave_daemon_lock out/$(BUILD_MODE)/weave_daemon_oven out/$(BUILD_MODE)/weave_daemon_sample out/$(BUILD_MODE)/weave_daemon_speaker +all-examples : out/$(BUILD_MODE)/weave_daemon_ledflasher out/$(BUILD_MODE)/weave_daemon_light out/$(BUILD_MODE)/weave_daemon_lock out/$(BUILD_MODE)/weave_daemon_sample .PHONY : all-examples diff --git a/examples/provider/avahi_client.cc b/examples/provider/avahi_client.cc index ddd4630..36109c4 100644 --- a/examples/provider/avahi_client.cc +++ b/examples/provider/avahi_client.cc @@ -5,6 +5,7 @@ #include "examples/provider/avahi_client.h" #include +#include #include #include diff --git a/examples/provider/avahi_client.h b/examples/provider/avahi_client.h index 7d9b932..f9ba01c 100644 --- a/examples/provider/avahi_client.h +++ b/examples/provider/avahi_client.h @@ -6,6 +6,7 @@ #define LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_ #include +#include #include #include diff --git a/examples/provider/event_network.h b/examples/provider/event_network.h index 3aeac24..6a5617f 100644 --- a/examples/provider/event_network.h +++ b/examples/provider/event_network.h @@ -5,6 +5,8 @@ #ifndef LIBWEAVE_EXAMPLES_UBUNTU_EVENT_NETWORK_H_ #define LIBWEAVE_EXAMPLES_UBUNTU_EVENT_NETWORK_H_ +#include + #include #include diff --git a/examples/provider/event_task_runner.h b/examples/provider/event_task_runner.h index 97f9db9..a788950 100644 --- a/examples/provider/event_task_runner.h +++ b/examples/provider/event_task_runner.h @@ -6,6 +6,7 @@ #define LIBWEAVE_EXAMPLES_PROVIDER_EVENT_TASK_RUNNER_H_ #include +#include #include #include diff --git a/include/weave/provider/test/fake_task_runner.h b/include/weave/provider/test/fake_task_runner.h index 9476d02..9a06a8e 100644 --- a/include/weave/provider/test/fake_task_runner.h +++ b/include/weave/provider/test/fake_task_runner.h @@ -9,6 +9,7 @@ #include #include +#include #include #include diff --git a/include/weave/settings.h b/include/weave/settings.h index 2dceedb..2ebc4f2 100644 --- a/include/weave/settings.h +++ b/include/weave/settings.h @@ -13,7 +13,7 @@ namespace weave { // Scopes in order of increasing privileges. -enum class AuthScope { +enum class AuthScope : int32_t { kNone, kViewer, kUser, diff --git a/src/access_revocation_manager_impl.cc b/src/access_revocation_manager_impl.cc index 93bdf3f..1c051de 100644 --- a/src/access_revocation_manager_impl.cc +++ b/src/access_revocation_manager_impl.cc @@ -4,8 +4,11 @@ #include "src/access_revocation_manager_impl.h" +#include + #include #include +#include #include #include "src/commands/schema_constants.h" @@ -70,7 +73,8 @@ void AccessRevocationManagerImpl::Save(const DoneCallback& callback) { base::ListValue list; for (const auto& e : entries_) { - scoped_ptr entry{new base::DictionaryValue}; + std::unique_ptr entry = + base::MakeUnique(); entry->SetString(kUser, Base64Encode(e.user_id)); entry->SetString(kApp, Base64Encode(e.app_id)); entry->SetInteger(kRevocation, ToJ2000Time(e.revocation)); diff --git a/src/bind_lambda.h b/src/bind_lambda.h index e6f367c..164e3e4 100644 --- a/src/bind_lambda.h +++ b/src/bind_lambda.h @@ -31,7 +31,7 @@ class LambdaAdapter { public: typedef R(RunType)(Args...); LambdaAdapter(Lambda lambda) : lambda_(lambda) {} - R Run(Args... args) { return lambda_(CallbackForward(args)...); } + R Run(Args... args) { return lambda_(std::forward(args)...); } private: Lambda lambda_; @@ -43,7 +43,7 @@ class LambdaAdapter { public: typedef R(RunType)(Args...); LambdaAdapter(Lambda lambda) : lambda_(lambda) {} - R Run(Args... args) { return lambda_(CallbackForward(args)...); } + R Run(Args... args) { return lambda_(std::forward(args)...); } private: Lambda lambda_; diff --git a/src/privet/privet_handler.cc b/src/privet/privet_handler.cc index 42a1c23..ada9f44 100644 --- a/src/privet/privet_handler.cc +++ b/src/privet/privet_handler.cc @@ -711,7 +711,8 @@ void PrivetHandler::HandleAuth(const base::DictionaryValue& input, return ReturnError(*error, callback); } - CHECK_LE(access_token_scope, desired_scope); + CHECK_LE(static_cast(access_token_scope), + static_cast(desired_scope)); if (access_token_scope < acceptable_scope) { Error::AddToPrintf(&error, FROM_HERE, errors::kAccessDenied, diff --git a/src/privet/privet_handler.h b/src/privet/privet_handler.h index e64151b..eab1aa3 100644 --- a/src/privet/privet_handler.h +++ b/src/privet/privet_handler.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "src/privet/cloud_delegate.h" diff --git a/src/privet/privet_types.h b/src/privet/privet_types.h index 44be96f..2a290d4 100644 --- a/src/privet/privet_types.h +++ b/src/privet/privet_types.h @@ -6,6 +6,7 @@ #define LIBWEAVE_SRC_PRIVET_PRIVET_TYPES_H_ #include +#include #include #include diff --git a/src/streams.h b/src/streams.h index 990f47c..cefcf94 100644 --- a/src/streams.h +++ b/src/streams.h @@ -5,6 +5,8 @@ #ifndef LIBWEAVE_SRC_STREAMS_H_ #define LIBWEAVE_SRC_STREAMS_H_ +#include + #include #include diff --git a/tests_schema/daemon/testdevice/standard_traits.h b/tests_schema/daemon/testdevice/standard_traits.h index c63c5fe..27586f8 100644 --- a/tests_schema/daemon/testdevice/standard_traits.h +++ b/tests_schema/daemon/testdevice/standard_traits.h @@ -196,6 +196,35 @@ const char kTraits[] = R"({ } } } + }, + "volume": { + "commands": { + "setConfig": { + "minimalRole": "user", + "parameters": { + "volume": { + "type": "integer", + "minimum": 0, + "maximum": 100 + }, + "isMuted": { + "type": "boolean" + } + } + } + }, + "state": { + "volume": { + "isRequired": true, + "type": "integer", + "minimum": 0, + "maximum": 100 + }, + "isMuted": { + "isRequired": true, + "type": "boolean" + } + } } })"; @@ -203,6 +232,7 @@ const char kDefaultState[] = R"({ "lock":{"isLockingSupported": true}, "onOff":{"state": "on"}, "brightness":{"brightness": 0.0}, + "volume":{"isMuted": true}, "colorTemp":{"colorTemp": 0}, "colorXy": { "colorSetting": {"colorX": 0.0, "colorY": 0.0}, diff --git a/tests_schema/daemon/testdevice/testdevice.cc b/tests_schema/daemon/testdevice/testdevice.cc index a69ff46..7a29eac 100644 --- a/tests_schema/daemon/testdevice/testdevice.cc +++ b/tests_schema/daemon/testdevice/testdevice.cc @@ -45,7 +45,8 @@ class TestDeviceHandler { CHECK(device->AddComponent( standard_traits::kComponent, - {"lock", "onOff", "brightness", "colorTemp", "colorXy"}, nullptr)); + {"lock", "onOff", "brightness", "volume", "colorTemp", "colorXy"}, + nullptr)); CHECK(device->AddComponent(custom_traits::ledflasher, {"_ledflasher"}, nullptr)); @@ -79,6 +80,9 @@ class TestDeviceHandler { standard_traits::kComponent, "brightness.setConfig", base::Bind(&TestDeviceHandler::OnBrightnessSetConfig, weak_ptr_factory_.GetWeakPtr())); + device->AddCommandHandler(standard_traits::kComponent, "volume.setConfig", + base::Bind(&TestDeviceHandler::OnVolumeSetConfig, + weak_ptr_factory_.GetWeakPtr())); device->AddCommandHandler( standard_traits::kComponent, "colorTemp.setConfig", base::Bind(&TestDeviceHandler::OnColorTempSetConfig, @@ -148,6 +152,50 @@ class TestDeviceHandler { AbortCommand(cmd); } + void OnVolumeSetConfig(const std::weak_ptr& command) { + auto cmd = command.lock(); + if (!cmd) + return; + LOG(INFO) << "received command: " << cmd->GetName(); + const auto& params = cmd->GetParameters(); + // Handle volume parameter + bool updateState = false; + int32_t volume_value = 0; + if (params.GetInteger("volume", &volume_value)) { + LOG(INFO) << cmd->GetName() << " volume: " << volume_value; + + if (volume_value < 0 || volume_value > 100) { + // Invalid volume range value is specified. + AbortCommand(cmd); + return; + } + + if (volume_value_ != volume_value) { + volume_value_ = volume_value; + updateState = true; + } + } + + // Handle isMuted parameter + bool isMuted_status = false; + if (params.GetBoolean("isMuted", &isMuted_status)) { + LOG(INFO) << cmd->GetName() << " is " + << (isMuted_status ? "muted" : "not muted"); + + if (isMuted_status_ != isMuted_status) { + isMuted_status_ = isMuted_status; + LOG(INFO) << "Speaker is now: " + << (isMuted_status ? "muted" : "not muted"); + updateState = true; + } + } + + if (updateState) { + UpdateTestDeviceState(); + } + cmd->Complete({}, nullptr); + } + void OnOnOffSetConfig(const std::weak_ptr& command) { auto cmd = command.lock(); if (!cmd) @@ -159,18 +207,16 @@ class TestDeviceHandler { LOG(INFO) << cmd->GetName() << " state: " << requested_state; std::string temp_state = requested_state; - std::transform(temp_state.begin(), temp_state.end(), temp_state.begin(), - ::toupper); - if (temp_state != "ON" && temp_state != "OFF") { + if (temp_state != "on" && temp_state != "off") { // Invalid OnOff state is specified. AbortCommand(cmd); return; } - bool new_light_status = requested_state == "on"; - if (new_light_status != light_status_) { - light_status_ = new_light_status; - LOG(INFO) << "Light is now: " << (light_status_ ? "ON" : "OFF"); + bool new_device_status = requested_state == "on"; + if (new_device_status != device_status_) { + device_status_ = new_device_status; + LOG(INFO) << "Device is now: " << (device_status_ ? "ON" : "OFF"); UpdateTestDeviceState(); } cmd->Complete({}, nullptr); @@ -319,8 +365,11 @@ class TestDeviceHandler { device_->SetStateProperty(standard_traits::kComponent, "lock.lockedState", base::StringValue{updated_state}, nullptr); base::DictionaryValue state; - state.SetString("onOff.state", light_status_ ? "on" : "off"); + state.SetString("onOff.state", device_status_ ? "on" : "off"); state.SetDouble("brightness.brightness", brightness_state_); + // state.SetString("onOff.state", speaker_status_ ? "on" : "off"); + state.SetBoolean("volume.isMuted", isMuted_status_); + state.SetInteger("volume.volume", volume_value_); state.SetInteger("colorTemp.minColorTemp", color_temp_min_value_); state.SetInteger("colorTemp.maxColorTemp", color_temp_max_value_); state.SetInteger("colorTemp.colorTemp", color_temp_); @@ -344,8 +393,10 @@ class TestDeviceHandler { // Simulate the state of the testdevice. weave::lockstate::LockState lock_state_{weave::lockstate::LockState::kLocked}; - bool light_status_{false}; + bool device_status_{false}; double brightness_state_{0.0}; + bool isMuted_status_{false}; + int32_t volume_value_{0}; int32_t color_temp_{0}; int32_t color_temp_min_value_{0}; int32_t color_temp_max_value_{1}; 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, + ::testing::Types, std::unique_ptr, std::unique_ptr>; TYPED_TEST_CASE(BindMoveOnlyTypeTest, MoveOnlyTypesToTest); @@ -880,23 +880,23 @@ TYPED_TEST(BindMoveOnlyTypeTest, UnboundForwarding) { EXPECT_EQ(1, deletes); } -void VerifyVector(const std::vector>& v) { +void VerifyVector(const std::vector>& v) { ASSERT_EQ(1u, v.size()); EXPECT_EQ(12345, *v[0]); } -std::vector> AcceptAndReturnMoveOnlyVector( - std::vector> v) { +std::vector> AcceptAndReturnMoveOnlyVector( + std::vector> 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>; + using MoveOnlyVector = std::vector>; MoveOnlyVector v; - v.push_back(make_scoped_ptr(new int(12345))); + v.push_back(base::MakeUnique(12345)); // Early binding should work: base::Callback 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 -#include -#include -#include -#include +#include #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 extern template class CallbackBase; extern template class CallbackBase; -// 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 struct IsMoveOnlyType { - // Types YesType and NoType are guaranteed such that sizeof(YesType) < - // sizeof(NoType). - using YesType = char; - struct NoType { YesType dummy[2]; }; - - template - static YesType Test(const typename U::MoveOnlyTypeForCPP03*); - - template - static NoType Test(...); - - static const bool value = sizeof((Test(0))) == sizeof(YesType) && - !std::is_const::value; -}; - -// Specialization of IsMoveOnlyType so that std::unique_ptr is still considered -// move-only, even without the sentinel member. -template -struct IsMoveOnlyType> : 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 -struct IsMoveOnlyType> : IsMoveOnlyType {}; - -template -struct CallbackParamTraitsForMoveOnlyType; - -template -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 -struct CallbackParamTraits - : std::conditional::value, - CallbackParamTraitsForMoveOnlyType, - CallbackParamTraitsForNonMoveOnlyType>::type { -}; - -template -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 -struct CallbackParamTraitsForNonMoveOnlyType { - using ForwardType = const T*; -}; - -// See comment for CallbackParamTraits. -template -struct CallbackParamTraitsForNonMoveOnlyType { - 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 -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 std::enable_if::value, T>::type& CallbackForward( - T& t) { - return t; -} - -template -typename std::enable_if::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 +#include #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 OnFooCallback; // -// scoped_ptr::Subscription> +// std::unique_ptr::Subscription> // RegisterCallback(const OnFooCallback& cb) { // return callback_list_.Add(cb); // } @@ -62,7 +61,7 @@ // // Do something. // } // -// scoped_ptr::Subscription> +// std::unique_ptr::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 Add(const CallbackType& cb) WARN_UNUSED_RESULT { + std::unique_ptr Add(const CallbackType& cb) WARN_UNUSED_RESULT { DCHECK(!cb.is_null()); - return scoped_ptr( + return std::unique_ptr( new Subscription(this, callbacks_.insert(callbacks_.end(), cb))); } @@ -211,8 +210,8 @@ class CallbackList CallbackList() {} - void Notify( - typename internal::CallbackParamTraits::ForwardType... args) { + template + void Notify(RunArgs&&... args) { typename internal::CallbackListBase::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 +#include #include #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::Subscription> sub) { + std::unique_ptr::Subscription> sub) { removal_subscription_ = std::move(sub); } @@ -46,7 +46,7 @@ class Remover { private: int total_; - scoped_ptr::Subscription> removal_subscription_; + std::unique_ptr::Subscription> removal_subscription_; DISALLOW_COPY_AND_ASSIGN(Remover); }; @@ -74,7 +74,7 @@ class Adder { bool added_; int total_; CallbackList* cb_reg_; - scoped_ptr::Subscription> subscription_; + std::unique_ptr::Subscription> subscription_; DISALLOW_COPY_AND_ASSIGN(Adder); }; @@ -118,42 +118,43 @@ TEST(CallbackListTest, ArityTest) { Summer s; CallbackList c1; - scoped_ptr::Subscription> subscription1 = + std::unique_ptr::Subscription> subscription1 = c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); c1.Notify(1); EXPECT_EQ(1, s.value()); CallbackList c2; - scoped_ptr::Subscription> subscription2 = + std::unique_ptr::Subscription> subscription2 = c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); c2.Notify(1, 2); EXPECT_EQ(3, s.value()); CallbackList c3; - scoped_ptr::Subscription> + std::unique_ptr::Subscription> subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); c3.Notify(1, 2, 3); EXPECT_EQ(6, s.value()); CallbackList c4; - scoped_ptr::Subscription> + std::unique_ptr::Subscription> subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); c4.Notify(1, 2, 3, 4); EXPECT_EQ(10, s.value()); CallbackList c5; - scoped_ptr::Subscription> + std::unique_ptr::Subscription> subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); c5.Notify(1, 2, 3, 4, 5); EXPECT_EQ(15, s.value()); CallbackList c6; - scoped_ptr::Subscription> + std::unique_ptr< + CallbackList::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 cb_reg; Listener a, b, c; - scoped_ptr::Subscription> a_subscription = + std::unique_ptr::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); - scoped_ptr::Subscription> b_subscription = + std::unique_ptr::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::Subscription> c_subscription = + std::unique_ptr::Subscription> c_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c))); cb_reg.Notify(); @@ -201,9 +202,9 @@ TEST(CallbackListTest, BasicTestWithParams) { CallbackList cb_reg; Listener a(1), b(-1), c(1); - scoped_ptr::Subscription> a_subscription = + std::unique_ptr::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a))); - scoped_ptr::Subscription> b_subscription = + std::unique_ptr::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::Subscription> c_subscription = + std::unique_ptr::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::Subscription> remover_1_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_1))); - scoped_ptr::Subscription> remover_2_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_2))); - scoped_ptr::Subscription> a_subscription = + std::unique_ptr::Subscription> remover_1_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); + std::unique_ptr::Subscription> remover_2_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); + std::unique_ptr::Subscription> a_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); - scoped_ptr::Subscription> b_subscription = + std::unique_ptr::Subscription> b_subscription = cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); // |remover_1| will remove itself. @@ -278,9 +279,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) { CallbackList cb_reg; Adder a(&cb_reg); Listener b; - scoped_ptr::Subscription> a_subscription = + std::unique_ptr::Subscription> a_subscription = cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a))); - scoped_ptr::Subscription> b_subscription = + std::unique_ptr::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::Subscription> subscription = + std::unique_ptr::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::Subscription> remover_1_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_1))); - scoped_ptr::Subscription> remover_2_sub = - cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, - Unretained(&remover_2))); + std::unique_ptr::Subscription> remover_1_sub = + cb_reg.Add( + Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); + std::unique_ptr::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 +#include #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 +#include #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 json, + std::unique_ptr root) + : json_(std::move(json)) { DCHECK(root->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue::Swap(static_cast(root)); + DictionaryValue::Swap(static_cast(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 copy(DeepCopy()); + std::unique_ptr 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* out) override { + std::unique_ptr* 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 out_owned; + std::unique_ptr out_owned; if (!DictionaryValue::RemoveWithoutPathExpansion(key, &out_owned)) return false; - out->reset(out_owned->DeepCopy()); + *out = out_owned->CreateDeepCopy(); return true; } private: - scoped_ptr json_; + std::unique_ptr json_; DISALLOW_COPY_AND_ASSIGN(DictionaryHiddenRootValue); }; class ListHiddenRootValue : public ListValue { public: - ListHiddenRootValue(std::string* json, Value* root) : json_(json) { + ListHiddenRootValue(std::unique_ptr json, + std::unique_ptr root) + : json_(std::move(json)) { DCHECK(root->IsType(Value::TYPE_LIST)); - ListValue::Swap(static_cast(root)); + ListValue::Swap(static_cast(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 copy(DeepCopy()); + std::unique_ptr 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* out) override { + bool Remove(size_t index, std::unique_ptr* 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 out_owned; + std::unique_ptr out_owned; if (!ListValue::Remove(index, &out_owned)) return false; - out->reset(out_owned->DeepCopy()); + *out = out_owned->CreateDeepCopy(); return true; } private: - scoped_ptr json_; + std::unique_ptr 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 input_copy; +std::unique_ptr JSONParser::Parse(StringPiece input) { + std::unique_ptr 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 root(ParseNextToken()); - if (!root.get()) - return NULL; + std::unique_ptr 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(c), 128); if (string_) string_->push_back(c); @@ -494,7 +500,7 @@ Value* JSONParser::ConsumeDictionary() { return NULL; } - scoped_ptr dict(new DictionaryValue); + std::unique_ptr dict(new DictionaryValue); NextChar(); Token token = GetNextToken(); @@ -558,7 +564,7 @@ Value* JSONParser::ConsumeList() { return NULL; } - scoped_ptr list(new ListValue); + std::unique_ptr 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 #include +#include #include #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 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 has too much of an overhead here. + // Strong. std::unique_ptr 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 +#include + #include #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 parser(NewTestParser(input)); + std::unique_ptr 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 parser(NewTestParser(input)); - scoped_ptr value(parser->ConsumeString()); + std::unique_ptr parser(NewTestParser(input)); + std::unique_ptr 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 parser(NewTestParser(input)); - scoped_ptr value(parser->ConsumeList()); + std::unique_ptr parser(NewTestParser(input)); + std::unique_ptr 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 parser(NewTestParser(input)); - scoped_ptr value(parser->ConsumeDictionary()); + std::unique_ptr parser(NewTestParser(input)); + std::unique_ptr 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 parser(NewTestParser(input)); - scoped_ptr value(parser->ConsumeLiteral()); + std::unique_ptr parser(NewTestParser(input)); + std::unique_ptr 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 parser(NewTestParser(input)); - scoped_ptr value(parser->ConsumeNumber()); + std::unique_ptr parser(NewTestParser(input)); + std::unique_ptr 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 root = JSONReader::ReadAndReturnError( + std::unique_ptr 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 root = JSONReader::ReadAndReturnError( + std::unique_ptr 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 JSONReader::Read(const StringPiece& json) { +std::unique_ptr JSONReader::Read(StringPiece json) { internal::JSONParser parser(JSON_PARSE_RFC); - return make_scoped_ptr(parser.Parse(json)); + return parser.Parse(json); } // static -scoped_ptr JSONReader::Read(const StringPiece& json, int options) { +std::unique_ptr JSONReader::Read(StringPiece json, int options) { internal::JSONParser parser(options); - return make_scoped_ptr(parser.Parse(json)); + return parser.Parse(json); } // static -scoped_ptr 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 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 root(parser.Parse(json)); + std::unique_ptr 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 JSONReader::ReadToValue(const std::string& json) { - return make_scoped_ptr(parser_->Parse(json)); +std::unique_ptr 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 #include #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 Read(const StringPiece& json); + static std::unique_ptr 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 Read(const StringPiece& json, int options); + static std::unique_ptr 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 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 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 ReadToValue(const std::string& json); + std::unique_ptr 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 parser_; + std::unique_ptr 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 #include +#include #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 root = JSONReader().ReadToValue(" null "); + std::unique_ptr 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 root2 = + std::unique_ptr 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 dict_literal_0; - scoped_ptr dict_literal_1; - scoped_ptr dict_string_0; - scoped_ptr dict_string_1; - scoped_ptr list_value_0; - scoped_ptr list_value_1; + std::unique_ptr dict_literal_0; + std::unique_ptr dict_literal_1; + std::unique_ptr dict_string_0; + std::unique_ptr dict_string_1; + std::unique_ptr list_value_0; + std::unique_ptr list_value_1; { - scoped_ptr root = JSONReader::Read( + std::unique_ptr 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 +#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 list(new ListValue()); - scoped_ptr inner_dict(new DictionaryValue()); + std::unique_ptr list(new ListValue()); + std::unique_ptr 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 period_dict2(new DictionaryValue()); + std::unique_ptr 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 root(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); + std::unique_ptr 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 +#include + +namespace base { + +// Helper to transfer ownership of a raw pointer to a std::unique_ptr. +// Note that std::unique_ptr has very different semantics from +// std::unique_ptr: do not use this helper for array allocations. +template +std::unique_ptr WrapUnique(T* ptr) { + return std::unique_ptr(ptr); +} + +namespace internal { + +template +struct MakeUniqueResult { + using Scalar = std::unique_ptr; +}; + +template +struct MakeUniqueResult { + using Array = std::unique_ptr; +}; + +template +struct MakeUniqueResult { + 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(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 +// auto ptr = MakeUnique("hello world!"); +// +// // arr is a std::unique_ptr +// auto arr = MakeUnique(5); + +// Overload for non-array types. Arguments are forwarded to T's constructor. +template +typename internal::MakeUniqueResult::Scalar MakeUnique(Args&&... args) { + return std::unique_ptr(new T(std::forward(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 internal::MakeUniqueResult::Array MakeUnique(size_t size) { + return std::unique_ptr(new typename std::remove_extent::type[size]()); +} + +// Overload to reject array types of known bound, e.g. T[n]. +template +typename internal::MakeUniqueResult::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): -// { -// scoped_ptr foo(new Foo("wee")); -// } // foo goes out of scope, releasing the pointer with it. -// -// { -// scoped_ptr 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): -// { -// scoped_ptr 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; -// 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 arg) { -// // Do something with arg. -// } -// scoped_ptr 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(new Foo("new")); -// } -// scoped_ptr PassThru(scoped_ptr arg) { -// return arg; -// } -// -// { -// scoped_ptr ptr(new Foo("yay")); // ptr manages Foo("yay"). -// TakesOwnership(std::move(ptr)); // ptr no longer owns Foo("yay"). -// scoped_ptr ptr2 = CreateFoo(); // ptr2 owns the return Foo. -// scoped_ptr 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 to initialize a scoped_ptr: -// -// scoped_ptr foo(new Foo()); -// scoped_ptr 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 -#include - -#include -#include -#include -#include - -#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 foo_ptr( -// static_cast(malloc(sizeof(int)))); -struct FreeDeleter { - inline void operator()(void* ptr) const { - free(ptr); - } -}; - -} // namespace base - -template > -using scoped_ptr = std::unique_ptr; - -// A function to convert T* into scoped_ptr -// Doing e.g. make_scoped_ptr(new FooBarBaz(arg)) is a shorter notation -// for scoped_ptr >(new FooBarBaz(arg)) -template -scoped_ptr make_scoped_ptr(T* ptr) { - return scoped_ptr(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 #include #include "base/base_export.h" @@ -197,8 +198,9 @@ template class WeakPtrFactory; template 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& 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 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 #include #include #include "base/bind.h" #include "base/location.h" -#include "base/memory/scoped_ptr.h" namespace base { namespace { +WeakPtr PassThru(WeakPtr ptr) { + return ptr; +} + struct Base { std::string member; }; @@ -52,13 +56,13 @@ TEST(WeakPtrFactoryTest, Comparison) { TEST(WeakPtrFactoryTest, OutOfScope) { WeakPtr ptr; - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); { int data; WeakPtrFactory 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 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 ptr = PassThru(nullptr); + EXPECT_EQ(nullptr, ptr.get()); +} + TEST(WeakPtrTest, SupportsWeakPtr) { Target target; WeakPtr 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 #include +#include #include #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 CopyWithoutEmptyChildren(const Value& node); +std::unique_ptr 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 CopyListWithoutEmptyChildren(const ListValue& list) { - scoped_ptr copy; +std::unique_ptr CopyListWithoutEmptyChildren(const ListValue& list) { + std::unique_ptr copy; for (ListValue::const_iterator it = list.begin(); it != list.end(); ++it) { - scoped_ptr child_copy = CopyWithoutEmptyChildren(**it); + std::unique_ptr child_copy = CopyWithoutEmptyChildren(**it); if (child_copy) { if (!copy) copy.reset(new ListValue); @@ -39,11 +40,11 @@ scoped_ptr CopyListWithoutEmptyChildren(const ListValue& list) { return copy; } -scoped_ptr CopyDictionaryWithoutEmptyChildren( +std::unique_ptr CopyDictionaryWithoutEmptyChildren( const DictionaryValue& dict) { - scoped_ptr copy; + std::unique_ptr copy; for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { - scoped_ptr child_copy = CopyWithoutEmptyChildren(it.value()); + std::unique_ptr child_copy = CopyWithoutEmptyChildren(it.value()); if (child_copy) { if (!copy) copy.reset(new DictionaryValue); @@ -53,7 +54,7 @@ scoped_ptr CopyDictionaryWithoutEmptyChildren( return copy; } -scoped_ptr CopyWithoutEmptyChildren(const Value& node) { +std::unique_ptr CopyWithoutEmptyChildren(const Value& node) { switch (node.GetType()) { case Value::TYPE_LIST: return CopyListWithoutEmptyChildren(static_cast(node)); @@ -89,47 +90,47 @@ Value::~Value() { } // static -scoped_ptr Value::CreateNullValue() { - return make_scoped_ptr(new Value(TYPE_NULL)); +std::unique_ptr 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::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr 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 buffer, size_t size) +BinaryValue::BinaryValue(std::unique_ptr 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 scoped_buffer_copy(buffer_copy); + std::unique_ptr 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::From(scoped_ptr value) { +std::unique_ptr DictionaryValue::From( + std::unique_ptr 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 in_value) { +void DictionaryValue::Set(const std::string& path, + std::unique_ptr in_value) { DCHECK(IsStringUTF8(path)); DCHECK(in_value); @@ -407,7 +410,7 @@ void DictionaryValue::Set(const std::string& path, scoped_ptr 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 in_value) { + std::unique_ptr 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* out_value) { + std::unique_ptr* 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* out_value) { +bool DictionaryValue::RemoveWithoutPathExpansion( + const std::string& key, + std::unique_ptr* 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* out_value) { + std::unique_ptr* 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::DeepCopyWithoutEmptyChildren() +std::unique_ptr DictionaryValue::DeepCopyWithoutEmptyChildren() const { - scoped_ptr copy = CopyDictionaryWithoutEmptyChildren(*this); + std::unique_ptr copy = + CopyDictionaryWithoutEmptyChildren(*this); if (!copy) copy.reset(new DictionaryValue); return copy; @@ -810,8 +815,8 @@ DictionaryValue* DictionaryValue::DeepCopy() const { return result; } -scoped_ptr DictionaryValue::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr 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::From(scoped_ptr value) { +std::unique_ptr ListValue::From(std::unique_ptr 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 in_value) { +bool ListValue::Set(size_t index, std::unique_ptr in_value) { return Set(index, in_value.release()); } @@ -985,7 +990,7 @@ bool ListValue::GetList(size_t index, ListValue** out_value) { const_cast(out_value)); } -bool ListValue::Remove(size_t index, scoped_ptr* out_value) { +bool ListValue::Remove(size_t index, std::unique_ptr* 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* out_value) { + std::unique_ptr* 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 in_value) { +void ListValue::Append(std::unique_ptr in_value) { Append(in_value.release()); } @@ -1105,8 +1110,8 @@ ListValue* ListValue::DeepCopy() const { return result; } -scoped_ptr ListValue::CreateDeepCopy() const { - return make_scoped_ptr(DeepCopy()); +std::unique_ptr 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 #include +#include #include #include #include @@ -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 CreateNullValue(); + static std::unique_ptr 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 CreateDeepCopy() const; + std::unique_ptr 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 buffer, size_t size); + BinaryValue(std::unique_ptr 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 buffer_; + std::unique_ptr 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 From(scoped_ptr value); + static std::unique_ptr From(std::unique_ptr 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 in_value); + void Set(const std::string& path, std::unique_ptr 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 in_value); + std::unique_ptr 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* out_value); + virtual bool Remove(const std::string& path, + std::unique_ptr* 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* out_value); + std::unique_ptr* 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* out_value); + std::unique_ptr* 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 DeepCopyWithoutEmptyChildren() const; + std::unique_ptr 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 CreateDeepCopy() const; + std::unique_ptr 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 From(scoped_ptr value); + static std::unique_ptr From(std::unique_ptr 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 in_value); + bool Set(size_t index, std::unique_ptr 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* out_value); + virtual bool Remove(size_t index, std::unique_ptr* 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* out_value); + iterator Erase(iterator iter, std::unique_ptr* out_value); // Appends a Value to the end of the list. - void Append(scoped_ptr in_value); + void Append(std::unique_ptr 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 CreateDeepCopy() const; + std::unique_ptr 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 #include +#include #include #include -#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 new_toolbar_bookmarks(new ListValue); + std::unique_ptr 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 new_bookmark(new DictionaryValue); + std::unique_ptr 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 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 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 binary(new BinaryValue()); + std::unique_ptr 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 buffer(new char[15]); + std::unique_ptr 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 narrow_value(new StringValue("narrow")); + std::unique_ptr 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 removed_item; + std::unique_ptr 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::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 value(new DeletionTestValue(&deletion_flag)); + std::unique_ptr 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 removed_item; + std::unique_ptr 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 removed_item; + std::unique_ptr 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 scoped_null = Value::CreateNullValue(); + std::unique_ptr scoped_null = Value::CreateNullValue(); Value* original_null = scoped_null.get(); original_dict.Set("null", std::move(scoped_null)); - scoped_ptr scoped_bool(new FundamentalValue(true)); + std::unique_ptr scoped_bool(new FundamentalValue(true)); FundamentalValue* original_bool = scoped_bool.get(); original_dict.Set("bool", std::move(scoped_bool)); - scoped_ptr scoped_int(new FundamentalValue(42)); + std::unique_ptr scoped_int(new FundamentalValue(42)); FundamentalValue* original_int = scoped_int.get(); original_dict.Set("int", std::move(scoped_int)); - scoped_ptr scoped_double(new FundamentalValue(3.14)); + std::unique_ptr scoped_double(new FundamentalValue(3.14)); FundamentalValue* original_double = scoped_double.get(); original_dict.Set("double", std::move(scoped_double)); - scoped_ptr scoped_string(new StringValue("hello")); + std::unique_ptr scoped_string(new StringValue("hello")); StringValue* original_string = scoped_string.get(); original_dict.Set("string", std::move(scoped_string)); - scoped_ptr original_buffer(new char[42]); + std::unique_ptr original_buffer(new char[42]); memset(original_buffer.get(), '!', 42); - scoped_ptr scoped_binary( + std::unique_ptr 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 scoped_list(new ListValue()); + std::unique_ptr scoped_list(new ListValue()); Value* original_list = scoped_list.get(); - scoped_ptr scoped_list_element_0(new FundamentalValue(0)); + std::unique_ptr 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 scoped_list_element_1(new FundamentalValue(1)); + std::unique_ptr 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 scoped_nested_dictionary(new DictionaryValue()); + std::unique_ptr 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 copy_dict = original_dict.CreateDeepCopy(); + std::unique_ptr 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 null1(Value::CreateNullValue()); - scoped_ptr null2(Value::CreateNullValue()); + std::unique_ptr null1(Value::CreateNullValue()); + std::unique_ptr 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 copy = dv.CreateDeepCopy(); + std::unique_ptr copy = dv.CreateDeepCopy(); EXPECT_TRUE(dv.Equals(copy.get())); - scoped_ptr list(new ListValue); + std::unique_ptr list(new ListValue); ListValue* original_list = list.get(); list->Append(Value::CreateNullValue()); - list->Append(make_scoped_ptr(new DictionaryValue)); - scoped_ptr list_copy(list->CreateDeepCopy()); + list->Append(WrapUnique(new DictionaryValue)); + std::unique_ptr 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 null1(Value::CreateNullValue()); - scoped_ptr null2(Value::CreateNullValue()); + std::unique_ptr null1(Value::CreateNullValue()); + std::unique_ptr null2(Value::CreateNullValue()); EXPECT_TRUE(Value::Equals(null1.get(), null2.get())); EXPECT_TRUE(Value::Equals(NULL, NULL)); - scoped_ptr i42(new FundamentalValue(42)); - scoped_ptr j42(new FundamentalValue(42)); - scoped_ptr i17(new FundamentalValue(17)); + std::unique_ptr i42(new FundamentalValue(42)); + std::unique_ptr j42(new FundamentalValue(42)); + std::unique_ptr 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 scoped_null(Value::CreateNullValue()); + std::unique_ptr scoped_null(Value::CreateNullValue()); Value* original_null = scoped_null.get(); original_dict.Set("null", std::move(scoped_null)); - scoped_ptr scoped_bool(new FundamentalValue(true)); + std::unique_ptr scoped_bool(new FundamentalValue(true)); Value* original_bool = scoped_bool.get(); original_dict.Set("bool", std::move(scoped_bool)); - scoped_ptr scoped_int(new FundamentalValue(42)); + std::unique_ptr scoped_int(new FundamentalValue(42)); Value* original_int = scoped_int.get(); original_dict.Set("int", std::move(scoped_int)); - scoped_ptr scoped_double(new FundamentalValue(3.14)); + std::unique_ptr scoped_double(new FundamentalValue(3.14)); Value* original_double = scoped_double.get(); original_dict.Set("double", std::move(scoped_double)); - scoped_ptr scoped_string(new StringValue("hello")); + std::unique_ptr scoped_string(new StringValue("hello")); Value* original_string = scoped_string.get(); original_dict.Set("string", std::move(scoped_string)); - scoped_ptr original_buffer(new char[42]); + std::unique_ptr original_buffer(new char[42]); memset(original_buffer.get(), '!', 42); - scoped_ptr scoped_binary( + std::unique_ptr 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 scoped_list(new ListValue()); + std::unique_ptr scoped_list(new ListValue()); Value* original_list = scoped_list.get(); - scoped_ptr scoped_list_element_0(new FundamentalValue(0)); + std::unique_ptr scoped_list_element_0( + new FundamentalValue(0)); scoped_list->Append(std::move(scoped_list_element_0)); - scoped_ptr scoped_list_element_1(new FundamentalValue(1)); + std::unique_ptr 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 copy_dict = original_dict.CreateDeepCopy(); - scoped_ptr copy_null = original_null->CreateDeepCopy(); - scoped_ptr copy_bool = original_bool->CreateDeepCopy(); - scoped_ptr copy_int = original_int->CreateDeepCopy(); - scoped_ptr copy_double = original_double->CreateDeepCopy(); - scoped_ptr copy_string = original_string->CreateDeepCopy(); - scoped_ptr copy_binary = original_binary->CreateDeepCopy(); - scoped_ptr copy_list = original_list->CreateDeepCopy(); + std::unique_ptr copy_dict = original_dict.CreateDeepCopy(); + std::unique_ptr copy_null = original_null->CreateDeepCopy(); + std::unique_ptr copy_bool = original_bool->CreateDeepCopy(); + std::unique_ptr copy_int = original_int->CreateDeepCopy(); + std::unique_ptr copy_double = original_double->CreateDeepCopy(); + std::unique_ptr copy_string = original_string->CreateDeepCopy(); + std::unique_ptr copy_binary = original_binary->CreateDeepCopy(); + std::unique_ptr 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 root(new DictionaryValue); + std::unique_ptr 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 inner(new DictionaryValue); - inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); - inner->Set("empty_list", make_scoped_ptr(new ListValue)); + std::unique_ptr 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 inner(new ListValue); - inner->Append(make_scoped_ptr(new DictionaryValue)); - inner->Append(make_scoped_ptr(new ListValue)); + std::unique_ptr 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 inner(new ListValue()); - inner->Append(make_scoped_ptr(new DictionaryValue)); - inner->Append(make_scoped_ptr(new ListValue)); + std::unique_ptr inner(new ListValue()); + inner->Append(WrapUnique(new DictionaryValue)); + inner->Append(WrapUnique(new ListValue)); root->Set("list_with_empty_children", std::move(inner)); - scoped_ptr inner2(new DictionaryValue); - inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); - inner2->Set("empty_list", make_scoped_ptr(new ListValue)); + std::unique_ptr 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 inner(new ListValue); - scoped_ptr inner2(new ListValue); - inner2->Append(make_scoped_ptr(new StringValue("hello"))); - inner->Append(make_scoped_ptr(new DictionaryValue)); + std::unique_ptr inner(new ListValue); + std::unique_ptr 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 base(new DictionaryValue); + std::unique_ptr base(new DictionaryValue); base->SetString("base_key", "base_key_value_base"); base->SetString("collide_key", "collide_key_value_base"); - scoped_ptr base_sub_dict(new DictionaryValue); + std::unique_ptr 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 merge(new DictionaryValue); + std::unique_ptr merge(new DictionaryValue); merge->SetString("merge_key", "merge_key_value_merge"); merge->SetString("collide_key", "collide_key_value_merge"); - scoped_ptr merge_sub_dict(new DictionaryValue); + std::unique_ptr 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 child(new DictionaryValue); + std::unique_ptr 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 base(new DictionaryValue); + std::unique_ptr 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 merged(new DictionaryValue); + std::unique_ptr 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 #include -#include - namespace crypto { void SHA256HashString(const std::string& str, uint8_t* output, size_t len) { -- cgit v1.2.3