Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc |
| diff --git a/chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc b/chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc |
| index 40768cf22b1944a4e2af49cc536c05ebdb689b2a..a8e987831265045e422e88262dba942ad554e4f9 100644 |
| --- a/chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc |
| +++ b/chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc |
| @@ -5,10 +5,13 @@ |
| #include "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h" |
| #include "base/bind.h" |
| +#include "base/json/json_reader.h" |
| #include "base/memory/weak_ptr.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| #include "chrome/common/url_constants.h" |
| +#include "chromeos/dbus/debug_daemon_client.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/web_ui.h" |
| #include "content/public/browser/web_ui_message_handler.h" |
| @@ -18,6 +21,9 @@ namespace chromeos { |
| namespace { |
| +// JS API callback names. |
| +const char kJsApiUpdateConnStatus[] = "updateConnectivityStatus"; |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // DiagnosticsHandler |
| @@ -36,6 +42,9 @@ class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { |
| // Called when the page is first loaded. |
| void OnPageLoaded(const base::ListValue* args); |
| + // Called when GetNetworkInterfaces() is complete. |
|
James Hawkins
2012/08/06 16:05:39
nit: Document parameters.
hshi1
2012/08/06 17:30:55
Done.
|
| + void OnGetNetworkInterfaces(bool succeeded, const std::string& status); |
| + |
| base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler); |
| }; |
| @@ -48,8 +57,26 @@ void DiagnosticsWebUIHandler::RegisterMessages() { |
| } |
| void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) { |
| - // TODO: invoke debugd methods to retrieve diagnostics information, and |
| - // upon completion call javascript function to update status. |
| + chromeos::DebugDaemonClient* debugd_client = |
| + chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| + DCHECK(debugd_client); |
| + |
| + debugd_client->GetNetworkInterfaces( |
| + base::Bind(&DiagnosticsWebUIHandler::OnGetNetworkInterfaces, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void DiagnosticsWebUIHandler::OnGetNetworkInterfaces( |
| + bool succeeded, |
| + const std::string& status) { |
|
James Hawkins
2012/08/06 16:05:39
Optional nit: This parameter can fit on the line a
hshi1
2012/08/06 17:30:55
Done.
|
| + if (succeeded) { |
|
James Hawkins
2012/08/06 16:05:39
Optional nit: Reverse the logic and return early t
hshi1
2012/08/06 17:30:55
Done.
|
| + scoped_ptr<Value> parsed_value(base::JSONReader::Read(status)); |
| + if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) { |
| + base::DictionaryValue* result = |
| + static_cast<DictionaryValue*>(parsed_value.get()); |
| + web_ui()->CallJavascriptFunction(kJsApiUpdateConnStatus, *result); |
| + } |
| + } |
| } |
| } // namespace |
| @@ -63,6 +90,8 @@ DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) |
| ChromeWebUIDataSource* source = |
| new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); |
| + source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS); |
| + source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS); |
| source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); |
| Profile* profile = Profile::FromWebUI(web_ui); |