Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/system_info_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 21 #include "chrome/browser/chromeos/system/sysinfo_provider.h" | 21 #include "chrome/browser/chromeos/syslogs/syslogs_fetcher.h" |
| 22 #include "chrome/browser/chromeos/system/syslogs_provider.h" | 22 #include "chrome/browser/chromeos/syslogs/syslogs_fetcher_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/jstemplate_builder.h" | 26 #include "chrome/common/jstemplate_builder.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 31 #include "content/public/browser/web_ui_message_handler.h" | 31 #include "content/public/browser/web_ui_message_handler.h" |
| 32 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 51 virtual void StartDataRequest(const std::string& path, | 51 virtual void StartDataRequest(const std::string& path, |
| 52 bool is_incognito, | 52 bool is_incognito, |
| 53 int request_id); | 53 int request_id); |
| 54 virtual std::string GetMimeType(const std::string&) const { | 54 virtual std::string GetMimeType(const std::string&) const { |
| 55 return "text/html"; | 55 return "text/html"; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 ~SystemInfoUIHTMLSource() {} | 59 ~SystemInfoUIHTMLSource() {} |
| 60 | 60 |
| 61 void SyslogsComplete(chromeos::system::LogDictionaryType* sys_info, | 61 void SysInfoComplete(chromeos::SysLogsResponse* response); |
| 62 std::string* ignored_content); | |
| 63 void SysInfoComplete(chromeos::system::SysInfoResponse* response); | |
| 64 void RequestComplete(); | 62 void RequestComplete(); |
| 65 void WaitForData(); | 63 void WaitForData(); |
| 66 | 64 |
| 67 CancelableRequestConsumer logs_consumer_; | |
| 68 CancelableRequestConsumer sys_info_consumer_; | |
| 69 | |
| 70 // Stored data from StartDataRequest() | 65 // Stored data from StartDataRequest() |
| 71 std::string path_; | 66 std::string path_; |
| 72 int request_id_; | 67 int request_id_; |
| 73 | 68 |
| 74 int pending_requests_; | 69 chromeos::SysLogsResponse* sys_info_; |
| 75 chromeos::system::LogDictionaryType* logs_; | 70 base::WeakPtrFactory<SystemInfoUIHTMLSource> weak_ptr_factory_; |
| 76 chromeos::system::SysInfoResponse* sys_info_; | |
| 77 scoped_ptr<chromeos::system::SysInfoProvider> sys_info_provider_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource); | 71 DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource); |
| 80 }; | 72 }; |
| 81 | 73 |
| 82 // The handler for Javascript messages related to the "system" view. | 74 // The handler for Javascript messages related to the "system" view. |
| 83 class SystemInfoHandler : public WebUIMessageHandler, | 75 class SystemInfoHandler : public WebUIMessageHandler, |
| 84 public base::SupportsWeakPtr<SystemInfoHandler> { | 76 public base::SupportsWeakPtr<SystemInfoHandler> { |
| 85 public: | 77 public: |
| 86 SystemInfoHandler(); | 78 SystemInfoHandler(); |
| 87 virtual ~SystemInfoHandler(); | 79 virtual ~SystemInfoHandler(); |
| 88 | 80 |
| 89 // WebUIMessageHandler implementation. | 81 // WebUIMessageHandler implementation. |
| 90 virtual void RegisterMessages() OVERRIDE; | 82 virtual void RegisterMessages() OVERRIDE; |
| 91 | 83 |
| 92 private: | 84 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); | 85 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
| 97 // | 89 // |
| 98 // SystemInfoUIHTMLSource | 90 // SystemInfoUIHTMLSource |
| 99 // | 91 // |
| 100 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
| 101 | 93 |
| 102 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() | 94 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() |
| 103 : DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()), | 95 : DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()), |
| 104 request_id_(0), logs_(NULL), sys_info_(NULL), | 96 request_id_(0), sys_info_(NULL), |
| 105 sys_info_provider_(chromeos::system::SysInfoProvider::Create()) { | 97 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 106 } | 98 } |
| 107 | 99 |
| 108 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, | 100 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, |
| 109 bool is_incognito, | 101 bool is_incognito, |
| 110 int request_id) { | 102 int request_id) { |
| 111 path_ = path; | 103 path_ = path; |
| 112 request_id_ = request_id; | 104 request_id_ = request_id; |
| 113 pending_requests_ = 0; | |
| 114 | 105 |
| 115 chromeos::system::SyslogsProvider* provider = | 106 chromeos::SysLogsFetcher * fetcher = |
| 116 chromeos::system::SyslogsProvider::GetInstance(); | 107 chromeos::SysLogsFetcherFactory::GetInstance()->CreateFetcher(); |
| 117 if (provider) { | 108 fetcher->Fetch(base::Bind( |
| 118 provider->RequestSyslogs( | 109 &SystemInfoUIHTMLSource::SysInfoComplete, |
| 119 false, // don't compress. | 110 weak_ptr_factory_.GetWeakPtr())); |
| 120 chromeos::system::SyslogsProvider::SYSLOGS_SYSINFO, | |
| 121 &logs_consumer_, | |
| 122 base::Bind(&SystemInfoUIHTMLSource::SyslogsComplete, | |
| 123 base::Unretained(this))); | |
| 124 pending_requests_++; | |
| 125 } | |
| 126 | 111 |
| 127 sys_info_provider_->Fetch(&sys_info_consumer_, | |
| 128 base::Bind( | |
| 129 &SystemInfoUIHTMLSource::SysInfoComplete, | |
| 130 base::Unretained(this))); | |
| 131 pending_requests_++; | |
| 132 } | 112 } |
| 133 | 113 |
| 134 void SystemInfoUIHTMLSource::SyslogsComplete( | |
| 135 chromeos::system::LogDictionaryType* sys_info, | |
| 136 std::string* ignored_content) { | |
| 137 logs_ = sys_info; | |
| 138 RequestComplete(); | |
| 139 } | |
| 140 | 114 |
| 141 void SystemInfoUIHTMLSource::SysInfoComplete( | 115 void SystemInfoUIHTMLSource::SysInfoComplete( |
| 142 chromeos::system::SysInfoResponse* sys_info) { | 116 chromeos::SysLogsResponse* sys_info) { |
| 143 sys_info_ = sys_info; | 117 sys_info_ = sys_info; |
| 144 RequestComplete(); | 118 RequestComplete(); |
| 145 } | 119 } |
| 146 | 120 |
| 147 void SystemInfoUIHTMLSource::RequestComplete() { | 121 void SystemInfoUIHTMLSource::RequestComplete() { |
| 148 if (--pending_requests_) | |
| 149 return; | |
| 150 | |
| 151 DictionaryValue strings; | 122 DictionaryValue strings; |
| 152 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); | 123 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); |
| 153 strings.SetString("description", | 124 strings.SetString("description", |
| 154 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); | 125 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); |
| 155 strings.SetString("table_title", | 126 strings.SetString("table_title", |
| 156 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); | 127 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); |
| 157 strings.SetString("expand_all_btn", | 128 strings.SetString("expand_all_btn", |
| 158 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); | 129 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); |
| 159 strings.SetString("collapse_all_btn", | 130 strings.SetString("collapse_all_btn", |
| 160 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); | 131 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); |
| 161 strings.SetString("expand_btn", | 132 strings.SetString("expand_btn", |
| 162 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); | 133 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); |
| 163 strings.SetString("collapse_btn", | 134 strings.SetString("collapse_btn", |
| 164 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); | 135 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); |
| 165 SetFontAndTextDirection(&strings); | 136 SetFontAndTextDirection(&strings); |
| 166 | 137 if (sys_info_) |
| 167 if (logs_ || sys_info_) { | 138 { |
| 168 ListValue* details = new ListValue(); | 139 ListValue* details = new ListValue(); |
| 169 strings.Set("details", details); | 140 strings.Set("details", details); |
| 170 if (logs_) { | 141 |
| 171 chromeos::system::LogDictionaryType::iterator it; | 142 chromeos::SysLogsResponse::iterator it; |
| 172 for (it = logs_->begin(); it != logs_->end(); ++it) { | 143 for (it = sys_info_->begin(); it != sys_info_->end(); ++it) { |
| 173 DictionaryValue* val = new DictionaryValue; | 144 DictionaryValue* val = new DictionaryValue; |
| 174 val->SetString("stat_name", it->first); | 145 val->SetString("stat_name", it->first); |
| 175 val->SetString("stat_value", it->second); | 146 val->SetString("stat_value", it->second); |
| 176 details->Append(val); | 147 details->Append(val); |
| 177 } | |
| 178 delete logs_; | |
| 179 } | 148 } |
| 180 if (sys_info_) { | 149 delete sys_info_; |
|
rkc
2012/08/06 18:30:18
Even though a delete null is a NOP, it's move effi
tudalex(Chromium)
2012/08/06 19:14:22
It is inside the if block, it's not inside the for
| |
| 181 chromeos::system::SysInfoResponse::iterator it; | |
| 182 for (it = sys_info_->begin(); it != sys_info_->end(); ++it) { | |
| 183 DictionaryValue* val = new DictionaryValue; | |
| 184 // Prefix stats coming from debugd with 'debugd-' for now. The code that | |
| 185 // displays stats can only handle one stat with a given name, so this | |
| 186 // prevents names from overlapping. Once the duplicates have been | |
| 187 // removed from userfeedback's list by | |
| 188 // <https://gerrit.chromium.org/gerrit/25106>, the prefix can go away. | |
| 189 val->SetString("stat_name", "debugd-" + it->first); | |
| 190 val->SetString("stat_value", it->second); | |
| 191 details->Append(val); | |
| 192 } | |
| 193 delete sys_info_; | |
| 194 } | |
| 195 strings.SetString("anchor", path_); | 150 strings.SetString("anchor", path_); |
| 196 } | 151 } |
| 197 static const base::StringPiece systeminfo_html( | 152 static const base::StringPiece systeminfo_html( |
| 198 ResourceBundle::GetSharedInstance().GetRawDataResource( | 153 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 199 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); | 154 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); |
| 200 std::string full_html = jstemplate_builder::GetTemplatesHtml( | 155 std::string full_html = jstemplate_builder::GetTemplatesHtml( |
| 201 systeminfo_html, &strings, "t" /* template root node id */); | 156 systeminfo_html, &strings, "t" /* template root node id */); |
| 202 | |
| 203 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); | 157 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); |
| 204 } | 158 } |
| 205 | 159 |
| 206 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 207 // | 161 // |
| 208 // SystemInfoHandler | 162 // SystemInfoHandler |
| 209 // | 163 // |
| 210 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
| 211 SystemInfoHandler::SystemInfoHandler() { | 165 SystemInfoHandler::SystemInfoHandler() { |
| 212 } | 166 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 226 | 180 |
| 227 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 181 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 228 SystemInfoHandler* handler = new SystemInfoHandler(); | 182 SystemInfoHandler* handler = new SystemInfoHandler(); |
| 229 web_ui->AddMessageHandler(handler); | 183 web_ui->AddMessageHandler(handler); |
| 230 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); | 184 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); |
| 231 | 185 |
| 232 // Set up the chrome://system/ source. | 186 // Set up the chrome://system/ source. |
| 233 Profile* profile = Profile::FromWebUI(web_ui); | 187 Profile* profile = Profile::FromWebUI(web_ui); |
| 234 ChromeURLDataManager::AddDataSource(profile, html_source); | 188 ChromeURLDataManager::AddDataSource(profile, html_source); |
| 235 } | 189 } |
| OLD | NEW |