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

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

Issue 209313002: Modified components ui to address concern of all the time disabled check update button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified according to code review comments. Created 6 years, 7 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 | Annotate | Revision Log
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/component_updater/component_updater_service.h" 13 #include "chrome/browser/component_updater/component_updater_service.h"
14 #include "chrome/browser/component_updater/crx_update_item.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
19 #include "content/public/browser/web_ui_data_source.h" 20 #include "content/public/browser/web_ui_data_source.h"
20 #include "content/public/browser/web_ui_message_handler.h" 21 #include "content/public/browser/web_ui_message_handler.h"
21 #include "grit/browser_resources.h" 22 #include "grit/browser_resources.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // WebUIMessageHandler implementation. 69 // WebUIMessageHandler implementation.
69 virtual void RegisterMessages() OVERRIDE; 70 virtual void RegisterMessages() OVERRIDE;
70 71
71 // Callback for the "requestComponentsData" message. 72 // Callback for the "requestComponentsData" message.
72 void HandleRequestComponentsData(const base::ListValue* args); 73 void HandleRequestComponentsData(const base::ListValue* args);
73 74
74 // Callback for the "checkUpdate" message. 75 // Callback for the "checkUpdate" message.
75 void HandleCheckUpdate(const base::ListValue* args); 76 void HandleCheckUpdate(const base::ListValue* args);
76 77
77 private: 78 private:
78 void LoadComponents();
79
80 content::NotificationRegistrar registrar_; 79 content::NotificationRegistrar registrar_;
81 80
82 DISALLOW_COPY_AND_ASSIGN(ComponentsDOMHandler); 81 DISALLOW_COPY_AND_ASSIGN(ComponentsDOMHandler);
83 }; 82 };
84 83
85 ComponentsDOMHandler::ComponentsDOMHandler() { 84 ComponentsDOMHandler::ComponentsDOMHandler() {
86 } 85 }
87 86
88 void ComponentsDOMHandler::RegisterMessages() { 87 void ComponentsDOMHandler::RegisterMessages() {
89 web_ui()->RegisterMessageCallback("requestComponentsData", 88 web_ui()->RegisterMessageCallback(
89 "requestComponentsData",
90 base::Bind(&ComponentsDOMHandler::HandleRequestComponentsData, 90 base::Bind(&ComponentsDOMHandler::HandleRequestComponentsData,
91 base::Unretained(this))); 91 base::Unretained(this)));
92 92
93 web_ui()->RegisterMessageCallback("checkUpdate", 93 web_ui()->RegisterMessageCallback(
94 "checkUpdate",
94 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate, 95 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate,
95 base::Unretained(this))); 96 base::Unretained(this)));
96 } 97 }
97 98
98 void ComponentsDOMHandler::HandleRequestComponentsData( 99 void ComponentsDOMHandler::HandleRequestComponentsData(
99 const base::ListValue* args) { 100 const base::ListValue* args) {
100 LoadComponents(); 101 base::ListValue* list = ComponentsUI::LoadComponents();
Sorin Jianu 2014/05/08 22:07:24 Will the memory for |list| be correctly deallocate
Shrikant Kelkar 2014/05/15 23:12:43 Originally I also was concerned about this, but it
102 base::DictionaryValue result;
103 result.Set("components", list);
104 web_ui()->CallJavascriptFunction("returnComponentsData", result);
101 } 105 }
102 106
103 // This function is called when user presses button from html UI. 107 // This function is called when user presses button from html UI.
104 // TODO(shrikant): We need to make this button available based on current 108 // TODO(shrikant): We need to make this button available based on current
105 // state e.g. If component state is currently updating then we need to disable 109 // state e.g. If component state is currently updating then we need to disable
106 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) 110 // button. (https://code.google.com/p/chromium/issues/detail?id=272540)
107 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { 111 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) {
108 if (args->GetSize() != 1) { 112 if (args->GetSize() != 1) {
109 NOTREACHED(); 113 NOTREACHED();
110 return; 114 return;
111 } 115 }
112 116
113 std::string component_id; 117 std::string component_id;
114 if (!args->GetString(0, &component_id)) { 118 if (!args->GetString(0, &component_id)) {
115 NOTREACHED(); 119 NOTREACHED();
116 return; 120 return;
117 } 121 }
118 122
119 ComponentsUI::OnDemandUpdate(component_id); 123 ComponentsUI::OnDemandUpdate(component_id);
120 } 124 }
121 125
122 void ComponentsDOMHandler::LoadComponents() {
123 component_updater::ComponentUpdateService* cus =
124 g_browser_process->component_updater();
125 std::vector<component_updater::CrxComponentInfo> components;
126 cus->GetComponents(&components);
127
128 // Construct DictionaryValues to return to UI.
129 base::ListValue* component_list = new base::ListValue();
130 for (size_t j = 0; j < components.size(); ++j) {
131 const component_updater::CrxComponentInfo& component = components[j];
132
133 base::DictionaryValue* component_entry = new base::DictionaryValue();
134 component_entry->SetString("id", component.id);
135 component_entry->SetString("name", component.name);
136 component_entry->SetString("version", component.version);
137
138 component_list->Append(component_entry);
139 }
140
141 base::DictionaryValue results;
142 results.Set("components", component_list);
143 web_ui()->CallJavascriptFunction("returnComponentsData", results);
144 }
145
146 } // namespace 126 } // namespace
147 127
148 /////////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////////
149 // 129 //
150 // ComponentsUI 130 // ComponentsUI
151 // 131 //
152 /////////////////////////////////////////////////////////////////////////////// 132 ///////////////////////////////////////////////////////////////////////////////
153 133
154 ComponentsUI::ComponentsUI(content::WebUI* web_ui) : WebUIController(web_ui) { 134 ComponentsUI::ComponentsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
155 web_ui->AddMessageHandler(new ComponentsDOMHandler()); 135 web_ui->AddMessageHandler(new ComponentsDOMHandler());
156 136
157 // Set up the chrome://components/ source. 137 // Set up the chrome://components/ source.
158 Profile* profile = Profile::FromWebUI(web_ui); 138 Profile* profile = Profile::FromWebUI(web_ui);
159 content::WebUIDataSource::Add(profile, CreateComponentsUIHTMLSource(profile)); 139 content::WebUIDataSource::Add(profile, CreateComponentsUIHTMLSource(profile));
140 component_updater::ComponentUpdateService* cus =
141 g_browser_process->component_updater();
142 cus->AddObserver(this);
143 }
144
145 ComponentsUI::~ComponentsUI() {
146 component_updater::ComponentUpdateService* cus =
147 g_browser_process->component_updater();
148 if (cus)
149 cus->RemoveObserver(this);
160 } 150 }
161 151
162 // static 152 // static
163 void ComponentsUI::OnDemandUpdate(const std::string& component_id) { 153 void ComponentsUI::OnDemandUpdate(const std::string& component_id) {
164 component_updater::ComponentUpdateService* cus = 154 component_updater::ComponentUpdateService* cus =
165 g_browser_process->component_updater(); 155 g_browser_process->component_updater();
166 cus->OnDemandUpdate(component_id); 156 cus->OnDemandUpdate(component_id);
167 } 157 }
168 158
169 // static 159 // static
160 base::ListValue* ComponentsUI::LoadComponents() {
161 component_updater::ComponentUpdateService* cus =
162 g_browser_process->component_updater();
163 std::vector<std::string> component_ids;
164 component_ids = cus->GetComponentIDs();
165
166 // Construct DictionaryValues to return to UI.
167 base::ListValue* component_list = new base::ListValue();
Sorin Jianu 2014/05/08 22:07:24 Who owns this memory?
Shrikant Kelkar 2014/05/15 23:12:43 This instance is returned to caller, who attaches
168 for (size_t j = 0; j < component_ids.size(); ++j) {
169 component_updater::CrxUpdateItem* item = cus->GetComponentDetails(
Sorin Jianu 2014/05/08 22:07:24 This |item| could be const. Also, the result of ca
Shrikant Kelkar 2014/05/15 23:12:43 Done.
170 component_ids[j]);
171
172 base::DictionaryValue* component_entry = new base::DictionaryValue();
Sorin Jianu 2014/05/08 22:07:24 Who owns this memory allocation?
Shrikant Kelkar 2014/05/15 23:12:43 component_list is owner here.
173 component_entry->SetString("id", component_ids[j]);
174 component_entry->SetString("name", item->component.name);
175 component_entry->SetString("version", item->component.version.GetString());
176
177 component_entry->SetString("status",
178 ServiceStatusToString(item->status).c_str());
179
180 component_list->Append(component_entry);
181 }
182
183 return component_list;
184 }
185
186 // static
170 base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes( 187 base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes(
171 ui::ScaleFactor scale_factor) { 188 ui::ScaleFactor scale_factor) {
172 return ResourceBundle::GetSharedInstance(). 189 return ResourceBundle::GetSharedInstance().
173 LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor); 190 LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor);
174 } 191 }
192
193 void ComponentsUI::ComponentEventToString(Events event,
194 std::string* converted_event) {
Sorin Jianu 2014/05/08 22:07:24 Consider renaming the parameter to |event_string|
Shrikant Kelkar 2014/05/15 23:12:43 Done.
195 DCHECK(converted_event != NULL);
196 switch (event) {
197 case COMPONENT_UPDATER_STARTED:
198 *converted_event = "UpdaterStarted";
199 return;
200 case COMPONENT_UPDATER_SLEEPING:
201 *converted_event = "UpdaterSleeping";
202 return;
203 case COMPONENT_UPDATE_FOUND:
204 *converted_event = "UpdateFound";
205 return;
206 case COMPONENT_UPDATE_READY:
207 *converted_event = "UpdateReady";
208 return;
209 case COMPONENT_UPDATED:
210 *converted_event = "ComponentUpdated";
211 return;
212 case COMPONENT_NOT_UPDATED:
213 *converted_event = "ComponentNotUpdated";
214 return;
215 default:
216 *converted_event = "Unknown";
217 return;
218 }
219 }
220
221 std::string ComponentsUI::ServiceStatusToString(
222 component_updater::CrxUpdateItem::Status status) {
223 switch (status) {
224 case component_updater::CrxUpdateItem::kNew:
225 return "new";
226 case component_updater::CrxUpdateItem::kChecking:
227 return "checking";
228 case component_updater::CrxUpdateItem::kCanUpdate:
229 return "update";
230 case component_updater::CrxUpdateItem::kDownloadingDiff:
231 return "downloading_diff";
232 case component_updater::CrxUpdateItem::kDownloading:
233 return "downloading";
234 case component_updater::CrxUpdateItem::kUpdatingDiff:
235 return "updating_diff";
236 case component_updater::CrxUpdateItem::kUpdating:
237 return "updating";
238 case component_updater::CrxUpdateItem::kUpdated:
239 return "updated";
240 case component_updater::CrxUpdateItem::kUpToDate:
241 return "uptodate";
242 case component_updater::CrxUpdateItem::kNoUpdate:
243 return "no_update";
244 case component_updater::CrxUpdateItem::kLastStatus:
245 default:
246 return "Unknown";
247 }
248 return "Unknown";
249 }
250
251 void ComponentsUI::OnEvent(Events event, const std::string& id) {
252 std::string converted_event;
253 ComponentEventToString(event, &converted_event);
254 base::DictionaryValue parameters;
255 parameters.SetString("event", converted_event.c_str());
256 if (!id.empty())
257 parameters.SetString("id", id.c_str());
258 web_ui()->CallJavascriptFunction("onComponentEvent", parameters);
259 }
OLDNEW
« chrome/browser/resources/components.js ('K') | « chrome/browser/ui/webui/components_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698