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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/network_dropdown.cc

Issue 2392693002: Rewrite simple uses of base::ListValue::Append(base::Value*) on CrOS. (Closed)
Patch Set: MakeUnique Created 4 years, 2 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/chromeos/login/network_dropdown.h" 5 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown.h"
6 6
7 #include <memory>
7 #include <string> 8 #include <string>
9 #include <utility>
8 10
9 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 15 #include "base/time/time.h"
13 #include "base/values.h" 16 #include "base/values.h"
14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
15 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
16 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
17 #include "ui/base/models/menu_model.h" 20 #include "ui/base/models/menu_model.h"
18 #include "ui/base/webui/web_ui_util.h" 21 #include "ui/base/webui/web_ui_util.h"
19 #include "ui/chromeos/network/network_icon.h" 22 #include "ui/chromeos/network/network_icon.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 83
81 base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) { 84 base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) {
82 base::ListValue* list = new base::ListValue(); 85 base::ListValue* list = new base::ListValue();
83 for (int i = 0; i < model->GetItemCount(); ++i) { 86 for (int i = 0; i < model->GetItemCount(); ++i) {
84 ui::MenuModel::ItemType type = model->GetTypeAt(i); 87 ui::MenuModel::ItemType type = model->GetTypeAt(i);
85 int id; 88 int id;
86 if (type == ui::MenuModel::TYPE_SEPARATOR) 89 if (type == ui::MenuModel::TYPE_SEPARATOR)
87 id = -2; 90 id = -2;
88 else 91 else
89 id = model->GetCommandIdAt(i); 92 id = model->GetCommandIdAt(i);
90 base::DictionaryValue* item = new base::DictionaryValue(); 93 auto item = base::MakeUnique<base::DictionaryValue>();
91 item->SetInteger("id", id); 94 item->SetInteger("id", id);
92 base::string16 label = model->GetLabelAt(i); 95 base::string16 label = model->GetLabelAt(i);
93 base::ReplaceSubstringsAfterOffset(&label, 0, base::ASCIIToUTF16("&&"), 96 base::ReplaceSubstringsAfterOffset(&label, 0, base::ASCIIToUTF16("&&"),
94 base::ASCIIToUTF16("&")); 97 base::ASCIIToUTF16("&"));
95 item->SetString("label", label); 98 item->SetString("label", label);
96 gfx::Image icon; 99 gfx::Image icon;
97 if (model->GetIconAt(i, &icon)) { 100 if (model->GetIconAt(i, &icon)) {
98 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation( 101 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation(
99 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); 102 web_ui_->GetDeviceScaleFactor()).sk_bitmap();
100 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap)); 103 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap));
101 } 104 }
102 if (id >= 0) { 105 if (id >= 0) {
103 item->SetBoolean("enabled", model->IsEnabledAt(i)); 106 item->SetBoolean("enabled", model->IsEnabledAt(i));
104 const gfx::FontList* font_list = model->GetLabelFontListAt(i); 107 const gfx::FontList* font_list = model->GetLabelFontListAt(i);
105 if (font_list) 108 if (font_list)
106 item->SetBoolean("bold", 109 item->SetBoolean("bold",
107 font_list->GetFontWeight() == gfx::Font::Weight::BOLD); 110 font_list->GetFontWeight() == gfx::Font::Weight::BOLD);
108 } 111 }
109 if (type == ui::MenuModel::TYPE_SUBMENU) 112 if (type == ui::MenuModel::TYPE_SUBMENU)
110 item->Set("sub", ConvertMenuModel(model->GetSubmenuModelAt(i))); 113 item->Set("sub", ConvertMenuModel(model->GetSubmenuModelAt(i)));
111 list->Append(item); 114 list->Append(std::move(item));
112 } 115 }
113 return list; 116 return list;
114 } 117 }
115 118
116 // NetworkDropdown ------------------------------------------------------------- 119 // NetworkDropdown -------------------------------------------------------------
117 120
118 NetworkDropdown::NetworkDropdown(Actor* actor, 121 NetworkDropdown::NetworkDropdown(Actor* actor,
119 content::WebUI* web_ui, 122 content::WebUI* web_ui,
120 bool oobe) 123 bool oobe)
121 : actor_(actor), 124 : actor_(actor),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle", 208 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle",
206 title, icon); 209 title, icon);
207 } 210 }
208 211
209 void NetworkDropdown::RequestNetworkScan() { 212 void NetworkDropdown::RequestNetworkScan() {
210 NetworkHandler::Get()->network_state_handler()->RequestScan(); 213 NetworkHandler::Get()->network_state_handler()->RequestScan();
211 Refresh(); 214 Refresh();
212 } 215 }
213 216
214 } // namespace chromeos 217 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698