Reland: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions
The compilation failed on the original CL
https://codereview.chromium.org/2777063003/ because of compiler bug described
in https://crbug.com/703565: to downcast unique_ptr<DictionaryValue>, some
compilers require std::move, harming RVO.
Patch set 1 here is the reverted patch from issue 2777063003 at patchset 80001
(http://crrev.com/2777063003#ps80001).
Following patch sets are working around the compiler issue.
Original issue description follows:
Passing ownership of base::Value into API methods DictionaryValue::Set,
DictionaryValue::SetWithoutPathExpansion, and ListValue::Set through raw
pointers is deprecated, can hide bugs and should be done via unique_ptr
instead.
Therefore, this CL migrates c/b/chromeos, c/b/extensions and a bunch of related
files to use the unique_ptr-based API.
BUG=697817
[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Review-Url: https://codereview.chromium.org/2811673002
Cr-Commit-Position: refs/heads/master@{#463222}
diff --git a/chrome/browser/prefs/tracked/pref_hash_browsertest.cc b/chrome/browser/prefs/tracked/pref_hash_browsertest.cc
index 513998b..ec497040 100644
--- a/chrome/browser/prefs/tracked/pref_hash_browsertest.cc
+++ b/chrome/browser/prefs/tracked/pref_hash_browsertest.cc
@@ -4,6 +4,7 @@
#include <memory>
#include <string>
+#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
@@ -11,6 +12,7 @@
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
@@ -885,9 +887,9 @@
// Drop a fake extension (for the purpose of this test, dropped settings
// don't need to be valid extension settings).
- base::DictionaryValue* fake_extension = new base::DictionaryValue;
+ auto fake_extension = base::MakeUnique<base::DictionaryValue>();
fake_extension->SetString("name", "foo");
- extensions_dict->Set(std::string(32, 'a'), fake_extension);
+ extensions_dict->Set(std::string(32, 'a'), std::move(fake_extension));
}
void VerifyReactionToPrefAttack() override {