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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/environment.h" 15 #include "base/environment.h"
15 #include "base/i18n/number_formatting.h" 16 #include "base/i18n/number_formatting.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
18 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
19 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1226
1226 int default_index = -1; 1227 int default_index = -1;
1227 base::ListValue search_engines; 1228 base::ListValue search_engines;
1228 TemplateURLService::TemplateURLVector model_urls( 1229 TemplateURLService::TemplateURLVector model_urls(
1229 template_url_service_->GetTemplateURLs()); 1230 template_url_service_->GetTemplateURLs());
1230 for (size_t i = 0; i < model_urls.size(); ++i) { 1231 for (size_t i = 0; i < model_urls.size(); ++i) {
1231 if (!model_urls[i]->ShowInDefaultList( 1232 if (!model_urls[i]->ShowInDefaultList(
1232 template_url_service_->search_terms_data())) 1233 template_url_service_->search_terms_data()))
1233 continue; 1234 continue;
1234 1235
1235 base::DictionaryValue* entry = new base::DictionaryValue(); 1236 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue());
1236 entry->SetString("name", model_urls[i]->short_name()); 1237 entry->SetString("name", model_urls[i]->short_name());
1237 entry->SetInteger("index", i); 1238 entry->SetInteger("index", i);
1238 search_engines.Append(entry); 1239 search_engines.Append(std::move(entry));
1239 if (model_urls[i] == default_url) 1240 if (model_urls[i] == default_url)
1240 default_index = i; 1241 default_index = i;
1241 } 1242 }
1242 1243
1243 web_ui()->CallJavascriptFunctionUnsafe( 1244 web_ui()->CallJavascriptFunctionUnsafe(
1244 "BrowserOptions.updateSearchEngines", search_engines, 1245 "BrowserOptions.updateSearchEngines", search_engines,
1245 base::FundamentalValue(default_index), 1246 base::FundamentalValue(default_index),
1246 base::FundamentalValue( 1247 base::FundamentalValue(
1247 template_url_service_->is_default_search_managed() || 1248 template_url_service_->is_default_search_managed() ||
1248 template_url_service_->IsExtensionControlledDefaultSearch())); 1249 template_url_service_->IsExtensionControlledDefaultSearch()));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 g_browser_process->profile_manager()-> 1349 g_browser_process->profile_manager()->
1349 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); 1350 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName();
1350 std::unique_ptr<base::ListValue> profile_info_list(new base::ListValue); 1351 std::unique_ptr<base::ListValue> profile_info_list(new base::ListValue);
1351 base::FilePath current_profile_path = 1352 base::FilePath current_profile_path =
1352 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); 1353 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1353 1354
1354 for (const ProfileAttributesEntry* entry : entries) { 1355 for (const ProfileAttributesEntry* entry : entries) {
1355 // The items in |profile_value| are also described in 1356 // The items in |profile_value| are also described in
1356 // chrome/browser/resources/options/browser_options.js in a @typedef for 1357 // chrome/browser/resources/options/browser_options.js in a @typedef for
1357 // Profile. Please update it whenever you add or remove any keys here. 1358 // Profile. Please update it whenever you add or remove any keys here.
1358 base::DictionaryValue* profile_value = new base::DictionaryValue(); 1359 std::unique_ptr<base::DictionaryValue> profile_value(
1360 new base::DictionaryValue());
1359 profile_value->SetString("name", entry->GetName()); 1361 profile_value->SetString("name", entry->GetName());
1360 base::FilePath profile_path = entry->GetPath(); 1362 base::FilePath profile_path = entry->GetPath();
1361 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); 1363 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1362 profile_value->SetBoolean("isCurrentProfile", 1364 profile_value->SetBoolean("isCurrentProfile",
1363 profile_path == current_profile_path); 1365 profile_path == current_profile_path);
1364 profile_value->SetBoolean("isSupervised", entry->IsSupervised()); 1366 profile_value->SetBoolean("isSupervised", entry->IsSupervised());
1365 profile_value->SetBoolean("isChild", entry->IsChild()); 1367 profile_value->SetBoolean("isChild", entry->IsChild());
1366 1368
1367 if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) { 1369 if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) {
1368 gfx::Image icon = profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(), 1370 gfx::Image icon = profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(),
1369 true); 1371 true);
1370 profile_value->SetString("iconURL", 1372 profile_value->SetString("iconURL",
1371 webui::GetBitmapDataUrl(icon.AsBitmap())); 1373 webui::GetBitmapDataUrl(icon.AsBitmap()));
1372 } else { 1374 } else {
1373 size_t icon_index = entry->GetAvatarIconIndex(); 1375 size_t icon_index = entry->GetAvatarIconIndex();
1374 profile_value->SetString("iconURL", 1376 profile_value->SetString("iconURL",
1375 profiles::GetDefaultAvatarIconUrl(icon_index)); 1377 profiles::GetDefaultAvatarIconUrl(icon_index));
1376 } 1378 }
1377 1379
1378 profile_info_list->Append(profile_value); 1380 profile_info_list->Append(std::move(profile_value));
1379 } 1381 }
1380 1382
1381 return profile_info_list; 1383 return profile_info_list;
1382 } 1384 }
1383 1385
1384 void BrowserOptionsHandler::SendProfilesInfo() { 1386 void BrowserOptionsHandler::SendProfilesInfo() {
1385 if (!ShouldShowMultiProfilesUserList()) 1387 if (!ShouldShowMultiProfilesUserList())
1386 return; 1388 return;
1387 web_ui()->CallJavascriptFunctionUnsafe("BrowserOptions.setProfilesInfo", 1389 web_ui()->CallJavascriptFunctionUnsafe("BrowserOptions.setProfilesInfo",
1388 *GetProfilesInfoList()); 1390 *GetProfilesInfoList());
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 1999
1998 // Iterate through the zoom factors and and build the contents of the 2000 // Iterate through the zoom factors and and build the contents of the
1999 // selector that will be sent to the javascript handler. 2001 // selector that will be sent to the javascript handler.
2000 // Each item in the list has the following parameters: 2002 // Each item in the list has the following parameters:
2001 // 1. Title (string). 2003 // 1. Title (string).
2002 // 2. Value (double). 2004 // 2. Value (double).
2003 // 3. Is selected? (bool). 2005 // 3. Is selected? (bool).
2004 base::ListValue zoom_factors_value; 2006 base::ListValue zoom_factors_value;
2005 for (std::vector<double>::const_iterator i = zoom_factors.begin(); 2007 for (std::vector<double>::const_iterator i = zoom_factors.begin();
2006 i != zoom_factors.end(); ++i) { 2008 i != zoom_factors.end(); ++i) {
2007 base::ListValue* option = new base::ListValue(); 2009 std::unique_ptr<base::ListValue> option(new base::ListValue());
2008 double factor = *i; 2010 double factor = *i;
2009 int percent = static_cast<int>(factor * 100 + 0.5); 2011 int percent = static_cast<int>(factor * 100 + 0.5);
2010 option->AppendString(base::FormatPercent(percent)); 2012 option->AppendString(base::FormatPercent(percent));
2011 option->AppendDouble(factor); 2013 option->AppendDouble(factor);
2012 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); 2014 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
2013 option->AppendBoolean(selected); 2015 option->AppendBoolean(selected);
2014 zoom_factors_value.Append(option); 2016 zoom_factors_value.Append(std::move(option));
2015 } 2017 }
2016 2018
2017 web_ui()->CallJavascriptFunctionUnsafe("BrowserOptions.setupPageZoomSelector", 2019 web_ui()->CallJavascriptFunctionUnsafe("BrowserOptions.setupPageZoomSelector",
2018 zoom_factors_value); 2020 zoom_factors_value);
2019 } 2021 }
2020 2022
2021 void BrowserOptionsHandler::SetupAutoOpenFileTypes() { 2023 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
2022 // Set the hidden state for the AutoOpenFileTypesResetToDefault button. 2024 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
2023 // We show the button if the user has any auto-open file types registered. 2025 // We show the button if the user has any auto-open file types registered.
2024 DownloadManager* manager = BrowserContext::GetDownloadManager( 2026 DownloadManager* manager = BrowserContext::GetDownloadManager(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 2186
2185 bool BrowserOptionsHandler::IsDeviceOwnerProfile() { 2187 bool BrowserOptionsHandler::IsDeviceOwnerProfile() {
2186 #if defined(OS_CHROMEOS) 2188 #if defined(OS_CHROMEOS)
2187 return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui())); 2189 return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui()));
2188 #else 2190 #else
2189 return true; 2191 return true;
2190 #endif 2192 #endif
2191 } 2193 }
2192 2194
2193 } // namespace options 2195 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/nacl_ui.cc ('k') | chrome/browser/ui/webui/options/certificate_manager_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698