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

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: Rebase to revision 150108. 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
« no previous file with comments | « chrome/browser/resources/chromeos/diagnostics/main.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
46 // |succeeded|: information was obtained successfully.
47 // |status|: network interfaces information in json. See
48 // DebugDaemonClient::GetNetworkInterfaces() for details.
49 void OnGetNetworkInterfaces(bool succeeded, const std::string& status);
50
39 base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_; 51 base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_;
40 DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler); 52 DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler);
41 }; 53 };
42 54
43 void DiagnosticsWebUIHandler::RegisterMessages() { 55 void DiagnosticsWebUIHandler::RegisterMessages() {
44 web_ui()->RegisterMessageCallback( 56 web_ui()->RegisterMessageCallback(
45 "pageLoaded", 57 "pageLoaded",
46 base::Bind(&DiagnosticsWebUIHandler::OnPageLoaded, 58 base::Bind(&DiagnosticsWebUIHandler::OnPageLoaded,
47 weak_ptr_factory_.GetWeakPtr())); 59 weak_ptr_factory_.GetWeakPtr()));
48 } 60 }
49 61
50 void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) { 62 void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
51 // TODO: invoke debugd methods to retrieve diagnostics information, and 63 chromeos::DebugDaemonClient* debugd_client =
52 // upon completion call javascript function to update status. 64 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
65 DCHECK(debugd_client);
66
67 debugd_client->GetNetworkInterfaces(
68 base::Bind(&DiagnosticsWebUIHandler::OnGetNetworkInterfaces,
69 weak_ptr_factory_.GetWeakPtr()));
70 }
71
72 void DiagnosticsWebUIHandler::OnGetNetworkInterfaces(
73 bool succeeded, const std::string& status) {
74 if (!succeeded)
75 return;
76 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
77 if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) {
78 base::DictionaryValue* result =
79 static_cast<DictionaryValue*>(parsed_value.get());
80 web_ui()->CallJavascriptFunction(kJsApiUpdateConnStatus, *result);
81 }
53 } 82 }
54 83
55 } // namespace 84 } // namespace
56 85
57 //////////////////////////////////////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////////
58 // DiagnosticsUI 87 // DiagnosticsUI
59 88
60 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) 89 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui)
61 : WebUIController(web_ui) { 90 : WebUIController(web_ui) {
62 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler()); 91 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler());
63 92
64 ChromeWebUIDataSource* source = 93 ChromeWebUIDataSource* source =
65 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); 94 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost);
95 source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS);
96 source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS);
66 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); 97 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML);
67 98
68 Profile* profile = Profile::FromWebUI(web_ui); 99 Profile* profile = Profile::FromWebUI(web_ui);
69 ChromeURLDataManager::AddDataSource(profile, source); 100 ChromeURLDataManager::AddDataSource(profile, source);
70 } 101 }
71 102
72 } // namespace chromeos 103 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/diagnostics/main.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698