Skip to content

Commit

Permalink
Remove base::Value::CreateNullValue
Browse files Browse the repository at this point in the history
This change removes base::Value::CreateNullValue in favor of Value's default constructor. In particular, this change

- Replaces |Value::CreateNullValue()| with |MakeUnique<Value>()|.
  - Adds #includes of base/memory/ptr_util.h where needed.
  - Replaces |std::unique_ptr<Value>| with |auto| where appropriate.
- Replaces |*Value::CreateNullValue()| with |Value()|.
- Replaces |Value::CreateNullValue().release()| with |new Value()|.

BUG=646113
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2792573002
Cr-Commit-Position: refs/heads/master@{#462794}
  • Loading branch information
jdoerrie authored and Commit bot committed Apr 7, 2017
1 parent 2c6775c commit e067999
Show file tree
Hide file tree
Showing 86 changed files with 214 additions and 189 deletions.
2 changes: 1 addition & 1 deletion base/json/json_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ std::unique_ptr<Value> JSONParser::ConsumeLiteral() {
return nullptr;
}
NextNChars(kNullLen - 1);
return Value::CreateNullValue();
return MakeUnique<Value>();
}
default:
ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
Expand Down
2 changes: 1 addition & 1 deletion base/json/json_writer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TEST(JSONWriterTest, BasicTypes) {
std::string output_js;

// Test null.
EXPECT_TRUE(JSONWriter::Write(*Value::CreateNullValue(), &output_js));
EXPECT_TRUE(JSONWriter::Write(Value(), &output_js));
EXPECT_EQ("null", output_js);

// Test empty dict.
Expand Down
3 changes: 2 additions & 1 deletion base/test/values_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>

#include "base/json/json_reader.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ std::unique_ptr<Value> ParseJson(base::StringPiece json) {
json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg);
if (!result) {
ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
result = Value::CreateNullValue();
result = MakeUnique<Value>();
}
return result;
}
Expand Down
7 changes: 1 addition & 6 deletions base/values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node) {

} // namespace

// static
std::unique_ptr<Value> Value::CreateNullValue() {
return WrapUnique(new Value(Type::NONE));
}

// static
std::unique_ptr<BinaryValue> BinaryValue::CreateWithCopiedBuffer(
const char* buffer,
Expand Down Expand Up @@ -1091,7 +1086,7 @@ bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) {
if (index >= list_->size()) {
// Pad out any intermediate indexes with null settings
while (index > list_->size())
Append(CreateNullValue());
Append(MakeUnique<Value>());
Append(std::move(in_value));
} else {
// TODO(dcheng): remove this DCHECK once the raw pointer version is removed?
Expand Down
4 changes: 1 addition & 3 deletions base/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class BASE_EXPORT Value {
// Note: Do not add more types. See the file-level comment above for why.
};

static std::unique_ptr<Value> CreateNullValue();

// For situations where you want to keep ownership of your buffer, this
// factory method creates a new BinaryValue by copying the contents of the
// buffer that's passed in.
Expand Down Expand Up @@ -178,7 +176,7 @@ class BASE_EXPORT Value {
bool Equals(const Value* other) const;

// Compares if two Value objects have equal contents. Can handle NULLs.
// NULLs are considered equal but different from Value::CreateNullValue().
// NULLs are considered equal but different from Value(Value::Type::NONE).
// DEPRECATED, use operator==(const Value& lhs, const Value& rhs) instead.
// TODO(crbug.com/646113): Delete this and migrate callsites.
static bool Equals(const Value* a, const Value* b);
Expand Down
26 changes: 13 additions & 13 deletions base/values_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ TEST(ValuesTest, DictionaryRemoval) {

TEST(ValuesTest, DictionaryWithoutPathExpansion) {
DictionaryValue dict;
dict.Set("this.is.expanded", Value::CreateNullValue());
dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
dict.Set("this.is.expanded", MakeUnique<Value>());
dict.SetWithoutPathExpansion("this.isnt.expanded", MakeUnique<Value>());

EXPECT_FALSE(dict.HasKey("this.is.expanded"));
EXPECT_TRUE(dict.HasKey("this"));
Expand All @@ -607,8 +607,8 @@ TEST(ValuesTest, DictionaryWithoutPathExpansion) {
// TODO(estade): remove.
TEST(ValuesTest, DictionaryWithoutPathExpansionDeprecated) {
DictionaryValue dict;
dict.Set("this.is.expanded", Value::CreateNullValue());
dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
dict.Set("this.is.expanded", MakeUnique<Value>());
dict.SetWithoutPathExpansion("this.isnt.expanded", MakeUnique<Value>());

EXPECT_FALSE(dict.HasKey("this.is.expanded"));
EXPECT_TRUE(dict.HasKey("this"));
Expand Down Expand Up @@ -654,7 +654,7 @@ TEST(ValuesTest, DictionaryRemovePath) {

TEST(ValuesTest, DeepCopy) {
DictionaryValue original_dict;
std::unique_ptr<Value> scoped_null = Value::CreateNullValue();
auto scoped_null = MakeUnique<Value>();
Value* original_null = scoped_null.get();
original_dict.Set("null", std::move(scoped_null));
std::unique_ptr<Value> scoped_bool(new Value(true));
Expand Down Expand Up @@ -802,8 +802,8 @@ TEST(ValuesTest, DeepCopy) {
}

TEST(ValuesTest, Equals) {
std::unique_ptr<Value> null1(Value::CreateNullValue());
std::unique_ptr<Value> null2(Value::CreateNullValue());
auto null1 = MakeUnique<Value>();
auto null2 = MakeUnique<Value>();
EXPECT_NE(null1.get(), null2.get());
EXPECT_EQ(*null1, *null2);

Expand All @@ -816,14 +816,14 @@ TEST(ValuesTest, Equals) {
dv.SetDouble("c", 2.5);
dv.SetString("d1", "string");
dv.SetString("d2", ASCIIToUTF16("http://google.com"));
dv.Set("e", Value::CreateNullValue());
dv.Set("e", MakeUnique<Value>());

auto copy = MakeUnique<DictionaryValue>(dv);
EXPECT_EQ(dv, *copy);

std::unique_ptr<ListValue> list(new ListValue);
ListValue* original_list = list.get();
list->Append(Value::CreateNullValue());
list->Append(MakeUnique<Value>());
list->Append(WrapUnique(new DictionaryValue));
auto list_copy = MakeUnique<Value>(*list);

Expand All @@ -844,8 +844,8 @@ TEST(ValuesTest, Equals) {
}

TEST(ValuesTest, StaticEquals) {
std::unique_ptr<Value> null1(Value::CreateNullValue());
std::unique_ptr<Value> null2(Value::CreateNullValue());
auto null1 = MakeUnique<Value>();
auto null2 = MakeUnique<Value>();
EXPECT_TRUE(Value::Equals(null1.get(), null2.get()));
EXPECT_TRUE(Value::Equals(NULL, NULL));

Expand All @@ -859,7 +859,7 @@ TEST(ValuesTest, StaticEquals) {
EXPECT_FALSE(Value::Equals(i42.get(), NULL));
EXPECT_FALSE(Value::Equals(NULL, i42.get()));

// NULL and Value::CreateNullValue() are intentionally different: We need
// NULL and MakeUnique<Value>() are intentionally different: We need
// support for NULL as a return value for "undefined" without caring for
// ownership of the pointer.
EXPECT_FALSE(Value::Equals(null1.get(), NULL));
Expand Down Expand Up @@ -988,7 +988,7 @@ TEST(ValuesTest, Comparisons) {

TEST(ValuesTest, DeepCopyCovariantReturnTypes) {
DictionaryValue original_dict;
std::unique_ptr<Value> scoped_null(Value::CreateNullValue());
auto scoped_null = MakeUnique<Value>();
Value* original_null = scoped_null.get();
original_dict.Set("null", std::move(scoped_null));
std::unique_ptr<Value> scoped_bool(new Value(true));
Expand Down
3 changes: 2 additions & 1 deletion cc/benchmarks/invalidation_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>
#include <limits>

#include "base/memory/ptr_util.h"
#include "base/rand_util.h"
#include "base/values.h"
#include "cc/layers/layer.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ bool InvalidationBenchmark::ProcessMessage(std::unique_ptr<base::Value> value) {
if (message->HasKey("notify_done")) {
message->GetBoolean("notify_done", &notify_done);
if (notify_done)
NotifyDone(base::Value::CreateNullValue());
NotifyDone(base::MakeUnique<base::Value>());
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool FileManagerPrivateRequestWebStoreAccessTokenFunction::RunAsync() {
"CWS OAuth token fetch failed. OAuth2TokenService can't "
"be retrieved.");
}
SetResult(base::Value::CreateNullValue());
SetResult(base::MakeUnique<base::Value>());
return false;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ void FileManagerPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched(
"CWS OAuth token fetch failed. (DriveApiErrorCode: %s)",
google_apis::DriveApiErrorCodeToString(code).c_str());
}
SetResult(base::Value::CreateNullValue());
SetResult(base::MakeUnique<base::Value>());
SendResponse(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void NetworkConfigurationPolicyHandler::PrepareForDisplaying(
std::unique_ptr<base::Value> sanitized_config =
SanitizeNetworkConfig(entry->value.get());
if (!sanitized_config)
sanitized_config = base::Value::CreateNullValue();
sanitized_config = base::MakeUnique<base::Value>();

policies->Set(policy_name(), entry->level, entry->scope, entry->source,
std::move(sanitized_config), nullptr);
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/devtools/devtools_file_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/md5.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/value_conversions.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -385,7 +386,7 @@ void DevToolsFileHelper::AddUserConfirmedFileSystem(
prefs::kDevToolsFileSystemPaths);
base::DictionaryValue* file_systems_paths_value = update.Get();
file_systems_paths_value->SetWithoutPathExpansion(
file_system_path, base::Value::CreateNullValue());
file_system_path, base::MakeUnique<base::Value>());
}

std::vector<DevToolsFileHelper::FileSystem>
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/extensions/api/cookies/cookies_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
Expand Down Expand Up @@ -258,7 +259,7 @@ void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) {

// The cookie doesn't exist; return null.
if (!results_)
SetResult(base::Value::CreateNullValue());
SetResult(base::MakeUnique<base::Value>());

bool rv = BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <utility>

#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ std::unique_ptr<base::Value> SettingsPrivateDelegate::GetPref(
std::unique_ptr<api::settings_private::PrefObject> pref =
prefs_util_->GetPref(name);
if (!pref)
return base::Value::CreateNullValue();
return base::MakeUnique<base::Value>();
return pref->ToValue();
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/api/tabs/tabs_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ ExtensionFunction::ResponseAction WindowsCreateFunction::Run() {
!browser_context()->IsOffTheRecord() && !include_incognito()) {
// Don't expose incognito windows if extension itself works in non-incognito
// profile and CanCrossIncognito isn't allowed.
result = base::Value::CreateNullValue();
result = base::MakeUnique<base::Value>();
} else {
result = controller->CreateWindowValueWithTabs(extension());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"

#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h"
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.h"
Expand Down Expand Up @@ -476,7 +477,7 @@ ExtensionFunction::ResponseAction WebNavigationGetFrameFunction::Run() {
include_incognito(), nullptr, nullptr,
&web_contents, nullptr) ||
!web_contents) {
return RespondNow(OneArgument(base::Value::CreateNullValue()));
return RespondNow(OneArgument(base::MakeUnique<base::Value>()));
}

WebNavigationTabObserver* observer =
Expand All @@ -490,11 +491,11 @@ ExtensionFunction::ResponseAction WebNavigationGetFrameFunction::Run() {
ExtensionApiFrameIdMap::Get()->GetRenderFrameHostById(web_contents,
frame_id);
if (!frame_navigation_state.IsValidFrame(render_frame_host))
return RespondNow(OneArgument(base::Value::CreateNullValue()));
return RespondNow(OneArgument(base::MakeUnique<base::Value>()));

GURL frame_url = frame_navigation_state.GetUrl(render_frame_host);
if (!frame_navigation_state.IsValidUrl(frame_url))
return RespondNow(OneArgument(base::Value::CreateNullValue()));
return RespondNow(OneArgument(base::MakeUnique<base::Value>()));

GetFrame::Results::Details frame_details;
frame_details.url = frame_url.spec();
Expand All @@ -516,7 +517,7 @@ ExtensionFunction::ResponseAction WebNavigationGetAllFramesFunction::Run() {
include_incognito(), nullptr, nullptr,
&web_contents, nullptr) ||
!web_contents) {
return RespondNow(OneArgument(base::Value::CreateNullValue()));
return RespondNow(OneArgument(base::MakeUnique<base::Value>()));
}

WebNavigationTabObserver* observer =
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/policy/test/local_policy_test_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -245,7 +246,7 @@ bool LocalPolicyTestServer::GenerateAdditionalArguments(
arguments->SetString("policy-key", policy_key_.AsUTF8Unsafe());
if (automatic_rotation_of_signing_keys_enabled_) {
arguments->Set("rotate-policy-keys-automatically",
base::Value::CreateNullValue());
base::MakeUnique<base::Value>());
}
if (server_data_dir_.IsValid()) {
arguments->SetString("data-dir", server_data_dir_.GetPath().AsUTF8Unsafe());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "chrome/browser/safe_browsing/incident_reporting/incident.h"
#include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ class PreferenceValidationDelegateValues
using base::Value;
switch (value_type) {
case Value::Type::NONE:
return Value::CreateNullValue();
return base::MakeUnique<base::Value>();
case Value::Type::BOOLEAN:
return std::unique_ptr<Value>(new base::Value(false));
case Value::Type::INTEGER:
Expand Down Expand Up @@ -212,7 +213,7 @@ class PreferenceValidationDelegateNoIncident

TEST_P(PreferenceValidationDelegateNoIncident, Atomic) {
instance_->OnAtomicPreferenceValidation(
kPrefPath, base::Value::CreateNullValue(), value_state_,
kPrefPath, base::MakeUnique<base::Value>(), value_state_,
external_validation_value_state_, false /* is_personal */);
EXPECT_EQ(0U, incidents_.size());
}
Expand Down Expand Up @@ -255,7 +256,7 @@ class PreferenceValidationDelegateWithIncident

TEST_P(PreferenceValidationDelegateWithIncident, Atomic) {
instance_->OnAtomicPreferenceValidation(
kPrefPath, base::Value::CreateNullValue(), value_state_,
kPrefPath, base::MakeUnique<base::Value>(), value_state_,
external_validation_value_state_, is_personal_);
ASSERT_EQ(1U, incidents_.size());
std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_handler.h"

#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "content/public/browser/web_ui.h"

Expand Down Expand Up @@ -50,7 +51,7 @@ void FirstRunHandler::ShowStepPointingTo(const std::string& name,
int x,
int y,
int offset) {
std::unique_ptr<base::Value> null = base::Value::CreateNullValue();
auto null = base::MakeUnique<base::Value>();
base::ListValue point_with_offset;
point_with_offset.AppendInteger(x);
point_with_offset.AppendInteger(y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void LocalDiscoveryUIHandler::DeviceChanged(
web_ui()->CallJavascriptFunctionUnsafe(
"local_discovery.onUnregisteredDeviceUpdate", service_key, info);
} else {
std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
auto null_value = base::MakeUnique<base::Value>();

web_ui()->CallJavascriptFunctionUnsafe(
"local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value);
Expand All @@ -370,7 +370,7 @@ void LocalDiscoveryUIHandler::DeviceChanged(

void LocalDiscoveryUIHandler::DeviceRemoved(const std::string& name) {
device_descriptions_.erase(name);
std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
auto null_value = base::MakeUnique<base::Value>();
base::Value name_value(kKeyPrefixMDns + name);

web_ui()->CallJavascriptFunctionUnsafe(
Expand Down
Loading

0 comments on commit e067999

Please sign in to comment.