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" |
| 33 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 35 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
| 36 #include "net/base/directory_lister.h" | 36 #include "net/base/directory_lister.h" |
| 37 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/layout.h" | 39 #include "ui/base/layout.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 | 41 |
| 42 using content::WebContents; | 42 using content::WebContents; |
| 43 using content::WebUIMessageHandler; | 43 using content::WebUIMessageHandler; |
| 44 | 44 |
| 45 namespace chromeos { | |
| 46 | |
| 45 class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource { | 47 class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 46 public: | 48 public: |
| 47 SystemInfoUIHTMLSource(); | 49 SystemInfoUIHTMLSource(); |
| 48 | 50 |
| 49 // Called when the network layer has requested a resource underneath | 51 // Called when the network layer has requested a resource underneath |
| 50 // the path we registered. | 52 // the path we registered. |
| 51 virtual void StartDataRequest(const std::string& path, | 53 virtual void StartDataRequest(const std::string& path, |
| 52 bool is_incognito, | 54 bool is_incognito, |
| 53 int request_id) OVERRIDE; | 55 int request_id) OVERRIDE; |
| 54 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 56 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
| 55 return "text/html"; | 57 return "text/html"; |
| 56 } | 58 } |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 ~SystemInfoUIHTMLSource() {} | 61 ~SystemInfoUIHTMLSource() {} |
| 60 | 62 |
| 61 void SyslogsComplete(chromeos::system::LogDictionaryType* sys_info, | 63 void SysInfoComplete(scoped_ptr<SystemLogsResponse> response); |
| 62 std::string* ignored_content); | |
| 63 void SysInfoComplete(chromeos::system::SysInfoResponse* response); | |
| 64 void RequestComplete(); | 64 void RequestComplete(); |
| 65 void WaitForData(); | 65 void WaitForData(); |
| 66 | 66 |
| 67 CancelableRequestConsumer logs_consumer_; | |
| 68 CancelableRequestConsumer sys_info_consumer_; | |
| 69 | |
| 70 // Stored data from StartDataRequest() | 67 // Stored data from StartDataRequest() |
| 71 std::string path_; | 68 std::string path_; |
| 72 int request_id_; | 69 int request_id_; |
| 73 | 70 |
| 74 int pending_requests_; | 71 scoped_ptr<SystemLogsResponse> response_; |
| 75 chromeos::system::LogDictionaryType* logs_; | 72 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); | 73 DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource); |
| 80 }; | 74 }; |
| 81 | 75 |
| 82 // The handler for Javascript messages related to the "system" view. | 76 // The handler for Javascript messages related to the "system" view. |
| 83 class SystemInfoHandler : public WebUIMessageHandler, | 77 class SystemInfoHandler : public WebUIMessageHandler, |
| 84 public base::SupportsWeakPtr<SystemInfoHandler> { | 78 public base::SupportsWeakPtr<SystemInfoHandler> { |
| 85 public: | 79 public: |
| 86 SystemInfoHandler(); | 80 SystemInfoHandler(); |
| 87 virtual ~SystemInfoHandler(); | 81 virtual ~SystemInfoHandler(); |
| 88 | 82 |
| 89 // WebUIMessageHandler implementation. | 83 // WebUIMessageHandler implementation. |
| 90 virtual void RegisterMessages() OVERRIDE; | 84 virtual void RegisterMessages() OVERRIDE; |
| 91 | 85 |
| 92 private: | 86 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); | 87 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); |
| 94 }; | 88 }; |
| 95 | 89 |
| 96 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 97 // | 91 // |
| 98 // SystemInfoUIHTMLSource | 92 // SystemInfoUIHTMLSource |
| 99 // | 93 // |
| 100 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 101 | 95 |
| 102 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() | 96 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() |
| 103 : DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()), | 97 : DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()), |
| 104 request_id_(0), logs_(NULL), sys_info_(NULL), | 98 request_id_(0), |
| 105 sys_info_provider_(chromeos::system::SysInfoProvider::Create()) { | 99 response_(NULL), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | |
| 106 } | 101 } |
| 107 | 102 |
| 108 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, | 103 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, |
| 109 bool is_incognito, | 104 bool is_incognito, |
| 110 int request_id) { | 105 int request_id) { |
| 111 path_ = path; | 106 path_ = path; |
| 112 request_id_ = request_id; | 107 request_id_ = request_id; |
| 113 pending_requests_ = 0; | |
| 114 | 108 |
| 115 chromeos::system::SyslogsProvider* provider = | 109 SystemLogsFetcher* fetcher = new SystemLogsFetcher(); |
| 116 chromeos::system::SyslogsProvider::GetInstance(); | 110 fetcher->Fetch(base::Bind(&SystemInfoUIHTMLSource::SysInfoComplete, |
| 117 if (provider) { | 111 weak_ptr_factory_.GetWeakPtr())); |
| 118 provider->RequestSyslogs( | |
| 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 } | 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 scoped_ptr<SystemLogsResponse> sys_info) { |
| 143 sys_info_ = sys_info; | 117 response_ = sys_info.Pass(); |
| 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 (response_.get()) { |
| 167 if (logs_ || sys_info_) { | |
| 168 ListValue* details = new ListValue(); | 138 ListValue* details = new ListValue(); |
| 169 strings.Set("details", details); | 139 strings.Set("details", details); |
| 170 if (logs_) { | 140 for (SystemLogsResponse::iterator it = response_->begin(); |
|
Lei Zhang
2012/08/21 19:56:55
const_iterator
tudalex(Chromium)
2012/08/21 21:21:12
Done.
| |
| 171 chromeos::system::LogDictionaryType::iterator it; | 141 it != response_->end(); |
| 172 for (it = logs_->begin(); it != logs_->end(); ++it) { | 142 ++it) { |
| 173 DictionaryValue* val = new DictionaryValue; | 143 DictionaryValue* val = new DictionaryValue; |
| 174 // Skip the 'debugd' key; this is a duplicate of all the logs that | 144 val->SetString("stat_name", it->first); |
| 175 // we're already getting from the debugd daemon. This will be fixed | 145 val->SetString("stat_value", it->second); |
| 176 // with http://code.google.com/p/chromium/issues/detail?id=138582 | 146 details->Append(val); |
| 177 // which incidentally will also remove this code. | |
| 178 if (it->first == "debugd") | |
| 179 continue; | |
| 180 | |
| 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 } | 147 } |
| 197 strings.SetString("anchor", path_); | 148 strings.SetString("anchor", path_); |
| 198 } | 149 } |
| 199 static const base::StringPiece systeminfo_html( | 150 static const base::StringPiece systeminfo_html( |
| 200 ResourceBundle::GetSharedInstance().GetRawDataResource( | 151 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 201 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); | 152 IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE)); |
| 202 std::string full_html = jstemplate_builder::GetTemplatesHtml( | 153 std::string full_html = jstemplate_builder::GetTemplatesHtml( |
| 203 systeminfo_html, &strings, "t" /* template root node id */); | 154 systeminfo_html, &strings, "t" /* template root node id */); |
| 204 | |
| 205 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); | 155 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); |
| 206 } | 156 } |
| 207 | 157 |
| 208 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
| 209 // | 159 // |
| 210 // SystemInfoHandler | 160 // SystemInfoHandler |
| 211 // | 161 // |
| 212 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
| 213 SystemInfoHandler::SystemInfoHandler() { | 163 SystemInfoHandler::SystemInfoHandler() { |
| 214 } | 164 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 228 | 178 |
| 229 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 179 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 230 SystemInfoHandler* handler = new SystemInfoHandler(); | 180 SystemInfoHandler* handler = new SystemInfoHandler(); |
| 231 web_ui->AddMessageHandler(handler); | 181 web_ui->AddMessageHandler(handler); |
| 232 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); | 182 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); |
| 233 | 183 |
| 234 // Set up the chrome://system/ source. | 184 // Set up the chrome://system/ source. |
| 235 Profile* profile = Profile::FromWebUI(web_ui); | 185 Profile* profile = Profile::FromWebUI(web_ui); |
| 236 ChromeURLDataManager::AddDataSource(profile, html_source); | 186 ChromeURLDataManager::AddDataSource(profile, html_source); |
| 237 } | 187 } |
| 188 | |
| 189 } // namespace chromeos | |
| OLD | NEW |