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

Unified 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: Code review 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 side-by-side diff with in-line comments
Download patch
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..467cad10af9308bf4c079f3e7d7574272a118696 100644
--- a/chrome/browser/ui/webui/components_ui.cc
+++ b/chrome/browser/ui/webui/components_ui.cc
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/component_updater_service.h"
+#include "chrome/browser/component_updater/crx_update_item.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_paths.h"
@@ -75,8 +76,6 @@ class ComponentsDOMHandler : public WebUIMessageHandler {
void HandleCheckUpdate(const base::ListValue* args);
private:
- void LoadComponents();
-
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ComponentsDOMHandler);
@@ -86,18 +85,23 @@ 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)));
}
void ComponentsDOMHandler::HandleRequestComponentsData(
const base::ListValue* args) {
- LoadComponents();
+ base::ListValue* list = ComponentsUI::LoadComponents();
+ base::DictionaryValue result;
+ result.Set("components", list);
+ web_ui()->CallJavascriptFunction("returnComponentsData", result);
}
// This function is called when user presses button from html UI.
@@ -119,30 +123,6 @@ void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) {
ComponentsUI::OnDemandUpdate(component_id);
}
-void ComponentsDOMHandler::LoadComponents() {
- component_updater::ComponentUpdateService* cus =
- g_browser_process->component_updater();
- std::vector<component_updater::CrxComponentInfo> components;
- cus->GetComponents(&components);
-
- // Construct DictionaryValues to return to UI.
- base::ListValue* component_list = new base::ListValue();
- for (size_t j = 0; j < components.size(); ++j) {
- const component_updater::CrxComponentInfo& component = components[j];
-
- base::DictionaryValue* component_entry = new base::DictionaryValue();
- component_entry->SetString("id", component.id);
- component_entry->SetString("name", component.name);
- component_entry->SetString("version", component.version);
-
- component_list->Append(component_entry);
- }
-
- base::DictionaryValue results;
- results.Set("components", component_list);
- web_ui()->CallJavascriptFunction("returnComponentsData", results);
-}
-
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -157,6 +137,16 @@ 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);
+}
+
+ComponentsUI::~ComponentsUI() {
+ component_updater::ComponentUpdateService* cus =
+ g_browser_process->component_updater();
+ if (cus)
+ cus->RemoveObserver(this);
}
// static
@@ -167,8 +157,105 @@ void ComponentsUI::OnDemandUpdate(const std::string& component_id) {
}
// static
+base::ListValue* ComponentsUI::LoadComponents() {
+ component_updater::ComponentUpdateService* cus =
+ g_browser_process->component_updater();
+ std::vector<std::string> component_ids;
+ component_ids = cus->GetComponentIDs();
+
+ // Construct DictionaryValues to return to UI.
+ base::ListValue* component_list = new base::ListValue();
+ for (size_t j = 0; j < component_ids.size(); ++j) {
+ const component_updater::CrxUpdateItem* item = cus->GetComponentDetails(
+ component_ids[j]);
+ if (item) {
+ base::DictionaryValue* component_entry = new base::DictionaryValue();
+ component_entry->SetString("id", component_ids[j]);
+ component_entry->SetString("name", item->component.name);
+ component_entry->SetString("version",
+ item->component.version.GetString());
+
+ component_entry->SetString("status",
+ ServiceStatusToString(item->status).c_str());
+
+ component_list->Append(component_entry);
+ }
+ }
+
+ return component_list;
+}
+
+// static
base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes(
ui::ScaleFactor scale_factor) {
return ResourceBundle::GetSharedInstance().
LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor);
}
+
+void ComponentsUI::ComponentEventToString(Events event,
+ std::string* event_string) {
+ DCHECK(event_string != NULL);
+ switch (event) {
+ case COMPONENT_UPDATER_STARTED:
+ *event_string = "UpdaterStarted";
+ return;
+ case COMPONENT_UPDATER_SLEEPING:
+ *event_string = "UpdaterSleeping";
+ return;
+ case COMPONENT_UPDATE_FOUND:
+ *event_string = "UpdateFound";
+ return;
+ case COMPONENT_UPDATE_READY:
+ *event_string = "UpdateReady";
+ return;
+ case COMPONENT_UPDATED:
+ *event_string = "ComponentUpdated";
+ return;
+ case COMPONENT_NOT_UPDATED:
+ *event_string = "ComponentNotUpdated";
+ return;
+ default:
+ *event_string = "Unknown";
+ return;
+ }
+}
+
+std::string ComponentsUI::ServiceStatusToString(
+ component_updater::CrxUpdateItem::Status status) {
+ switch (status) {
+ case component_updater::CrxUpdateItem::kNew:
+ return "new";
+ case component_updater::CrxUpdateItem::kChecking:
+ return "checking";
+ case component_updater::CrxUpdateItem::kCanUpdate:
+ return "update";
+ case component_updater::CrxUpdateItem::kDownloadingDiff:
+ return "downloading_diff";
+ case component_updater::CrxUpdateItem::kDownloading:
+ return "downloading";
+ case component_updater::CrxUpdateItem::kUpdatingDiff:
+ return "updating_diff";
+ case component_updater::CrxUpdateItem::kUpdating:
+ return "updating";
+ case component_updater::CrxUpdateItem::kUpdated:
+ return "updated";
+ case component_updater::CrxUpdateItem::kUpToDate:
+ return "uptodate";
+ case component_updater::CrxUpdateItem::kNoUpdate:
+ return "no_update";
+ case component_updater::CrxUpdateItem::kLastStatus:
+ default:
+ return "Unknown";
+ }
+ return "Unknown";
+}
+
+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);
+}
« chrome/browser/ui/webui/components_ui.h ('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