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

Side by Side Diff: chrome/browser/ui/webui/components_ui.cc

Issue 2814363006: Reland of Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: std::move Created 3 years, 8 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/ui/webui/components_ui.h" 5 #include "chrome/browser/ui/webui/components_ui.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 base::Unretained(this))); 97 base::Unretained(this)));
98 98
99 web_ui()->RegisterMessageCallback( 99 web_ui()->RegisterMessageCallback(
100 "checkUpdate", 100 "checkUpdate",
101 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate, 101 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate,
102 base::Unretained(this))); 102 base::Unretained(this)));
103 } 103 }
104 104
105 void ComponentsDOMHandler::HandleRequestComponentsData( 105 void ComponentsDOMHandler::HandleRequestComponentsData(
106 const base::ListValue* args) { 106 const base::ListValue* args) {
107 base::ListValue* list = ComponentsUI::LoadComponents();
108 base::DictionaryValue result; 107 base::DictionaryValue result;
109 result.Set("components", list); 108 result.Set("components", ComponentsUI::LoadComponents());
110 web_ui()->CallJavascriptFunctionUnsafe("returnComponentsData", result); 109 web_ui()->CallJavascriptFunctionUnsafe("returnComponentsData", result);
111 } 110 }
112 111
113 // This function is called when user presses button from html UI. 112 // This function is called when user presses button from html UI.
114 // TODO(shrikant): We need to make this button available based on current 113 // TODO(shrikant): We need to make this button available based on current
115 // state e.g. If component state is currently updating then we need to disable 114 // state e.g. If component state is currently updating then we need to disable
116 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) 115 // button. (https://code.google.com/p/chromium/issues/detail?id=272540)
117 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { 116 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) {
118 if (args->GetSize() != 1) { 117 if (args->GetSize() != 1) {
119 NOTREACHED(); 118 NOTREACHED();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 156
158 // static 157 // static
159 void ComponentsUI::OnDemandUpdate(const std::string& component_id) { 158 void ComponentsUI::OnDemandUpdate(const std::string& component_id) {
160 component_updater::ComponentUpdateService* cus = 159 component_updater::ComponentUpdateService* cus =
161 g_browser_process->component_updater(); 160 g_browser_process->component_updater();
162 cus->GetOnDemandUpdater().OnDemandUpdate(component_id, 161 cus->GetOnDemandUpdater().OnDemandUpdate(component_id,
163 component_updater::Callback()); 162 component_updater::Callback());
164 } 163 }
165 164
166 // static 165 // static
167 base::ListValue* ComponentsUI::LoadComponents() { 166 std::unique_ptr<base::ListValue> ComponentsUI::LoadComponents() {
168 component_updater::ComponentUpdateService* cus = 167 component_updater::ComponentUpdateService* cus =
169 g_browser_process->component_updater(); 168 g_browser_process->component_updater();
170 std::vector<std::string> component_ids; 169 std::vector<std::string> component_ids;
171 component_ids = cus->GetComponentIDs(); 170 component_ids = cus->GetComponentIDs();
172 171
173 // Construct DictionaryValues to return to UI. 172 // Construct DictionaryValues to return to UI.
174 base::ListValue* component_list = new base::ListValue(); 173 auto component_list = base::MakeUnique<base::ListValue>();
175 for (size_t j = 0; j < component_ids.size(); ++j) { 174 for (size_t j = 0; j < component_ids.size(); ++j) {
176 update_client::CrxUpdateItem item; 175 update_client::CrxUpdateItem item;
177 if (cus->GetComponentDetails(component_ids[j], &item)) { 176 if (cus->GetComponentDetails(component_ids[j], &item)) {
178 std::unique_ptr<base::DictionaryValue> component_entry( 177 std::unique_ptr<base::DictionaryValue> component_entry(
179 new base::DictionaryValue()); 178 new base::DictionaryValue());
180 component_entry->SetString("id", component_ids[j]); 179 component_entry->SetString("id", component_ids[j]);
181 component_entry->SetString("name", item.component.name); 180 component_entry->SetString("name", item.component.name);
182 component_entry->SetString("version", item.component.version.GetString()); 181 component_entry->SetString("version", item.component.version.GetString());
183 component_entry->SetString("status", ServiceStatusToString(item.state)); 182 component_entry->SetString("status", ServiceStatusToString(item.state));
184 component_list->Append(std::move(component_entry)); 183 component_list->Append(std::move(component_entry));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (event == Events::COMPONENT_UPDATED) { 254 if (event == Events::COMPONENT_UPDATED) {
256 auto* component_updater = g_browser_process->component_updater(); 255 auto* component_updater = g_browser_process->component_updater();
257 update_client::CrxUpdateItem item; 256 update_client::CrxUpdateItem item;
258 if (component_updater->GetComponentDetails(id, &item)) 257 if (component_updater->GetComponentDetails(id, &item))
259 parameters.SetString("version", item.component.version.GetString()); 258 parameters.SetString("version", item.component.version.GetString());
260 } 259 }
261 parameters.SetString("id", id); 260 parameters.SetString("id", id);
262 } 261 }
263 web_ui()->CallJavascriptFunctionUnsafe("onComponentEvent", parameters); 262 web_ui()->CallJavascriptFunctionUnsafe("onComponentEvent", parameters);
264 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/components_ui.h ('k') | chrome/browser/ui/webui/cookies_tree_model_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698