| 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 <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/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/component_updater/component_updater_service.h" | 18 #include "components/component_updater/component_updater_service.h" |
| 19 #include "components/component_updater/crx_update_item.h" | |
| 20 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
| 21 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
| 22 #include "content/public/browser/web_ui_message_handler.h" | 21 #include "content/public/browser/web_ui_message_handler.h" |
| 23 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
| 24 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 27 | 26 |
| 28 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" | 28 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // static | 159 // static |
| 161 base::ListValue* ComponentsUI::LoadComponents() { | 160 base::ListValue* ComponentsUI::LoadComponents() { |
| 162 component_updater::ComponentUpdateService* cus = | 161 component_updater::ComponentUpdateService* cus = |
| 163 g_browser_process->component_updater(); | 162 g_browser_process->component_updater(); |
| 164 std::vector<std::string> component_ids; | 163 std::vector<std::string> component_ids; |
| 165 component_ids = cus->GetComponentIDs(); | 164 component_ids = cus->GetComponentIDs(); |
| 166 | 165 |
| 167 // Construct DictionaryValues to return to UI. | 166 // Construct DictionaryValues to return to UI. |
| 168 base::ListValue* component_list = new base::ListValue(); | 167 base::ListValue* component_list = new base::ListValue(); |
| 169 for (size_t j = 0; j < component_ids.size(); ++j) { | 168 for (size_t j = 0; j < component_ids.size(); ++j) { |
| 170 component_updater::CrxUpdateItem item; | 169 update_client::CrxUpdateItem item; |
| 171 if (cus->GetComponentDetails(component_ids[j], &item)) { | 170 if (cus->GetComponentDetails(component_ids[j], &item)) { |
| 172 base::DictionaryValue* component_entry = new base::DictionaryValue(); | 171 base::DictionaryValue* component_entry = new base::DictionaryValue(); |
| 173 component_entry->SetString("id", component_ids[j]); | 172 component_entry->SetString("id", component_ids[j]); |
| 174 component_entry->SetString("name", item.component.name); | 173 component_entry->SetString("name", item.component.name); |
| 175 component_entry->SetString("version", item.component.version.GetString()); | 174 component_entry->SetString("version", item.component.version.GetString()); |
| 176 component_entry->SetString("status", ServiceStatusToString(item.status)); | 175 component_entry->SetString("status", ServiceStatusToString(item.status)); |
| 177 component_list->Append(component_entry); | 176 component_list->Append(component_entry); |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 202 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_UPDATED); | 201 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_UPDATED); |
| 203 case COMPONENT_NOT_UPDATED: | 202 case COMPONENT_NOT_UPDATED: |
| 204 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_NOTUPDATED); | 203 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_NOTUPDATED); |
| 205 case COMPONENT_UPDATE_DOWNLOADING: | 204 case COMPONENT_UPDATE_DOWNLOADING: |
| 206 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_DOWNLOADING); | 205 return l10n_util::GetStringUTF16(IDS_COMPONENTS_EVT_STATUS_DOWNLOADING); |
| 207 } | 206 } |
| 208 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); | 207 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); |
| 209 } | 208 } |
| 210 | 209 |
| 211 base::string16 ComponentsUI::ServiceStatusToString( | 210 base::string16 ComponentsUI::ServiceStatusToString( |
| 212 component_updater::CrxUpdateItem::Status status) { | 211 update_client::CrxUpdateItem::Status status) { |
| 213 switch (status) { | 212 switch (status) { |
| 214 case component_updater::CrxUpdateItem::kNew: | 213 case update_client::CrxUpdateItem::kNew: |
| 215 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_NEW); | 214 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_NEW); |
| 216 case component_updater::CrxUpdateItem::kChecking: | 215 case update_client::CrxUpdateItem::kChecking: |
| 217 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_CHECKING); | 216 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_CHECKING); |
| 218 case component_updater::CrxUpdateItem::kCanUpdate: | 217 case update_client::CrxUpdateItem::kCanUpdate: |
| 219 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATE); | 218 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATE); |
| 220 case component_updater::CrxUpdateItem::kDownloadingDiff: | 219 case update_client::CrxUpdateItem::kDownloadingDiff: |
| 221 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_DNL_DIFF); | 220 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_DNL_DIFF); |
| 222 case component_updater::CrxUpdateItem::kDownloading: | 221 case update_client::CrxUpdateItem::kDownloading: |
| 223 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_DNL); | 222 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_DNL); |
| 224 case component_updater::CrxUpdateItem::kUpdatingDiff: | 223 case update_client::CrxUpdateItem::kUpdatingDiff: |
| 225 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDT_DIFF); | 224 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDT_DIFF); |
| 226 case component_updater::CrxUpdateItem::kUpdating: | 225 case update_client::CrxUpdateItem::kUpdating: |
| 227 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATING); | 226 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATING); |
| 228 case component_updater::CrxUpdateItem::kUpdated: | 227 case update_client::CrxUpdateItem::kUpdated: |
| 229 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATED); | 228 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPDATED); |
| 230 case component_updater::CrxUpdateItem::kUpToDate: | 229 case update_client::CrxUpdateItem::kUpToDate: |
| 231 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPTODATE); | 230 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPTODATE); |
| 232 case component_updater::CrxUpdateItem::kNoUpdate: | 231 case update_client::CrxUpdateItem::kNoUpdate: |
| 233 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_NOUPDATE); | 232 return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_NOUPDATE); |
| 234 case component_updater::CrxUpdateItem::kLastStatus: | 233 case update_client::CrxUpdateItem::kLastStatus: |
| 235 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); | 234 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); |
| 236 } | 235 } |
| 237 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); | 236 return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); |
| 238 } | 237 } |
| 239 | 238 |
| 240 void ComponentsUI::OnEvent(Events event, const std::string& id) { | 239 void ComponentsUI::OnEvent(Events event, const std::string& id) { |
| 241 base::DictionaryValue parameters; | 240 base::DictionaryValue parameters; |
| 242 parameters.SetString("event", ComponentEventToString(event)); | 241 parameters.SetString("event", ComponentEventToString(event)); |
| 243 if (!id.empty()) { | 242 if (!id.empty()) { |
| 244 using component_updater::ComponentUpdateService; | 243 using component_updater::ComponentUpdateService; |
| 245 if (event == ComponentUpdateService::Observer::COMPONENT_UPDATED) { | 244 if (event == ComponentUpdateService::Observer::COMPONENT_UPDATED) { |
| 246 ComponentUpdateService* cus = g_browser_process->component_updater(); | 245 ComponentUpdateService* cus = g_browser_process->component_updater(); |
| 247 component_updater::CrxUpdateItem item; | 246 update_client::CrxUpdateItem item; |
| 248 if (cus->GetComponentDetails(id, &item)) | 247 if (cus->GetComponentDetails(id, &item)) |
| 249 parameters.SetString("version", item.component.version.GetString()); | 248 parameters.SetString("version", item.component.version.GetString()); |
| 250 } | 249 } |
| 251 parameters.SetString("id", id); | 250 parameters.SetString("id", id); |
| 252 } | 251 } |
| 253 web_ui()->CallJavascriptFunction("onComponentEvent", parameters); | 252 web_ui()->CallJavascriptFunction("onComponentEvent", parameters); |
| 254 } | 253 } |
| OLD | NEW |