| OLD | NEW | 
|---|
| 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  Loading... | 
| 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(); | 
| 107   base::DictionaryValue result; | 108   base::DictionaryValue result; | 
| 108   result.Set("components", ComponentsUI::LoadComponents()); | 109   result.Set("components", list); | 
| 109   web_ui()->CallJavascriptFunctionUnsafe("returnComponentsData", result); | 110   web_ui()->CallJavascriptFunctionUnsafe("returnComponentsData", result); | 
| 110 } | 111 } | 
| 111 | 112 | 
| 112 // This function is called when user presses button from html UI. | 113 // This function is called when user presses button from html UI. | 
| 113 // TODO(shrikant): We need to make this button available based on current | 114 // TODO(shrikant): We need to make this button available based on current | 
| 114 // state e.g. If component state is currently updating then we need to disable | 115 // state e.g. If component state is currently updating then we need to disable | 
| 115 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) | 116 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) | 
| 116 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { | 117 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { | 
| 117   if (args->GetSize() != 1) { | 118   if (args->GetSize() != 1) { | 
| 118     NOTREACHED(); | 119     NOTREACHED(); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 156 | 157 | 
| 157 // static | 158 // static | 
| 158 void ComponentsUI::OnDemandUpdate(const std::string& component_id) { | 159 void ComponentsUI::OnDemandUpdate(const std::string& component_id) { | 
| 159   component_updater::ComponentUpdateService* cus = | 160   component_updater::ComponentUpdateService* cus = | 
| 160       g_browser_process->component_updater(); | 161       g_browser_process->component_updater(); | 
| 161   cus->GetOnDemandUpdater().OnDemandUpdate(component_id, | 162   cus->GetOnDemandUpdater().OnDemandUpdate(component_id, | 
| 162                                            component_updater::Callback()); | 163                                            component_updater::Callback()); | 
| 163 } | 164 } | 
| 164 | 165 | 
| 165 // static | 166 // static | 
| 166 std::unique_ptr<base::ListValue> ComponentsUI::LoadComponents() { | 167 base::ListValue* ComponentsUI::LoadComponents() { | 
| 167   component_updater::ComponentUpdateService* cus = | 168   component_updater::ComponentUpdateService* cus = | 
| 168       g_browser_process->component_updater(); | 169       g_browser_process->component_updater(); | 
| 169   std::vector<std::string> component_ids; | 170   std::vector<std::string> component_ids; | 
| 170   component_ids = cus->GetComponentIDs(); | 171   component_ids = cus->GetComponentIDs(); | 
| 171 | 172 | 
| 172   // Construct DictionaryValues to return to UI. | 173   // Construct DictionaryValues to return to UI. | 
| 173   auto component_list = base::MakeUnique<base::ListValue>(); | 174   base::ListValue* component_list = new base::ListValue(); | 
| 174   for (size_t j = 0; j < component_ids.size(); ++j) { | 175   for (size_t j = 0; j < component_ids.size(); ++j) { | 
| 175     update_client::CrxUpdateItem item; | 176     update_client::CrxUpdateItem item; | 
| 176     if (cus->GetComponentDetails(component_ids[j], &item)) { | 177     if (cus->GetComponentDetails(component_ids[j], &item)) { | 
| 177       std::unique_ptr<base::DictionaryValue> component_entry( | 178       std::unique_ptr<base::DictionaryValue> component_entry( | 
| 178           new base::DictionaryValue()); | 179           new base::DictionaryValue()); | 
| 179       component_entry->SetString("id", component_ids[j]); | 180       component_entry->SetString("id", component_ids[j]); | 
| 180       component_entry->SetString("name", item.component.name); | 181       component_entry->SetString("name", item.component.name); | 
| 181       component_entry->SetString("version", item.component.version.GetString()); | 182       component_entry->SetString("version", item.component.version.GetString()); | 
| 182       component_entry->SetString("status", ServiceStatusToString(item.state)); | 183       component_entry->SetString("status", ServiceStatusToString(item.state)); | 
| 183       component_list->Append(std::move(component_entry)); | 184       component_list->Append(std::move(component_entry)); | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 254     if (event == Events::COMPONENT_UPDATED) { | 255     if (event == Events::COMPONENT_UPDATED) { | 
| 255       auto* component_updater = g_browser_process->component_updater(); | 256       auto* component_updater = g_browser_process->component_updater(); | 
| 256       update_client::CrxUpdateItem item; | 257       update_client::CrxUpdateItem item; | 
| 257       if (component_updater->GetComponentDetails(id, &item)) | 258       if (component_updater->GetComponentDetails(id, &item)) | 
| 258         parameters.SetString("version", item.component.version.GetString()); | 259         parameters.SetString("version", item.component.version.GetString()); | 
| 259     } | 260     } | 
| 260     parameters.SetString("id", id); | 261     parameters.SetString("id", id); | 
| 261   } | 262   } | 
| 262   web_ui()->CallJavascriptFunctionUnsafe("onComponentEvent", parameters); | 263   web_ui()->CallJavascriptFunctionUnsafe("onComponentEvent", parameters); | 
| 263 } | 264 } | 
| OLD | NEW | 
|---|