diff --git a/base/values.cc b/base/values.cc index d0058359..765cf90 100644 --- a/base/values.cc +++ b/base/values.cc
@@ -1233,13 +1233,6 @@ list_->push_back(std::move(*in_value)); } -#if !defined(OS_LINUX) && !defined(OS_MACOSX) -void ListValue::Append(Value* in_value) { - DCHECK(in_value); - Append(WrapUnique(in_value)); -} -#endif - void ListValue::AppendBoolean(bool in_value) { Append(MakeUnique<Value>(in_value)); }
diff --git a/base/values.h b/base/values.h index a18f11f..782a8ba 100644 --- a/base/values.h +++ b/base/values.h
@@ -450,10 +450,6 @@ // Appends a Value to the end of the list. void Append(std::unique_ptr<Value> in_value); -#if !defined(OS_LINUX) && !defined(OS_MACOSX) - // Deprecated version of the above. TODO(estade): remove. - void Append(Value* in_value); -#endif // Convenience forms of Append. void AppendBoolean(bool in_value);
diff --git a/chrome/browser/android/bookmarks/partner_bookmarks_shim.cc b/chrome/browser/android/bookmarks/partner_bookmarks_shim.cc index bd15315a..b1cc322 100644 --- a/chrome/browser/android/bookmarks/partner_bookmarks_shim.cc +++ b/chrome/browser/android/bookmarks/partner_bookmarks_shim.cc
@@ -5,8 +5,10 @@ #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" #include <tuple> +#include <utility> #include "base/lazy_instance.h" +#include "base/memory/ptr_util.h" #include "base/values.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" @@ -282,11 +284,11 @@ for (NodeRenamingMap::const_iterator i = node_rename_remove_map_.begin(); i != node_rename_remove_map_.end(); ++i) { - base::DictionaryValue* dict = new base::DictionaryValue(); + auto dict = base::MakeUnique<base::DictionaryValue>(); dict->SetString(kMappingUrl, i->first.url().spec()); dict->SetString(kMappingProviderTitle, i->first.provider_title()); dict->SetString(kMappingTitle, i->second); - list.Append(dict); + list.Append(std::move(dict)); } prefs_->Set(prefs::kPartnerBookmarkMappings, list); }
diff --git a/chrome/browser/notifications/notification_system_observer.cc b/chrome/browser/notifications/notification_system_observer.cc index b72bd80c..427a894 100644 --- a/chrome/browser/notifications/notification_system_observer.cc +++ b/chrome/browser/notifications/notification_system_observer.cc
@@ -5,23 +5,30 @@ #include "chrome/browser/notifications/notification_system_observer.h" #include "base/logging.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" #include "content/public/browser/notification_service.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/extension.h" NotificationSystemObserver::NotificationSystemObserver( NotificationUIManager* ui_manager) - : ui_manager_(ui_manager) { + : ui_manager_(ui_manager), extension_registry_observer_(this) { DCHECK(ui_manager_); registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, content::NotificationService::AllSources()); - registrar_.Add(this, - extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, + registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, content::NotificationService::AllSources()); registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, content::NotificationService::AllSources()); + for (auto* profile : + g_browser_process->profile_manager()->GetLoadedProfiles()) { + extension_registry_observer_.Add( + extensions::ExtensionRegistry::Get(profile)); + } } NotificationSystemObserver::~NotificationSystemObserver() { @@ -31,21 +38,37 @@ int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_APP_TERMINATING) { - ui_manager_->StartShutdown(); - } else if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { - if (!content::Source<Profile>(source)->IsOffTheRecord()) { - extensions::UnloadedExtensionInfo* extension_info = - content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); - const extensions::Extension* extension = extension_info->extension; - ui_manager_->CancelAllBySourceOrigin(extension->url()); + switch (type) { + case chrome::NOTIFICATION_APP_TERMINATING: + ui_manager_->StartShutdown(); + break; + case chrome::NOTIFICATION_PROFILE_ADDED: { + Profile* profile = content::Source<Profile>(source).ptr(); + DCHECK(!profile->IsOffTheRecord()); + auto* registry = extensions::ExtensionRegistry::Get(profile); + DCHECK(!extension_registry_observer_.IsObserving(registry)); + extension_registry_observer_.Add(registry); + break; } - } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { - // We only want to remove the incognito notifications. - if (content::Source<Profile>(source)->IsOffTheRecord()) - ui_manager_->CancelAllByProfile(NotificationUIManager::GetProfileID( - content::Source<Profile>(source).ptr())); - } else { - NOTREACHED(); + case chrome::NOTIFICATION_PROFILE_DESTROYED: + // We only want to remove the incognito notifications. + if (content::Source<Profile>(source)->IsOffTheRecord()) + ui_manager_->CancelAllByProfile(NotificationUIManager::GetProfileID( + content::Source<Profile>(source).ptr())); + break; + default: + NOTREACHED(); } } + +void NotificationSystemObserver::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const extensions::Extension* extension, + extensions::UnloadedExtensionInfo::Reason reason) { + ui_manager_->CancelAllBySourceOrigin(extension->url()); +} + +void NotificationSystemObserver::OnShutdown( + extensions::ExtensionRegistry* registry) { + extension_registry_observer_.Remove(registry); +}
diff --git a/chrome/browser/notifications/notification_system_observer.h b/chrome/browser/notifications/notification_system_observer.h index 6e2eb9a..a6e0a4d6 100644 --- a/chrome/browser/notifications/notification_system_observer.h +++ b/chrome/browser/notifications/notification_system_observer.h
@@ -6,14 +6,25 @@ #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_SYSTEM_OBSERVER_H_ #include "base/macros.h" +#include "base/scoped_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "extensions/browser/extension_registry_observer.h" + +namespace content { +class BrowserContext; +} + +namespace extensions { +class ExtensionRegistry; +} class NotificationUIManager; // The content::NotificationObserver observes system status change and sends // events to NotificationUIManager. -class NotificationSystemObserver : public content::NotificationObserver { +class NotificationSystemObserver : public content::NotificationObserver, + extensions::ExtensionRegistryObserver { public: explicit NotificationSystemObserver(NotificationUIManager* ui_manager); ~NotificationSystemObserver() override; @@ -24,11 +35,22 @@ const content::NotificationSource& source, const content::NotificationDetails& details) override; + // extensions::ExtensionRegistryObserver override. + void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const extensions::Extension* extension, + extensions::UnloadedExtensionInfo::Reason reason) override; + void OnShutdown(extensions::ExtensionRegistry* registry) override; + private: // Registrar for the other kind of notifications (event signaling). content::NotificationRegistrar registrar_; NotificationUIManager* ui_manager_; + ScopedObserver<extensions::ExtensionRegistry, + extensions::ExtensionRegistryObserver> + extension_registry_observer_; + DISALLOW_COPY_AND_ASSIGN(NotificationSystemObserver); };
diff --git a/chrome/browser/notifications/notification_system_observer_unittest.cc b/chrome/browser/notifications/notification_system_observer_unittest.cc new file mode 100644 index 0000000..8f9e97c --- /dev/null +++ b/chrome/browser/notifications/notification_system_observer_unittest.cc
@@ -0,0 +1,80 @@ +// Copyright 2017 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. + +#include <memory> + +#include "base/memory/ptr_util.h" +#include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/browser/notifications/notification_system_observer.h" +#include "chrome/browser/notifications/notification_test_util.h" +#include "chrome/browser/notifications/notification_ui_manager.h" +#include "chrome/test/base/testing_browser_process.h" +#include "chrome/test/base/testing_profile_manager.h" +#include "components/crx_file/id_util.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/common/extension_builder.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { +scoped_refptr<const extensions::Extension> CreateGoodExtension( + const std::string& name) { + return extensions::ExtensionBuilder() + .SetManifest(extensions::DictionaryBuilder() + .Set("name", name) + .Set("version", "1.0") + .Build()) + .SetID(crx_file::id_util::GenerateId(name)) + .Build(); +} +} // namespace + +class NotificationSystemObserverTest : public testing::Test { + protected: + NotificationSystemObserverTest() = default; + ~NotificationSystemObserverTest() override = default; + + // testing::Test: + void SetUp() override { + profile_manager_ = base::MakeUnique<TestingProfileManager>( + TestingBrowserProcess::GetGlobal()); + ASSERT_TRUE(profile_manager_->SetUp()); + profile_ = profile_manager_->CreateTestingProfile("test-profile"); + ui_manager_ = base::MakeUnique<StubNotificationUIManager>(); + notification_observer_ = + base::MakeUnique<NotificationSystemObserver>(ui_manager_.get()); + } + + TestingProfileManager* profile_manager() { return profile_manager_.get(); } + TestingProfile* profile() { return profile_; } + StubNotificationUIManager* ui_manager() { return ui_manager_.get(); } + + private: + content::TestBrowserThreadBundle thread_bundle_; + std::unique_ptr<TestingProfileManager> profile_manager_; + TestingProfile* profile_ = nullptr; + std::unique_ptr<StubNotificationUIManager> ui_manager_; + std::unique_ptr<NotificationSystemObserver> notification_observer_; +}; + +TEST_F(NotificationSystemObserverTest, MultiProfileExtensionUnloaded) { + scoped_refptr<const extensions::Extension> extension = + CreateGoodExtension("foo"); + ASSERT_NE(extension->url(), ui_manager()->last_canceled_source()); + // Claim the extension has been unloaded. + extensions::ExtensionRegistry::Get(profile())->TriggerOnUnloaded( + extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); + // Check the NotificationUIManger has canceled the source coming from the + // unloaded extension. + EXPECT_EQ(extension->url(), ui_manager()->last_canceled_source()); + + TestingProfile* profile2 = + profile_manager()->CreateTestingProfile("test-profile2"); + scoped_refptr<const extensions::Extension> extension2 = + CreateGoodExtension("bar"); + // Claim the extension has been unloaded with anoter profile. + extensions::ExtensionRegistry::Get(profile2)->TriggerOnUnloaded( + extension2.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); + EXPECT_EQ(extension2->url(), ui_manager()->last_canceled_source()); +}
diff --git a/chrome/browser/notifications/notification_test_util.cc b/chrome/browser/notifications/notification_test_util.cc index f9c31b6a..d78512c 100644 --- a/chrome/browser/notifications/notification_test_util.cc +++ b/chrome/browser/notifications/notification_test_util.cc
@@ -142,8 +142,8 @@ bool StubNotificationUIManager::CancelAllBySourceOrigin( const GURL& source_origin) { - NOTIMPLEMENTED(); - return false; + last_canceled_source_ = source_origin; + return true; } bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h index 5b1b5b20..01be0ca 100644 --- a/chrome/browser/notifications/notification_test_util.h +++ b/chrome/browser/notifications/notification_test_util.h
@@ -72,6 +72,8 @@ void CancelAll() override; void StartShutdown() override; + GURL& last_canceled_source() { return last_canceled_source_; } + private: using NotificationPair = std::pair<Notification, ProfileID>; std::vector<NotificationPair> notifications_; @@ -79,6 +81,7 @@ base::Closure notification_added_callback_; bool is_shutdown_started_ = false; + GURL last_canceled_source_; DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); };
diff --git a/chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc b/chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc index 77de128..f67e903 100644 --- a/chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc +++ b/chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc
@@ -6,11 +6,14 @@ #include <stdint.h> #include <stdlib.h> +#include <utility> #include <vector> #include "base/bind.h" #include "base/guid.h" +#include "base/memory/ptr_util.h" #include "base/strings/string_number_conversions.h" +#include "base/values.h" #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" #include "chrome/browser/profiles/profile.h" @@ -133,8 +136,7 @@ base::ListValue results; for (const auto& page : pages) { - base::DictionaryValue* offline_page = new base::DictionaryValue(); - results.Append(offline_page); + auto offline_page = base::MakeUnique<base::DictionaryValue>(); offline_page->SetString("onlineUrl", page.url.spec()); offline_page->SetString("namespace", page.client_id.name_space); offline_page->SetDouble("size", page.file_size); @@ -144,6 +146,7 @@ offline_page->SetDouble("lastAccessTime", page.last_access_time.ToJsTime()); offline_page->SetInteger("accessCount", page.access_count); offline_page->SetString("originalUrl", page.original_url.spec()); + results.Append(std::move(offline_page)); } ResolveJavascriptCallback(base::Value(callback_id), results); } @@ -155,8 +158,7 @@ base::ListValue save_page_requests; if (result == offline_pages::GetRequestsResult::SUCCESS) { for (const auto& request : requests) { - base::DictionaryValue* save_page_request = new base::DictionaryValue(); - save_page_requests.Append(save_page_request); + auto save_page_request = base::MakeUnique<base::DictionaryValue>(); save_page_request->SetString("onlineUrl", request->url().spec()); save_page_request->SetDouble("creationTime", request->creation_time().ToJsTime()); @@ -168,6 +170,7 @@ save_page_request->SetString("id", std::to_string(request->request_id())); save_page_request->SetString("originalUrl", request->original_url().spec()); + save_page_requests.Append(std::move(save_page_request)); } } ResolveJavascriptCallback(base::Value(callback_id), save_page_requests);
diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc index 6fd29ce1..b21df5fcf 100644 --- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc
@@ -107,7 +107,7 @@ user_list->Append(CreateUserInfo(email, display_email, std::string())); } } - return user_list; + return std::move(user_list); } // Checks whether this is a secondary user in a multi-profile session. @@ -229,7 +229,7 @@ dict->SetBoolean("disabled", !controlled_by.empty()); if (!controlled_by.empty()) dict->SetString("controlledBy", controlled_by); - return dict; + return std::move(dict); } void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { @@ -307,7 +307,7 @@ auto dict = base::MakeUnique<base::DictionaryValue>(); dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue())); dict->SetString("controlledBy", "shared"); - return dict; + return std::move(dict); } } }
diff --git a/chrome/browser/win/enumerate_modules_model.cc b/chrome/browser/win/enumerate_modules_model.cc index 9a088ef..7f02a70 100644 --- a/chrome/browser/win/enumerate_modules_model.cc +++ b/chrome/browser/win/enumerate_modules_model.cc
@@ -15,6 +15,7 @@ #include <algorithm> #include <set> #include <string> +#include <utility> #include "base/bind.h" #include "base/command_line.h" @@ -24,6 +25,7 @@ #include "base/file_version_info.h" #include "base/i18n/case_conversion.h" #include "base/macros.h" +#include "base/memory/ptr_util.h" #include "base/metrics/histogram_macros.h" #include "base/scoped_generic.h" #include "base/strings/string_number_conversions.h" @@ -606,7 +608,7 @@ for (ModuleEnumerator::ModulesVector::const_iterator module = enumerated_modules_.begin(); module != enumerated_modules_.end(); ++module) { - base::DictionaryValue* data = new base::DictionaryValue(); + auto data = base::MakeUnique<base::DictionaryValue>(); data->SetInteger("type", module->type); base::string16 type_string; if ((module->type & ModuleEnumerator::LOADED_MODULE) == 0) { @@ -670,7 +672,7 @@ // TODO(chrisha): Set help_url when we have a meaningful place for users // to land. - list->Append(data); + list->Append(std::move(data)); } return list;
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index fd3bac3..3ed3b79 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn
@@ -4029,6 +4029,7 @@ "../browser/media_galleries/chromeos/mtp_device_object_enumerator_unittest.cc", "../browser/metrics/extensions_metrics_provider_unittest.cc", "../browser/notifications/extension_welcome_notification_unittest.cc", + "../browser/notifications/notification_system_observer_unittest.cc", "../browser/renderer_context_menu/context_menu_content_type_unittest.cc", "../browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc", "../browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_model_unittest.cc",
diff --git a/components/policy/core/common/policy_loader_win_unittest.cc b/components/policy/core/common/policy_loader_win_unittest.cc index be4652d..25b272d 100644 --- a/components/policy/core/common/policy_loader_win_unittest.cc +++ b/components/policy/core/common/policy_loader_win_unittest.cc
@@ -32,6 +32,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/sys_byteorder.h" +#include "base/values.h" #include "base/win/registry.h" #include "base/win/win_util.h" #include "components/policy/core/common/async_policy_provider.h" @@ -907,14 +908,14 @@ policy.SetInteger("int", -123); policy.SetDouble("double", 456.78e9); base::ListValue list; - list.Append(policy.DeepCopy()); - list.Append(policy.DeepCopy()); - policy.Set("list", list.DeepCopy()); + list.Append(base::MakeUnique<base::Value>(policy)); + list.Append(base::MakeUnique<base::Value>(policy)); + policy.Set("list", base::MakeUnique<base::Value>(list)); // Encode |policy| before adding the "dict" entry. std::string encoded_dict; base::JSONWriter::Write(policy, &encoded_dict); ASSERT_FALSE(encoded_dict.empty()); - policy.Set("dict", policy.DeepCopy()); + policy.Set("dict", base::MakeUnique<base::Value>(policy)); std::string encoded_list; base::JSONWriter::Write(list, &encoded_list); ASSERT_FALSE(encoded_list.empty()); @@ -1001,7 +1002,7 @@ policy.SetString("double2", "123.456e7"); policy.SetString("invalid", "omg"); base::DictionaryValue all_policies; - all_policies.Set("policy", policy.DeepCopy()); + all_policies.Set("policy", base::MakeUnique<base::Value>(policy)); const base::string16 kPathSuffix = kTestPolicyKey + base::ASCIIToUTF16("\\3rdparty\\extensions\\test"); @@ -1014,7 +1015,8 @@ expected_policy.SetDouble("double1", 789.0); expected_policy.SetDouble("double2", 123.456e7); base::DictionaryValue expected_policies; - expected_policies.Set("policy", expected_policy.DeepCopy()); + expected_policies.Set("policy", + base::MakeUnique<base::Value>(expected_policy)); PolicyBundle expected; expected.Get(ns).LoadFrom(&expected_policies, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM);
diff --git a/components/wifi/wifi_service_win.cc b/components/wifi/wifi_service_win.cc index 1d5e1617..b27443d 100644 --- a/components/wifi/wifi_service_win.cc +++ b/components/wifi/wifi_service_win.cc
@@ -10,7 +10,9 @@ #include <stdint.h> #include <wlanapi.h> +#include <memory> #include <set> +#include <utility> #include "base/base_paths_win.h" #include "base/bind.h" @@ -22,6 +24,7 @@ #include "base/strings/string16.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "base/win/registry.h" #include "components/onc/onc_constants.h" #include "components/wifi/network_properties.h" @@ -581,7 +584,7 @@ existing_properties->MergeDictionary(properties.get()); } else { connect_properties_.SetWithoutPathExpansion(network_guid, - properties.release()); + std::move(properties)); } } @@ -630,7 +633,7 @@ tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); tkip_profile->SetBoolean(kProfileSharedKey, shared); created_profiles_.SetWithoutPathExpansion(network_properties.guid, - tkip_profile.release()); + std::move(tkip_profile)); } *network_guid = network_properties.guid; @@ -656,7 +659,7 @@ ++it) { std::unique_ptr<base::DictionaryValue> network( it->ToValue(!include_details)); - network_list->Append(network.release()); + network_list->Append(std::move(network)); } } }
diff --git a/content/browser/android/java/gin_java_bridge_dispatcher_host.cc b/content/browser/android/java/gin_java_bridge_dispatcher_host.cc index 4b1fbeb..ed067a5 100644 --- a/content/browser/android/java/gin_java_bridge_dispatcher_host.cc +++ b/content/browser/android/java/gin_java_bridge_dispatcher_host.cc
@@ -357,8 +357,7 @@ routing_id); } wrapped_result->Append( - GinJavaBridgeValue::CreateObjectIDValue( - returned_object_id).release()); + GinJavaBridgeValue::CreateObjectIDValue(returned_object_id)); } else { wrapped_result->Append(base::MakeUnique<base::Value>()); }
diff --git a/content/browser/android/java/gin_java_method_invocation_helper.cc b/content/browser/android/java/gin_java_method_invocation_helper.cc index 1a5d1df..6c5edab7 100644 --- a/content/browser/android/java/gin_java_method_invocation_helper.cc +++ b/content/browser/android/java/gin_java_method_invocation_helper.cc
@@ -258,8 +258,7 @@ if (std::isfinite(result)) { result_wrapper.AppendDouble(result); } else { - result_wrapper.Append( - GinJavaBridgeValue::CreateNonFiniteValue(result).release()); + result_wrapper.Append(GinJavaBridgeValue::CreateNonFiniteValue(result)); } break; } @@ -270,8 +269,7 @@ if (std::isfinite(result)) { result_wrapper.AppendDouble(result); } else { - result_wrapper.Append( - GinJavaBridgeValue::CreateNonFiniteValue(result).release()); + result_wrapper.Append(GinJavaBridgeValue::CreateNonFiniteValue(result)); } break; } @@ -280,15 +278,13 @@ env->CallVoidMethodA(object, id, parameters); else env->CallStaticVoidMethodA(clazz, id, parameters); - result_wrapper.Append( - GinJavaBridgeValue::CreateUndefinedValue().release()); + result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); break; case JavaType::TypeArray: // LIVECONNECT_COMPLIANCE: Existing behavior is to not call methods that // return arrays. Spec requires calling the method and converting the // result to a JavaScript array. - result_wrapper.Append( - GinJavaBridgeValue::CreateUndefinedValue().release()); + result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); break; case JavaType::TypeString: { jstring java_string = static_cast<jstring>( @@ -305,8 +301,7 @@ if (!scoped_java_string.obj()) { // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined. // Spec requires returning a null string. - result_wrapper.Append( - GinJavaBridgeValue::CreateUndefinedValue().release()); + result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); break; } result_wrapper.AppendString(
diff --git a/content/browser/android/java/gin_java_method_invocation_helper_unittest.cc b/content/browser/android/java/gin_java_method_invocation_helper_unittest.cc index 113cee35..dfc96ff7 100644 --- a/content/browser/android/java/gin_java_method_invocation_helper_unittest.cc +++ b/content/browser/android/java/gin_java_method_invocation_helper_unittest.cc
@@ -6,8 +6,12 @@ #include <stddef.h> +#include <utility> + #include "base/android/jni_android.h" #include "base/macros.h" +#include "base/memory/ptr_util.h" +#include "base/values.h" #include "content/browser/android/java/jni_helper.h" #include "content/common/android/gin_java_bridge_value.h" #include "testing/gtest/include/gtest/gtest.h" @@ -124,25 +128,25 @@ TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsHaveObjects) { base::ListValue objects; objects.AppendInteger(100); - objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1).release()); - base::ListValue* sub_list = new base::ListValue(); + objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1)); + auto sub_list = base::MakeUnique<base::ListValue>(); sub_list->AppendInteger(200); - sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(2).release()); - objects.Append(sub_list); - base::DictionaryValue* sub_dict = new base::DictionaryValue(); + sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(2)); + objects.Append(std::move(sub_list)); + auto sub_dict = base::MakeUnique<base::DictionaryValue>(); sub_dict->SetInteger("1", 300); - sub_dict->Set("2", GinJavaBridgeValue::CreateObjectIDValue(3).release()); - objects.Append(sub_dict); - base::ListValue* sub_list_with_dict = new base::ListValue(); - base::DictionaryValue* sub_sub_dict = new base::DictionaryValue(); - sub_sub_dict->Set("1", GinJavaBridgeValue::CreateObjectIDValue(4).release()); - sub_list_with_dict->Append(sub_sub_dict); - objects.Append(sub_list_with_dict); - base::DictionaryValue* sub_dict_with_list = new base::DictionaryValue(); - base::ListValue* sub_sub_list = new base::ListValue(); - sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5).release()); - sub_dict_with_list->Set("1", sub_sub_list); - objects.Append(sub_dict_with_list); + sub_dict->Set("2", GinJavaBridgeValue::CreateObjectIDValue(3)); + objects.Append(std::move(sub_dict)); + auto sub_list_with_dict = base::MakeUnique<base::ListValue>(); + auto sub_sub_dict = base::MakeUnique<base::DictionaryValue>(); + sub_sub_dict->Set("1", GinJavaBridgeValue::CreateObjectIDValue(4)); + sub_list_with_dict->Append(std::move(sub_sub_dict)); + objects.Append(std::move(sub_list_with_dict)); + auto sub_dict_with_list = base::MakeUnique<base::DictionaryValue>(); + auto sub_sub_list = base::MakeUnique<base::ListValue>(); + sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5)); + sub_dict_with_list->Set("1", std::move(sub_sub_list)); + objects.Append(std::move(sub_dict_with_list)); scoped_refptr<GinJavaMethodInvocationHelper> helper = new GinJavaMethodInvocationHelper(
diff --git a/content/browser/tracing/etw_tracing_agent_win.cc b/content/browser/tracing/etw_tracing_agent_win.cc index 4392084..c126212 100644 --- a/content/browser/tracing/etw_tracing_agent_win.cc +++ b/content/browser/tracing/etw_tracing_agent_win.cc
@@ -6,6 +6,8 @@ #include <stdint.h> +#include <utility> + #include "base/base64.h" #include "base/json/json_string_value_serializer.h" #include "base/lazy_instance.h" @@ -15,6 +17,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "base/trace_event/trace_event_impl.h" +#include "base/values.h" #include "content/public/browser/browser_thread.h" namespace content { @@ -174,7 +177,7 @@ "%08X%08X", now_in_us.HighPart, now_in_us.LowPart))); // Append it to the events buffer. - events_->Append(value.release()); + events_->Append(std::move(value)); } void EtwTracingAgent::AppendEventToBuffer(EVENT_TRACE* event) { @@ -204,7 +207,7 @@ value->Set("payload", new base::Value(payload)); // Append it to the events buffer. - events_->Append(value.release()); + events_->Append(std::move(value)); } void EtwTracingAgent::TraceAndConsumeOnThread() { @@ -228,7 +231,7 @@ header->Set("name", new base::Value("ETW")); // Release and pass the events buffer. - header->Set("content", events_.release()); + header->Set("content", std::move(events_)); // Serialize the results as a JSon string. std::string output;
diff --git a/content/common/font_list_win.cc b/content/common/font_list_win.cc index 38402c5..cd1b8aa 100644 --- a/content/common/font_list_win.cc +++ b/content/common/font_list_win.cc
@@ -8,7 +8,9 @@ #include <string.h> #include <set> +#include <utility> +#include "base/memory/ptr_util.h" #include "base/strings/string16.h" #include "base/values.h" @@ -45,10 +47,10 @@ std::unique_ptr<base::ListValue> font_list(new base::ListValue); std::set<base::string16>::iterator iter; for (iter = font_names.begin(); iter != font_names.end(); ++iter) { - base::ListValue* font_item = new base::ListValue(); - font_item->Append(new base::Value(*iter)); - font_item->Append(new base::Value(*iter)); - font_list->Append(font_item); + auto font_item = base::MakeUnique<base::ListValue>(); + font_item->AppendString(*iter); + font_item->AppendString(*iter); + font_list->Append(std::move(font_item)); } return font_list; }
diff --git a/content/renderer/java/gin_java_bridge_value_converter.cc b/content/renderer/java/gin_java_bridge_value_converter.cc index f080f70..c22cbf3c 100644 --- a/content/renderer/java/gin_java_bridge_value_converter.cc +++ b/content/renderer/java/gin_java_bridge_value_converter.cc
@@ -85,8 +85,7 @@ *end = element + typed_array_->Length(); element != end; ++element) { - const ListType list_value = *element; - out->Append(new base::Value(list_value)); + out->Append(base::MakeUnique<base::Value>(ListType(*element))); } }
diff --git a/content/renderer/java/gin_java_function_invocation_helper.cc b/content/renderer/java/gin_java_function_invocation_helper.cc index af300a2..873e203 100644 --- a/content/renderer/java/gin_java_function_invocation_helper.cc +++ b/content/renderer/java/gin_java_function_invocation_helper.cc
@@ -4,7 +4,10 @@ #include "content/renderer/java/gin_java_function_invocation_helper.h" +#include <utility> + #include "base/memory/ptr_util.h" +#include "base/values.h" #include "content/common/android/gin_java_bridge_errors.h" #include "content/common/android/gin_java_bridge_value.h" #include "content/public/child/v8_value_converter.h" @@ -63,11 +66,10 @@ v8::Local<v8::Value> val; while (args->GetNext(&val)) { std::unique_ptr<base::Value> arg(converter_->FromV8Value(val, context)); - if (arg.get()) { - arguments.Append(arg.release()); - } else { + if (arg.get()) + arguments.Append(std::move(arg)); + else arguments.Append(base::MakeUnique<base::Value>()); - } } }
diff --git a/net/socket/tcp_socket_posix.cc b/net/socket/tcp_socket_posix.cc index c758e63..82f42a7 100644 --- a/net/socket/tcp_socket_posix.cc +++ b/net/socket/tcp_socket_posix.cc
@@ -370,7 +370,7 @@ int TCPSocketPosix::SetDefaultOptionsForServer() { DCHECK(socket_); - return SetAddressReuse(true); + return AllowAddressReuse(); } void TCPSocketPosix::SetDefaultOptionsForClient() { @@ -399,29 +399,33 @@ #endif } -int TCPSocketPosix::SetAddressReuse(bool allow) { +int TCPSocketPosix::AllowAddressReuse() { DCHECK(socket_); - return SetReuseAddr(socket_->socket_fd(), allow); + return SetReuseAddr(socket_->socket_fd(), true); } int TCPSocketPosix::SetReceiveBufferSize(int32_t size) { DCHECK(socket_); + return SetSocketReceiveBufferSize(socket_->socket_fd(), size); } int TCPSocketPosix::SetSendBufferSize(int32_t size) { DCHECK(socket_); + return SetSocketSendBufferSize(socket_->socket_fd(), size); } bool TCPSocketPosix::SetKeepAlive(bool enable, int delay) { DCHECK(socket_); + return SetTCPKeepAlive(socket_->socket_fd(), enable, delay); } bool TCPSocketPosix::SetNoDelay(bool no_delay) { DCHECK(socket_); + return SetTCPNoDelay(socket_->socket_fd(), no_delay) == OK; }
diff --git a/net/socket/tcp_socket_posix.h b/net/socket/tcp_socket_posix.h index f52479f..f5ba10a 100644 --- a/net/socket/tcp_socket_posix.h +++ b/net/socket/tcp_socket_posix.h
@@ -42,6 +42,7 @@ virtual ~TCPSocketPosix(); int Open(AddressFamily family); + // Takes ownership of |socket_fd|. int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); @@ -69,13 +70,13 @@ // Sets various socket options. // The commonly used options for server listening sockets: - // - SetAddressReuse(true). + // - AllowAddressReuse(). int SetDefaultOptionsForServer(); // The commonly used options for client sockets and accepted sockets: // - SetNoDelay(true); // - SetKeepAlive(true, 45). void SetDefaultOptionsForClient(); - int SetAddressReuse(bool allow); + int AllowAddressReuse(); int SetReceiveBufferSize(int32_t size); int SetSendBufferSize(int32_t size); bool SetKeepAlive(bool enable, int delay);
diff --git a/remoting/host/pairing_registry_delegate_win.cc b/remoting/host/pairing_registry_delegate_win.cc index af61d6df..abd9e647 100644 --- a/remoting/host/pairing_registry_delegate_win.cc +++ b/remoting/host/pairing_registry_delegate_win.cc
@@ -68,7 +68,7 @@ return nullptr; } - return base::WrapUnique(static_cast<base::DictionaryValue*>(value.release())); + return base::DictionaryValue::From(std::move(value)); } // Serializes |value| into a JSON string and writes it as value |value_name| @@ -139,7 +139,7 @@ PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name)); if (pairing.is_valid()) - pairings->Append(pairing.ToValue().release()); + pairings->Append(pairing.ToValue()); } return pairings; @@ -221,7 +221,7 @@ CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); std::unique_ptr<base::DictionaryValue> secret_json( new base::DictionaryValue()); - secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release()); + secret_json->Set(PairingRegistry::kSharedSecretKey, std::move(secret_key)); // presubmit: allow wstring std::wstring value_name = base::UTF8ToWide(pairing.client_id());