diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-29 19:59:08 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-29 19:59:08 +0000 |
commit | b4cebf87816cde49f6d4991ffa254e5ead97703b (patch) | |
tree | fb12e4b464a43af846f30bbd0dbe9484150373b0 /chrome | |
parent | 45ce59f19161b517c04a4e3bcd0890b938382b06 (diff) | |
download | chromium_src-b4cebf87816cde49f6d4991ffa254e5ead97703b.zip chromium_src-b4cebf87816cde49f6d4991ffa254e5ead97703b.tar.gz chromium_src-b4cebf87816cde49f6d4991ffa254e5ead97703b.tar.bz2 |
Change the signature of JSONReader::Read() and related
methods to be more friendly to use with scoped_ptr. Change
all the callsites.
Review URL: http://codereview.chromium.org/16270
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 15 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_storage.cc | 2 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_host_impl.cpp | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.cc | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_host.cc | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 7 | ||||
-rw-r--r-- | chrome/browser/page_state.cc | 13 | ||||
-rw-r--r-- | chrome/common/json_value_serializer.cc | 11 | ||||
-rw-r--r-- | chrome/common/json_value_serializer.h | 16 | ||||
-rw-r--r-- | chrome/common/json_value_serializer_perftest.cc | 9 | ||||
-rw-r--r-- | chrome/common/json_value_serializer_unittest.cc | 96 | ||||
-rw-r--r-- | chrome/common/pref_service.cc | 42 | ||||
-rw-r--r-- | chrome/common/pref_service_uitest.cc | 8 | ||||
-rw-r--r-- | chrome/common/pref_service_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 11 | ||||
-rw-r--r-- | chrome/test/automation/tab_proxy.cc | 4 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.cc | 10 |
17 files changed, 121 insertions, 149 deletions
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 32c2fb2..17bdcc8 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -129,13 +129,14 @@ void SearchProvider::OnURLFetchComplete(const URLFetcher* source, } } - JSONStringValueSerializer deserializer(json_data); - deserializer.set_allow_trailing_comma(true); - Value* root_val = NULL; - have_suggest_results_ = status.is_success() && (response_code == 200) && - deserializer.Deserialize(&root_val, NULL) && - ParseSuggestResults(root_val); - delete root_val; + if (status.is_success() && response_code == 200) { + JSONStringValueSerializer deserializer(json_data); + deserializer.set_allow_trailing_comma(true); + scoped_ptr<Value> root_val(deserializer.Deserialize(NULL)); + have_suggest_results_ = + root_val.get() && ParseSuggestResults(root_val.get()); + } + ConvertResultsToAutocompleteMatches(); listener_->OnProviderUpdate(!suggest_results_.empty()); } diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc index e6e9a50..23f47b4 100644 --- a/chrome/browser/bookmarks/bookmark_storage.cc +++ b/chrome/browser/bookmarks/bookmark_storage.cc @@ -167,7 +167,7 @@ void BookmarkStorageBackend::Read(scoped_refptr<BookmarkStorage> service, Value* root = NULL; if (bookmark_file_exists) { JSONFileValueSerializer serializer(path); - serializer.Deserialize(&root, NULL); + root = serializer.Deserialize(NULL); } // BookmarkStorage takes ownership of root. diff --git a/chrome/browser/debugger/debugger_host_impl.cpp b/chrome/browser/debugger/debugger_host_impl.cpp index c2eb41d..32c13fd 100644 --- a/chrome/browser/debugger/debugger_host_impl.cpp +++ b/chrome/browser/debugger/debugger_host_impl.cpp @@ -83,8 +83,8 @@ void DebuggerHostImpl::Debug(TabContents* tab) { void DebuggerHostImpl::DebugMessage(const std::wstring& msg) { - Value* msg_value = NULL; - if (!JSONReader::Read(WideToUTF8(msg), &msg_value, false)) { + Value* msg_value = JSONReader::Read(WideToUTF8(msg), false); + if (!msg_value) { msg_value = Value::CreateStringValue(L"Message parse error!"); } ListValue* argv = new ListValue; diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 4fe9070..e7f2765 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -31,9 +31,10 @@ void DOMUI::ProcessDOMUIMessage(const std::string& message, return; // Convert the content JSON into a Value. - Value* value = NULL; + scoped_ptr<Value> value; if (!content.empty()) { - if (!JSONReader::Read(content, &value, false)) { + value.reset(JSONReader::Read(content, false)); + if (!value.get()) { // The page sent us something that we didn't understand. // This probably indicates a programming error. NOTREACHED(); @@ -42,8 +43,7 @@ void DOMUI::ProcessDOMUIMessage(const std::string& message, } // Forward this message and content on. - callback->second->Run(value); - delete value; + callback->second->Run(value.get()); } void DOMUI::CallJavascriptFunction(const std::wstring& function_name, diff --git a/chrome/browser/dom_ui/dom_ui_host.cc b/chrome/browser/dom_ui/dom_ui_host.cc index d9d0333..ff2ca1e 100644 --- a/chrome/browser/dom_ui/dom_ui_host.cc +++ b/chrome/browser/dom_ui/dom_ui_host.cc @@ -78,9 +78,10 @@ void DOMUIHost::ProcessDOMUIMessage(const std::string& message, return; // Convert the content JSON into a Value. - Value* value = NULL; + scoped_ptr<Value> value; if (!content.empty()) { - if (!JSONReader::Read(content, &value, false)) { + value.reset(JSONReader::Read(content, false)); + if (!value.get()) { // The page sent us something that we didn't understand. // This probably indicates a programming error. NOTREACHED(); @@ -89,8 +90,7 @@ void DOMUIHost::ProcessDOMUIMessage(const std::string& message, } // Forward this message and content on. - callback->second->Run(value); - delete value; + callback->second->Run(value.get()); } WebPreferences DOMUIHost::GetWebkitPrefs() { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index cd0397c..f38ff04 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -88,15 +88,14 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( } JSONFileValueSerializer serializer(manifest_path.ToWStringHack()); - Value* root = NULL; std::string error; - if (!serializer.Deserialize(&root, &error)) { + scoped_ptr<Value> root(serializer.Deserialize(&error)); + if (!root.get()) { ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(), error); continue; } - scoped_ptr<Value> scoped_root(root); if (!root->IsType(Value::TYPE_DICTIONARY)) { ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(), Extension::kInvalidManifestError); @@ -104,7 +103,7 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( } scoped_ptr<Extension> extension(new Extension(child_path)); - if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root), + if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root.get()), &error)) { ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(), error); diff --git a/chrome/browser/page_state.cc b/chrome/browser/page_state.cc index f47a4cf..1d52ffb 100644 --- a/chrome/browser/page_state.cc +++ b/chrome/browser/page_state.cc @@ -40,16 +40,15 @@ void PageState::InitWithBytes(const std::string& bytes) { state_.reset(new DictionaryValue); JSONStringValueSerializer serializer(bytes); - Value* root = NULL; + scoped_ptr<Value> root(serializer.Deserialize(NULL)); - if (!serializer.Deserialize(&root, NULL)) + if (!root.get()) { NOTREACHED(); - - if (root != NULL && root->GetType() == Value::TYPE_DICTIONARY) { - state_.reset(static_cast<DictionaryValue*>(root)); - } else if (root) { - delete root; + return; } + + if (root->GetType() == Value::TYPE_DICTIONARY) + state_.reset(static_cast<DictionaryValue*>(root.release())); } void PageState::GetByteRepresentation(std::string* out) const { diff --git a/chrome/common/json_value_serializer.cc b/chrome/common/json_value_serializer.cc index 82938ec..54afe7a 100644 --- a/chrome/common/json_value_serializer.cc +++ b/chrome/common/json_value_serializer.cc @@ -21,13 +21,11 @@ bool JSONStringValueSerializer::Serialize(const Value& root) { return true; } -bool JSONStringValueSerializer::Deserialize(Value** root, - std::string* error_message) { +Value* JSONStringValueSerializer::Deserialize(std::string* error_message) { if (!json_string_) return false; - return JSONReader::ReadAndReturnError(*json_string_, root, - allow_trailing_comma_, + return JSONReader::ReadAndReturnError(*json_string_, allow_trailing_comma_, error_message); } @@ -50,13 +48,12 @@ bool JSONFileValueSerializer::Serialize(const Value& root) { return true; } -bool JSONFileValueSerializer::Deserialize(Value** root, - std::string* error_message) { +Value* JSONFileValueSerializer::Deserialize(std::string* error_message) { std::string json_string; if (!file_util::ReadFileToString(json_file_path_, &json_string)) { return false; } JSONStringValueSerializer serializer(json_string); - return serializer.Deserialize(root, error_message); + return serializer.Deserialize(error_message); } diff --git a/chrome/common/json_value_serializer.h b/chrome/common/json_value_serializer.h index 2e581ee..7a51528 100644 --- a/chrome/common/json_value_serializer.h +++ b/chrome/common/json_value_serializer.h @@ -39,12 +39,9 @@ class JSONStringValueSerializer : public ValueSerializer { // Attempt to deserialize the data structure encoded in the string passed // in to the constructor into a structure of Value objects. If the return - // value is true, the |root| parameter will be set to point to a new Value - // object that corresponds to the values represented in the string. The - // caller takes ownership of the returned Value objects. Otherwise, the root - // value will be changed and if |error_message| is non-null, it will contain + // value is NULL and |error_message| is non-null, |error-message| will contain // a string describing the error. - bool Deserialize(Value** root, std::string* error_message); + Value* Deserialize(std::string* error_message); void set_pretty_print(bool new_value) { pretty_print_ = new_value; } bool pretty_print() { return pretty_print_; } @@ -86,12 +83,9 @@ class JSONFileValueSerializer : public ValueSerializer { // Attempt to deserialize the data structure encoded in the file passed // in to the constructor into a structure of Value objects. If the return - // value is true, the |root| parameter will be set to point to a new Value - // object that corresponds to the values represented in the file. The - // caller takes ownership of the returned Value objects. Otherwise, the root - // value will be changed and if |error_message| is non-null, it will contain - // a string describing the error. - bool Deserialize(Value** root, std::string* error_message); + // value is NULL, and if |error_message| is non-null, |error_message| will + // contain a string describing the error. + Value* Deserialize(std::string* error_message); private: std::wstring json_file_path_; diff --git a/chrome/common/json_value_serializer_perftest.cc b/chrome/common/json_value_serializer_perftest.cc index 6570d34..bef8fbe 100644 --- a/chrome/common/json_value_serializer_perftest.cc +++ b/chrome/common/json_value_serializer_perftest.cc @@ -52,10 +52,9 @@ TEST_F(JSONValueSerializerTests, Reading) { PerfTimeLogger chrome_timer("chrome"); for (int i = 0; i < kIterations; ++i) { for (size_t j = 0; j < test_cases_.size(); ++j) { - Value* root = NULL; JSONStringValueSerializer reader(test_cases_[j]); - ASSERT_TRUE(reader.Deserialize(&root, NULL)); - delete root; + scoped_ptr<Value> root(reader.Deserialize(NULL)); + ASSERT_TRUE(root.get()); } } chrome_timer.Done(); @@ -67,9 +66,9 @@ TEST_F(JSONValueSerializerTests, CompactWriting) { // Convert test cases to Value objects. std::vector<Value*> test_cases; for (size_t i = 0; i < test_cases_.size(); ++i) { - Value* root = NULL; JSONStringValueSerializer reader(test_cases_[i]); - ASSERT_TRUE(reader.Deserialize(&root, NULL)); + Value* root = reader.Deserialize(NULL); + ASSERT_TRUE(root); test_cases.push_back(root); } diff --git a/chrome/common/json_value_serializer_unittest.cc b/chrome/common/json_value_serializer_unittest.cc index 3dd175b..30f6320 100644 --- a/chrome/common/json_value_serializer_unittest.cc +++ b/chrome/common/json_value_serializer_unittest.cc @@ -16,13 +16,12 @@ TEST(JSONValueSerializerTest, Roundtrip) { const std::string original_serialization = "{\"bool\":true,\"int\":42,\"list\":[1,2],\"null\":null,\"real\":3.14}"; - Value* root = NULL; JSONStringValueSerializer serializer(original_serialization); - ASSERT_TRUE(serializer.Deserialize(&root, NULL)); - ASSERT_TRUE(root); + scoped_ptr<Value> root(serializer.Deserialize(NULL)); + ASSERT_TRUE(root.get()); ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* root_dict = static_cast<DictionaryValue*>(root); + DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); Value* null_value = NULL; ASSERT_TRUE(root_dict->Get(L"null", &null_value)); @@ -61,8 +60,6 @@ TEST(JSONValueSerializerTest, Roundtrip) { " \"real\": 3.14\r\n" "}\r\n"; ASSERT_EQ(pretty_serialization, test_serialization); - - delete root; } TEST(JSONValueSerializerTest, StringEscape) { @@ -119,14 +116,14 @@ TEST(JSONValueSerializerTest, UnicodeStrings) { ASSERT_EQ(expected, actual); // escaped ascii text -> json - Value* deserial_root = NULL; JSONStringValueSerializer deserializer(expected); - ASSERT_TRUE(deserializer.Deserialize(&deserial_root, NULL)); - DictionaryValue* dict_root = static_cast<DictionaryValue*>(deserial_root); + scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL)); + ASSERT_TRUE(deserial_root.get()); + DictionaryValue* dict_root = + static_cast<DictionaryValue*>(deserial_root.get()); std::wstring web_value; ASSERT_TRUE(dict_root->GetString(L"web", &web_value)); ASSERT_EQ(test, web_value); - delete deserial_root; } TEST(JSONValueSerializerTest, HexStrings) { @@ -143,57 +140,53 @@ TEST(JSONValueSerializerTest, HexStrings) { ASSERT_EQ(expected, actual); // escaped ascii text -> json - Value* deserial_root = NULL; JSONStringValueSerializer deserializer(expected); - ASSERT_TRUE(deserializer.Deserialize(&deserial_root, NULL)); - DictionaryValue* dict_root = static_cast<DictionaryValue*>(deserial_root); + scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL)); + ASSERT_TRUE(deserial_root.get()); + DictionaryValue* dict_root = + static_cast<DictionaryValue*>(deserial_root.get()); std::wstring test_value; ASSERT_TRUE(dict_root->GetString(L"test", &test_value)); ASSERT_EQ(test, test_value); - delete deserial_root; // Test converting escaped regular chars - deserial_root = NULL; std::string escaped_chars = "{\"test\":\"\\x67\\x6f\"}"; JSONStringValueSerializer deserializer2(escaped_chars); - ASSERT_TRUE(deserializer2.Deserialize(&deserial_root, NULL)); - dict_root = static_cast<DictionaryValue*>(deserial_root); + deserial_root.reset(deserializer2.Deserialize(NULL)); + ASSERT_TRUE(deserial_root.get()); + dict_root = static_cast<DictionaryValue*>(deserial_root.get()); ASSERT_TRUE(dict_root->GetString(L"test", &test_value)); ASSERT_EQ(std::wstring(L"go"), test_value); - delete deserial_root; } TEST(JSONValueSerializerTest, AllowTrailingComma) { - Value* root = NULL; - Value* root_expected = NULL; + scoped_ptr<Value> root; + scoped_ptr<Value> root_expected; std::string test_with_commas("{\"key\": [true,],}"); std::string test_no_commas("{\"key\": [true]}"); JSONStringValueSerializer serializer(test_with_commas); serializer.set_allow_trailing_comma(true); JSONStringValueSerializer serializer_expected(test_no_commas); - ASSERT_TRUE(serializer.Deserialize(&root, NULL)); - ASSERT_TRUE(serializer_expected.Deserialize(&root_expected, NULL)); - ASSERT_TRUE(root->Equals(root_expected)); - - delete root; - delete root_expected; + root.reset(serializer.Deserialize(NULL)); + ASSERT_TRUE(root.get()); + root_expected.reset(serializer_expected.Deserialize(NULL)); + ASSERT_TRUE(root_expected.get()); + ASSERT_TRUE(root->Equals(root_expected.get())); } namespace { void ValidateJsonList(const std::string& json) { - Value* root = NULL; - ASSERT_TRUE(JSONReader::Read(json, &root, false)); - ASSERT_TRUE(root && root->IsType(Value::TYPE_LIST)); - ListValue* list = static_cast<ListValue*>(root); + scoped_ptr<Value> root(JSONReader::Read(json, false)); + ASSERT_TRUE(root.get() && root->IsType(Value::TYPE_LIST)); + ListValue* list = static_cast<ListValue*>(root.get()); ASSERT_EQ(1U, list->GetSize()); Value* elt = NULL; ASSERT_TRUE(list->Get(0, &elt)); int value = 0; ASSERT_TRUE(elt && elt->GetAsInteger(&value)); ASSERT_EQ(1, value); - delete root; } } // namespace @@ -206,25 +199,26 @@ TEST(JSONValueSerializerTest, JSONReaderComments) { ValidateJsonList("[ 1 /* one */ ] /* end */"); ValidateJsonList("[ 1 //// ,2\r\n ]"); - Value* root = NULL; + scoped_ptr<Value> root; + // It's ok to have a comment in a string. - ASSERT_TRUE(JSONReader::Read("[\"// ok\\n /* foo */ \"]", &root, false)); - ASSERT_TRUE(root && root->IsType(Value::TYPE_LIST)); - ListValue* list = static_cast<ListValue*>(root); + root.reset(JSONReader::Read("[\"// ok\\n /* foo */ \"]", false)); + ASSERT_TRUE(root.get() && root->IsType(Value::TYPE_LIST)); + ListValue* list = static_cast<ListValue*>(root.get()); ASSERT_EQ(1U, list->GetSize()); Value* elt = NULL; ASSERT_TRUE(list->Get(0, &elt)); std::wstring value; ASSERT_TRUE(elt && elt->GetAsString(&value)); ASSERT_EQ(L"// ok\n /* foo */ ", value); - delete root; - root = NULL; // You can't nest comments. - ASSERT_FALSE(JSONReader::Read("/* /* inner */ outer */ [ 1 ]", &root, false)); + root.reset(JSONReader::Read("/* /* inner */ outer */ [ 1 ]", false)); + ASSERT_FALSE(root.get()); // Not a open comment token. - ASSERT_FALSE(JSONReader::Read("/ * * / [1]", &root, false)); + root.reset(JSONReader::Read("/ * * / [1]", false)); + ASSERT_FALSE(root.get()); } namespace { @@ -261,13 +255,13 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) { ASSERT_TRUE(file_util::PathExists(original_file_path)); JSONFileValueSerializer deserializer(original_file_path); - Value* root; - ASSERT_TRUE(deserializer.Deserialize(&root, NULL)); + scoped_ptr<Value> root; + root.reset(deserializer.Deserialize(NULL)); - ASSERT_TRUE(root); + ASSERT_TRUE(root.get()); ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* root_dict = static_cast<DictionaryValue*>(root); + DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); Value* null_value = NULL; ASSERT_TRUE(root_dict->Get(L"null", &null_value)); @@ -298,8 +292,6 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) { // Now compare file contents. EXPECT_TRUE(file_util::ContentsEqual(original_file_path, written_file_path)); EXPECT_TRUE(file_util::Delete(written_file_path, false)); - - delete root; } TEST_F(JSONFileValueSerializerTest, RoundtripNested) { @@ -311,8 +303,9 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) { ASSERT_TRUE(file_util::PathExists(original_file_path)); JSONFileValueSerializer deserializer(original_file_path); - Value* root; - ASSERT_TRUE(deserializer.Deserialize(&root, NULL)); + scoped_ptr<Value> root; + root.reset(deserializer.Deserialize(NULL)); + ASSERT_TRUE(root.get()); // Now try writing. std::wstring written_file_path = test_dir_; @@ -326,8 +319,6 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) { // Now compare file contents. EXPECT_TRUE(file_util::ContentsEqual(original_file_path, written_file_path)); EXPECT_TRUE(file_util::Delete(written_file_path, false)); - - delete root; } TEST_F(JSONFileValueSerializerTest, NoWhitespace) { @@ -337,9 +328,8 @@ TEST_F(JSONFileValueSerializerTest, NoWhitespace) { L"serializer_test_nowhitespace.js"); ASSERT_TRUE(file_util::PathExists(source_file_path)); JSONFileValueSerializer serializer(source_file_path); - Value* root; - ASSERT_TRUE(serializer.Deserialize(&root, NULL)); - ASSERT_TRUE(root); - delete root; + scoped_ptr<Value> root; + root.reset(serializer.Deserialize(NULL)); + ASSERT_TRUE(root.get()); } #endif // defined(OS_WIN) diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc index 8f3322a..870e79e 100644 --- a/chrome/common/pref_service.cc +++ b/chrome/common/pref_service.cc @@ -136,38 +136,34 @@ bool PrefService::LoadPersistentPrefs(const std::wstring& file_path) { DCHECK(CalledOnValidThread()); JSONFileValueSerializer serializer(file_path); - Value* root = NULL; - if (serializer.Deserialize(&root, NULL)) { - // Preferences should always have a dictionary root. - if (!root->IsType(Value::TYPE_DICTIONARY)) { - delete root; - return false; - } + scoped_ptr<Value> root(serializer.Deserialize(NULL)); + if (!root.get()) + return false; - persistent_.reset(static_cast<DictionaryValue*>(root)); - return true; - } + // Preferences should always have a dictionary root. + if (!root->IsType(Value::TYPE_DICTIONARY)) + return false; - return false; + persistent_.reset(static_cast<DictionaryValue*>(root.release())); + return true; } void PrefService::ReloadPersistentPrefs() { DCHECK(CalledOnValidThread()); JSONFileValueSerializer serializer(pref_filename_); - Value* root; - if (serializer.Deserialize(&root, NULL)) { - // Preferences should always have a dictionary root. - if (!root->IsType(Value::TYPE_DICTIONARY)) { - delete root; - return; - } + scoped_ptr<Value> root(serializer.Deserialize(NULL)); + if (!root.get()) + return; - persistent_.reset(static_cast<DictionaryValue*>(root)); - for (PreferenceSet::iterator it = prefs_.begin(); - it != prefs_.end(); ++it) { - (*it)->root_pref_ = persistent_.get(); - } + // Preferences should always have a dictionary root. + if (!root->IsType(Value::TYPE_DICTIONARY)) + return; + + persistent_.reset(static_cast<DictionaryValue*>(root.release())); + for (PreferenceSet::iterator it = prefs_.begin(); + it != prefs_.end(); ++it) { + (*it)->root_pref_ = persistent_.get(); } } diff --git a/chrome/common/pref_service_uitest.cc b/chrome/common/pref_service_uitest.cc index b9f0774..0ecd114 100644 --- a/chrome/common/pref_service_uitest.cc +++ b/chrome/common/pref_service_uitest.cc @@ -82,13 +82,12 @@ TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { ASSERT_TRUE(file_util::PathExists(tmp_pref_file_)); JSONFileValueSerializer deserializer(tmp_pref_file_); - Value* root = NULL; - ASSERT_TRUE(deserializer.Deserialize(&root, NULL)); + scoped_ptr<Value> root(deserializer.Deserialize(NULL)); - ASSERT_TRUE(root); + ASSERT_TRUE(root.get()); ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); - DictionaryValue* root_dict = static_cast<DictionaryValue*>(root); + DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); // Retrieve the screen rect for the launched window scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); @@ -130,6 +129,5 @@ TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { ASSERT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + L".maximized", &is_maximized)); ASSERT_EQ(is_maximized, is_window_maximized); - delete root; } diff --git a/chrome/common/pref_service_unittest.cc b/chrome/common/pref_service_unittest.cc index 2baa908..e35e44a 100644 --- a/chrome/common/pref_service_unittest.cc +++ b/chrome/common/pref_service_unittest.cc @@ -155,14 +155,16 @@ TEST_F(PrefServiceTest, Overlay) { Value* transient_value; { JSONStringValueSerializer serializer(transient); - ASSERT_TRUE(serializer.Deserialize(&transient_value, NULL)); + transient_value = serializer.Deserialize(NULL); + ASSERT_TRUE(transient_value); } prefs.transient()->Set(transient_string, transient_value); Value* both_transient_value; { JSONStringValueSerializer serializer(transient); - ASSERT_TRUE(serializer.Deserialize(&both_transient_value, NULL)); + both_transient_value = serializer.Deserialize(NULL); + ASSERT_TRUE(both_transient_value); } prefs.transient()->Set(L"both", both_transient_value); diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 34d10a9..21c74dd 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -12,14 +12,13 @@ namespace { DictionaryValue* ReadJSONPrefs(const std::string& data) { JSONStringValueSerializer json(data); - Value* root; - if (!json.Deserialize(&root, NULL)) + scoped_ptr<Value> root(json.Deserialize(NULL)); + if (!root.get()) return NULL; - if (!root->IsType(Value::TYPE_DICTIONARY)) { - delete root; + if (!root->IsType(Value::TYPE_DICTIONARY)) return NULL; - } - return static_cast<DictionaryValue*>(root); + + return static_cast<DictionaryValue*>(root.release()); } bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) { diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc index f17a35de..07a3488 100644 --- a/chrome/test/automation/tab_proxy.cc +++ b/chrome/test/automation/tab_proxy.cc @@ -555,10 +555,10 @@ bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath, json.append("]"); JSONStringValueSerializer deserializer(json); - succeeded = deserializer.Deserialize(value, NULL); + *value = deserializer.Deserialize(NULL); delete response; - return succeeded; + return *value != NULL; } bool TabProxy::GetConstrainedWindowCount(int* count) const { diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 4d58e6a..e1bea1b 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -497,13 +497,11 @@ static DictionaryValue* LoadDictionaryValueFromPath(const std::wstring& path) { return NULL; JSONFileValueSerializer serializer(path); - Value* root_value = NULL; - if (serializer.Deserialize(&root_value, NULL) && - root_value->GetType() != Value::TYPE_DICTIONARY) { - delete root_value; + scoped_ptr<Value> root_value(serializer.Deserialize(NULL)); + if (!root_value.get() || root_value->GetType() != Value::TYPE_DICTIONARY) return NULL; - } - return static_cast<DictionaryValue*>(root_value); + + return static_cast<DictionaryValue*>(root_value.release()); } DictionaryValue* UITest::GetLocalState() { |