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

Side by Side Diff: chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.cc

Issue 10827148: diagnostics: Add connectivity section to chrome://diagnostics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tweaking to conform to other chrome/about page style. Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/diagnostics/diagnostics_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h"
8 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "chromeos/dbus/debug_daemon_client.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_ui.h" 16 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_message_handler.h" 17 #include "content/public/browser/web_ui_message_handler.h"
15 #include "grit/browser_resources.h" 18 #include "grit/browser_resources.h"
16 19
17 namespace chromeos { 20 namespace chromeos {
18 21
19 namespace { 22 namespace {
20 23
24 // JS API callback names.
25 const char kJsApiUpdateConnStatus[] = "updateConnectivityStatus";
26
21 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
22 // DiagnosticsHandler 28 // DiagnosticsHandler
23 29
24 // Class to handle messages from chrome://diagnostics. 30 // Class to handle messages from chrome://diagnostics.
25 class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { 31 class DiagnosticsWebUIHandler : public content::WebUIMessageHandler {
26 public: 32 public:
27 DiagnosticsWebUIHandler() 33 DiagnosticsWebUIHandler()
28 : weak_ptr_factory_(this) { 34 : weak_ptr_factory_(this) {
29 } 35 }
30 virtual ~DiagnosticsWebUIHandler() {} 36 virtual ~DiagnosticsWebUIHandler() {}
31 37
32 private: 38 private:
33 // WebUIMessageHandler implementation. 39 // WebUIMessageHandler implementation.
34 virtual void RegisterMessages() OVERRIDE; 40 virtual void RegisterMessages() OVERRIDE;
35 41
36 // Called when the page is first loaded. 42 // Called when the page is first loaded.
37 void OnPageLoaded(const base::ListValue* args); 43 void OnPageLoaded(const base::ListValue* args);
38 44
45 // Called when GetNetworkInterfaces() is complete.
James Hawkins 2012/08/06 16:05:39 nit: Document parameters.
hshi1 2012/08/06 17:30:55 Done.
46 void OnGetNetworkInterfaces(bool succeeded, const std::string& status);
47
39 base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_; 48 base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_;
40 DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler); 49 DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler);
41 }; 50 };
42 51
43 void DiagnosticsWebUIHandler::RegisterMessages() { 52 void DiagnosticsWebUIHandler::RegisterMessages() {
44 web_ui()->RegisterMessageCallback( 53 web_ui()->RegisterMessageCallback(
45 "pageLoaded", 54 "pageLoaded",
46 base::Bind(&DiagnosticsWebUIHandler::OnPageLoaded, 55 base::Bind(&DiagnosticsWebUIHandler::OnPageLoaded,
47 weak_ptr_factory_.GetWeakPtr())); 56 weak_ptr_factory_.GetWeakPtr()));
48 } 57 }
49 58
50 void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) { 59 void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
51 // TODO: invoke debugd methods to retrieve diagnostics information, and 60 chromeos::DebugDaemonClient* debugd_client =
52 // upon completion call javascript function to update status. 61 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
62 DCHECK(debugd_client);
63
64 debugd_client->GetNetworkInterfaces(
65 base::Bind(&DiagnosticsWebUIHandler::OnGetNetworkInterfaces,
66 weak_ptr_factory_.GetWeakPtr()));
67 }
68
69 void DiagnosticsWebUIHandler::OnGetNetworkInterfaces(
70 bool succeeded,
71 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.
72 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.
73 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
74 if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) {
75 base::DictionaryValue* result =
76 static_cast<DictionaryValue*>(parsed_value.get());
77 web_ui()->CallJavascriptFunction(kJsApiUpdateConnStatus, *result);
78 }
79 }
53 } 80 }
54 81
55 } // namespace 82 } // namespace
56 83
57 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
58 // DiagnosticsUI 85 // DiagnosticsUI
59 86
60 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) 87 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui)
61 : WebUIController(web_ui) { 88 : WebUIController(web_ui) {
62 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler()); 89 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler());
63 90
64 ChromeWebUIDataSource* source = 91 ChromeWebUIDataSource* source =
65 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); 92 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost);
93 source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS);
94 source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS);
66 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); 95 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML);
67 96
68 Profile* profile = Profile::FromWebUI(web_ui); 97 Profile* profile = Profile::FromWebUI(web_ui);
69 ChromeURLDataManager::AddDataSource(profile, source); 98 ChromeURLDataManager::AddDataSource(profile, source);
70 } 99 }
71 100
72 } // namespace chromeos 101 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698