Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h" 5 #include "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 pref_key.c_str()); 132 pref_key.c_str());
133 EventRouter* router = EventRouter::Get(profile_); 133 EventRouter* router = EventRouter::Get(profile_);
134 if (router && router->HasEventListener(event_name)) { 134 if (router && router->HasEventListener(event_name)) {
135 const PrefService::Preference* preference = 135 const PrefService::Preference* preference =
136 profile_->GetPrefs()->FindPreference(pref_key.c_str()); 136 profile_->GetPrefs()->FindPreference(pref_key.c_str());
137 const base::Value* value = preference->GetValue(); 137 const base::Value* value = preference->GetValue();
138 138
139 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); 139 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
140 result->Set(preference_api_constants::kValue, value->DeepCopy()); 140 result->Set(preference_api_constants::kValue, value->DeepCopy());
141 base::ListValue args; 141 base::ListValue args;
142 args.Append(result.release()); 142 args.Append(std::move(result));
143 143
144 for (const scoped_refptr<const extensions::Extension>& extension : 144 for (const scoped_refptr<const extensions::Extension>& extension :
145 ExtensionRegistry::Get(profile_)->enabled_extensions()) { 145 ExtensionRegistry::Get(profile_)->enabled_extensions()) {
146 const std::string& extension_id = extension->id(); 146 const std::string& extension_id = extension->id();
147 if (router->ExtensionHasEventListener(extension_id, event_name)) { 147 if (router->ExtensionHasEventListener(extension_id, event_name)) {
148 std::unique_ptr<base::ListValue> args_copy(args.DeepCopy()); 148 std::unique_ptr<base::ListValue> args_copy(args.DeepCopy());
149 // TODO(kalman): Have a histogram value for each pref type. 149 // TODO(kalman): Have a histogram value for each pref type.
150 // This isn't so important for the current use case of these 150 // This isn't so important for the current use case of these
151 // histograms, which is to track which event types are waking up event 151 // histograms, which is to track which event types are waking up event
152 // pages, or which are delivered to persistent background pages. Simply 152 // pages, or which are delivered to persistent background pages. Simply
153 // "a setting changed" is enough detail for that. However if we try to 153 // "a setting changed" is enough detail for that. However if we try to
154 // use these histograms for any fine-grained logic (like removing the 154 // use these histograms for any fine-grained logic (like removing the
155 // string event name altogether), or if we discover this event is 155 // string event name altogether), or if we discover this event is
156 // firing a lot and want to understand that better, then this will need 156 // firing a lot and want to understand that better, then this will need
157 // to change. 157 // to change.
158 events::HistogramValue histogram_value = 158 events::HistogramValue histogram_value =
159 events::TYPES_PRIVATE_CHROME_DIRECT_SETTING_ON_CHANGE; 159 events::TYPES_PRIVATE_CHROME_DIRECT_SETTING_ON_CHANGE;
160 std::unique_ptr<Event> event( 160 std::unique_ptr<Event> event(
161 new Event(histogram_value, event_name, std::move(args_copy))); 161 new Event(histogram_value, event_name, std::move(args_copy)));
162 router->DispatchEventToExtension(extension_id, std::move(event)); 162 router->DispatchEventToExtension(extension_id, std::move(event));
163 } 163 }
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 } // namespace chromedirectsetting 168 } // namespace chromedirectsetting
169 } // namespace extensions 169 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698