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/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/cros/cros_library.h" | 21 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 21 #include "chrome/browser/chromeos/system/sysinfo_provider.h" | 22 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" |
| 22 #include "chrome/browser/chromeos/system/syslogs_provider.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) OVERRIDE; | 53 int request_id) OVERRIDE; |
| 54 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 54 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
| 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::SystemLogsResponse* response); |
|
satorux1
2012/08/14 05:53:21
I think you can put the code in the file in 'chrom
tudalex(Chromium)
2012/08/15 01:54:33
Done.
| |
| 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 scoped_ptr<chromeos::SystemLogsResponse> response_; |
| 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), response_(NULL), |
|
satorux1
2012/08/14 05:51:52
move response_(NULL) to the next line.
tudalex(Chromium)
2012/08/15 01:54:33
Done.
| |
| 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::SystemLogsFetcher * fetcher = new chromeos::SystemLogsFetcher(); |
| 116 chromeos::system::SyslogsProvider::GetInstance(); | 107 fetcher->Fetch(base::Bind( |
| 117 if (provider) { | 108 &SystemInfoUIHTMLSource::SysInfoComplete, |
| 118 provider->RequestSyslogs( | 109 weak_ptr_factory_.GetWeakPtr())); |
| 119 false, // don't compress. | |
| 120 chromeos::system::SyslogsProvider::SYSLOGS_SYSINFO, | |
| 121 &logs_consumer_, | |
| 122 base::Bind(&SystemInfoUIHTMLSource::SyslogsComplete, | |
| 123 base::Unretained(this))); | |
| 124 pending_requests_++; | |
| 125 } | |
| 126 | |
| 127 sys_info_provider_->Fetch(&sys_info_consumer_, | |
| 128 base::Bind( | |
| 129 &SystemInfoUIHTMLSource::SysInfoComplete, | |
| 130 base::Unretained(this))); | |
| 131 pending_requests_++; | |
| 132 } | 110 } |
| 133 | 111 |
| 134 void SystemInfoUIHTMLSource::SyslogsComplete( | |
| 135 chromeos::system::LogDictionaryType* sys_info, | |
| 136 std::string* ignored_content) { | |
| 137 logs_ = sys_info; | |
| 138 RequestComplete(); | |
| 139 } | |
| 140 | 112 |
| 141 void SystemInfoUIHTMLSource::SysInfoComplete( | 113 void SystemInfoUIHTMLSource::SysInfoComplete( |
| 142 chromeos::system::SysInfoResponse* sys_info) { | 114 chromeos::SystemLogsResponse* sys_info) { |
| 143 sys_info_ = sys_info; | 115 response_.reset(sys_info); |
| 144 RequestComplete(); | 116 RequestComplete(); |
| 145 } | 117 } |
| 146 | 118 |
| 147 void SystemInfoUIHTMLSource::RequestComplete() { | 119 void SystemInfoUIHTMLSource::RequestComplete() { |
| 148 if (--pending_requests_) | |
| 149 return; | |
| 150 | |
| 151 DictionaryValue strings; | 120 DictionaryValue strings; |
| 152 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); | 121 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); |
| 153 strings.SetString("description", | 122 strings.SetString("description", |
| 154 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); | 123 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); |
| 155 strings.SetString("table_title", | 124 strings.SetString("table_title", |
| 156 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); | 125 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); |
| 157 strings.SetString("expand_all_btn", | 126 strings.SetString("expand_all_btn", |
| 158 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); | 127 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); |
| 159 strings.SetString("collapse_all_btn", | 128 strings.SetString("collapse_all_btn", |
| 160 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); | 129 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); |
| 161 strings.SetString("expand_btn", | 130 strings.SetString("expand_btn", |
| 162 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); | 131 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); |
| 163 strings.SetString("collapse_btn", | 132 strings.SetString("collapse_btn", |
| 164 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); | 133 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); |
| 165 SetFontAndTextDirection(&strings); | 134 SetFontAndTextDirection(&strings); |
| 166 | 135 if (response_ != NULL) { |
|
satorux1
2012/08/14 05:51:52
It's ok to say if (response_) {
tudalex(Chromium)
2012/08/15 01:54:33
I can't say it. It gives me an error that it can't
satorux1
2012/08/15 02:12:36
Then do this if (response_.get())
tudalex(Chromium)
2012/08/15 17:20:21
Done.
| |
| 167 if (logs_ || sys_info_) { | |
| 168 ListValue* details = new ListValue(); | 136 ListValue* details = new ListValue(); |
| 169 strings.Set("details", details); | 137 strings.Set("details", details); |
| 170 if (logs_) { | 138 chromeos::SystemLogsResponse::iterator it; |
|
satorux1
2012/08/14 05:51:52
this is not fixed. please move this inside of for
tudalex(Chromium)
2012/08/15 01:54:33
Sorry. I forgot to save the file in eclipse with t
| |
| 171 chromeos::system::LogDictionaryType::iterator it; | 139 for (it = response_->begin(); it != response_->end(); ++it) { |
| 172 for (it = logs_->begin(); it != logs_->end(); ++it) { | 140 DictionaryValue* val = new DictionaryValue; |
| 173 DictionaryValue* val = new DictionaryValue; | 141 val->SetString("stat_name", it->first); |
| 174 // Skip the 'debugd' key; this is a duplicate of all the logs that | 142 val->SetString("stat_value", it->second); |
| 175 // we're already getting from the debugd daemon. This will be fixed | 143 details->Append(val); |
| 176 // with http://code.google.com/p/chromium/issues/detail?id=138582 | |
| 177 // which incidentally will also remove this code. | |
| 178 if (it->first == "debugd") | |
| 179 continue; | |
| 180 | 144 |
|
satorux1
2012/08/14 05:51:52
no blank line here.
tudalex(Chromium)
2012/08/15 01:54:33
Done.
| |
| 181 val->SetString("stat_name", it->first); | |
| 182 val->SetString("stat_value", it->second); | |
| 183 details->Append(val); | |
| 184 } | |
| 185 delete logs_; | |
| 186 } | |
| 187 if (sys_info_) { | |
| 188 chromeos::system::SysInfoResponse::iterator it; | |
| 189 for (it = sys_info_->begin(); it != sys_info_->end(); ++it) { | |
| 190 DictionaryValue* val = new DictionaryValue; | |
| 191 val->SetString("stat_name", it->first); | |
| 192 val->SetString("stat_value", it->second); | |
| 193 details->Append(val); | |
| 194 } | |
| 195 delete sys_info_; | |
| 196 } | 145 } |
| 197 strings.SetString("anchor", path_); | 146 strings.SetString("anchor", path_); |
| 198 } | 147 } |
| 199 static const base::StringPiece systeminfo_html( | 148 static const base::StringPiece systeminfo_html( |
| 200 ResourceBundle::GetSharedInstance().GetRawDataResource( | 149 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 201 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); | 150 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); |
| 202 std::string full_html = jstemplate_builder::GetTemplatesHtml( | 151 std::string full_html = jstemplate_builder::GetTemplatesHtml( |
| 203 systeminfo_html, &strings, "t" /* template root node id */); | 152 systeminfo_html, &strings, "t" /* template root node id */); |
| 204 | |
| 205 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); | 153 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); |
| 206 } | 154 } |
| 207 | 155 |
| 208 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
| 209 // | 157 // |
| 210 // SystemInfoHandler | 158 // SystemInfoHandler |
| 211 // | 159 // |
| 212 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 213 SystemInfoHandler::SystemInfoHandler() { | 161 SystemInfoHandler::SystemInfoHandler() { |
| 214 } | 162 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 228 | 176 |
| 229 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 177 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 230 SystemInfoHandler* handler = new SystemInfoHandler(); | 178 SystemInfoHandler* handler = new SystemInfoHandler(); |
| 231 web_ui->AddMessageHandler(handler); | 179 web_ui->AddMessageHandler(handler); |
| 232 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); | 180 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); |
| 233 | 181 |
| 234 // Set up the chrome://system/ source. | 182 // Set up the chrome://system/ source. |
| 235 Profile* profile = Profile::FromWebUI(web_ui); | 183 Profile* profile = Profile::FromWebUI(web_ui); |
| 236 ChromeURLDataManager::AddDataSource(profile, html_source); | 184 ChromeURLDataManager::AddDataSource(profile, html_source); |
| 237 } | 185 } |
| OLD | NEW |