Chromium Code Reviews| Index: chrome/browser/ui/webui/components_ui.cc |
| diff --git a/chrome/browser/ui/webui/components_ui.cc b/chrome/browser/ui/webui/components_ui.cc |
| index e5cce27f49a3874dd03e8144820f3d736545d4e2..301ae27c6bce62f9bd3570eea82135aeb21a04d4 100644 |
| --- a/chrome/browser/ui/webui/components_ui.cc |
| +++ b/chrome/browser/ui/webui/components_ui.cc |
| @@ -76,6 +76,8 @@ class ComponentsDOMHandler : public WebUIMessageHandler { |
| private: |
| void LoadComponents(); |
| + void ComponentsDOMHandler::HandleRequestComponentStatus( |
| + const base::ListValue* args); |
| content::NotificationRegistrar registrar_; |
| @@ -86,13 +88,20 @@ ComponentsDOMHandler::ComponentsDOMHandler() { |
| } |
| void ComponentsDOMHandler::RegisterMessages() { |
| - web_ui()->RegisterMessageCallback("requestComponentsData", |
| + web_ui()->RegisterMessageCallback( |
| + "requestComponentsData", |
| base::Bind(&ComponentsDOMHandler::HandleRequestComponentsData, |
| base::Unretained(this))); |
| - web_ui()->RegisterMessageCallback("checkUpdate", |
| + web_ui()->RegisterMessageCallback( |
| + "checkUpdate", |
| base::Bind(&ComponentsDOMHandler::HandleCheckUpdate, |
| base::Unretained(this))); |
| + |
| + web_ui()->RegisterMessageCallback( |
| + "requestComponentStatus", |
| + base::Bind(&ComponentsDOMHandler::HandleRequestComponentStatus, |
| + base::Unretained(this))); |
| } |
| void ComponentsDOMHandler::HandleRequestComponentsData( |
| @@ -119,6 +128,37 @@ void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { |
| ComponentsUI::OnDemandUpdate(component_id); |
| } |
| +void ComponentsDOMHandler::HandleRequestComponentStatus( |
| + const base::ListValue* args) { |
| + if (args->GetSize() != 1) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + std::string component_id; |
| + if (!args->GetString(0, &component_id)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + component_updater::ComponentUpdateService* cus = |
| + g_browser_process->component_updater(); |
| + component_updater::ComponentUpdateService::Status status = |
| + cus->GetComponentStatus(component_id); |
| + |
| + std::string string_status; |
| + if (status == component_updater::ComponentUpdateService::kInProgress) |
| + string_status = "in-progress"; |
| + else if (status == component_updater::ComponentUpdateService::kOk) |
| + string_status = "ok"; |
| + else |
| + string_status = "error"; |
| + |
| + web_ui()->CallJavascriptFunction("returnComponentStatus", |
| + base::StringValue(component_id), |
| + base::StringValue(string_status)); |
| +} |
| + |
| void ComponentsDOMHandler::LoadComponents() { |
| component_updater::ComponentUpdateService* cus = |
| g_browser_process->component_updater(); |
| @@ -134,6 +174,17 @@ void ComponentsDOMHandler::LoadComponents() { |
| component_entry->SetString("id", component.id); |
| component_entry->SetString("name", component.name); |
| component_entry->SetString("version", component.version); |
| + switch (component.status) { |
| + case component_updater::ComponentUpdateService::kInProgress: |
| + component_entry->SetString("status", "in-progress"); |
| + break; |
| + case component_updater::ComponentUpdateService::kOk: |
| + component_entry->SetString("status", "ok"); |
| + break; |
| + case component_updater::ComponentUpdateService::kError: |
| + component_entry->SetString("status", "error"); |
| + break; |
| + } |
| component_list->Append(component_entry); |
| } |
| @@ -157,6 +208,9 @@ ComponentsUI::ComponentsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| // Set up the chrome://components/ source. |
| Profile* profile = Profile::FromWebUI(web_ui); |
| content::WebUIDataSource::Add(profile, CreateComponentsUIHTMLSource(profile)); |
| + component_updater::ComponentUpdateService* cus = |
| + g_browser_process->component_updater(); |
| + cus->AddObserver(this); |
|
Sorin Jianu
2014/04/28 22:46:11
Are we removing the observer anywhere? Is there an
|
| } |
| // static |
| @@ -172,3 +226,41 @@ base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes( |
| return ResourceBundle::GetSharedInstance(). |
| LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor); |
| } |
| + |
| +void ComponentsUI::ComponentEventToString(Events event, |
| + std::string* converted_event) { |
| + DCHECK(converted_event != NULL); |
|
Sorin Jianu
2014/04/28 22:46:11
It seems converted_event is some kind of a an even
|
| + switch (event) { |
| + case COMPONENT_UPDATER_STARTED: |
| + *converted_event = "UpdaterStarted"; |
| + return; |
| + case COMPONENT_UPDATER_SLEEPING: |
| + *converted_event = "UpdaterSleeping"; |
| + return; |
| + case COMPONENT_UPDATE_FOUND: |
| + *converted_event = "UpdateFound"; |
| + return; |
| + case COMPONENT_UPDATE_READY: |
| + *converted_event = "UpdateReady"; |
| + return; |
| + case COMPONENT_UPDATED: |
| + *converted_event = "ComponentUpdated"; |
| + return; |
| + case COMPONENT_NOT_UPDATED: |
| + *converted_event = "ComponentNotUpdated"; |
| + return; |
| + default: |
| + *converted_event = "Unknown"; |
| + return; |
| + } |
| +} |
| + |
| +void ComponentsUI::OnEvent(Events event, const std::string& id) { |
| + std::string converted_event; |
| + ComponentEventToString(event, &converted_event); |
| + base::DictionaryValue parameters; |
| + parameters.SetString("event", converted_event.c_str()); |
| + if (!id.empty()) |
| + parameters.SetString("id", id.c_str()); |
| + web_ui()->CallJavascriptFunction("onComponentEvent", parameters); |
| +} |