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

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/webui/media_router/media_router_webui_message_handle r.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
12 #include "base/metrics/user_metrics.h" 13 #include "base/metrics/user_metrics.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/media/router/issue.h" 17 #include "chrome/browser/media/router/issue.h"
17 #include "chrome/browser/media/router/media_router_metrics.h" 18 #include "chrome/browser/media/router/media_router_metrics.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 show_domain = true; 122 show_domain = true;
122 } 123 }
123 } 124 }
124 125
125 int cast_mode_bits = 0; 126 int cast_mode_bits = 0;
126 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) 127 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes)
127 cast_mode_bits |= cast_mode; 128 cast_mode_bits |= cast_mode;
128 129
129 sink_val->SetInteger("castModes", cast_mode_bits); 130 sink_val->SetInteger("castModes", cast_mode_bits);
130 sink_val->SetBoolean("isPseudoSink", is_pseudo_sink); 131 sink_val->SetBoolean("isPseudoSink", is_pseudo_sink);
131 sinks_val->Append(sink_val.release()); 132 sinks_val->Append(std::move(sink_val));
132 } 133 }
133 134
134 sink_list_and_identity->Set("sinks", sinks_val.release()); 135 sink_list_and_identity->Set("sinks", sinks_val.release());
135 sink_list_and_identity->SetBoolean("showEmail", show_email); 136 sink_list_and_identity->SetBoolean("showEmail", show_email);
136 sink_list_and_identity->SetBoolean("showDomain", show_domain); 137 sink_list_and_identity->SetBoolean("showDomain", show_domain);
137 return sink_list_and_identity; 138 return sink_list_and_identity;
138 } 139 }
139 140
140 std::unique_ptr<base::DictionaryValue> RouteToValue( 141 std::unique_ptr<base::DictionaryValue> RouteToValue(
141 const MediaRoute& route, 142 const MediaRoute& route,
(...skipping 29 matching lines...) Expand all
171 const std::string& source_host) { 172 const std::string& source_host) {
172 std::unique_ptr<base::ListValue> value(new base::ListValue); 173 std::unique_ptr<base::ListValue> value(new base::ListValue);
173 174
174 for (const MediaCastMode& cast_mode : cast_modes) { 175 for (const MediaCastMode& cast_mode : cast_modes) {
175 std::unique_ptr<base::DictionaryValue> cast_mode_val( 176 std::unique_ptr<base::DictionaryValue> cast_mode_val(
176 new base::DictionaryValue); 177 new base::DictionaryValue);
177 cast_mode_val->SetInteger("type", cast_mode); 178 cast_mode_val->SetInteger("type", cast_mode);
178 cast_mode_val->SetString( 179 cast_mode_val->SetString(
179 "description", MediaCastModeToDescription(cast_mode, source_host)); 180 "description", MediaCastModeToDescription(cast_mode, source_host));
180 cast_mode_val->SetString("host", source_host); 181 cast_mode_val->SetString("host", source_host);
181 value->Append(cast_mode_val.release()); 182 value->Append(std::move(cast_mode_val));
182 } 183 }
183 184
184 return value; 185 return value;
185 } 186 }
186 187
187 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 188 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
188 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 189 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
189 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 190 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
190 dictionary->SetString("id", issue.id()); 191 dictionary->SetString("id", issue.id());
191 dictionary->SetString("title", issue.title()); 192 dictionary->SetString("title", issue.title());
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 std::unique_ptr<base::ListValue> value(new base::ListValue); 879 std::unique_ptr<base::ListValue> value(new base::ListValue);
879 const std::string& extension_id = 880 const std::string& extension_id =
880 media_router_ui_->GetRouteProviderExtensionId(); 881 media_router_ui_->GetRouteProviderExtensionId();
881 882
882 for (const MediaRoute& route : routes) { 883 for (const MediaRoute& route : routes) {
883 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); 884 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id());
884 int current_cast_mode = CurrentCastModeForRouteId(route.media_route_id(), 885 int current_cast_mode = CurrentCastModeForRouteId(route.media_route_id(),
885 current_cast_modes); 886 current_cast_modes);
886 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue( 887 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue(
887 route, can_join, extension_id, off_the_record_, current_cast_mode)); 888 route, can_join, extension_id, off_the_record_, current_cast_mode));
888 value->Append(route_val.release()); 889 value->Append(std::move(route_val));
889 } 890 }
890 891
891 return value; 892 return value;
892 } 893 }
893 894
894 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 895 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
895 set_web_ui(web_ui); 896 set_web_ui(web_ui);
896 } 897 }
897 898
898 } // namespace media_router 899 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698