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

Unified Diff: chrome/browser/ui/webui/chromeos/system_info_ui.cc

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/system_info_ui.cc
diff --git a/chrome/browser/ui/webui/chromeos/system_info_ui.cc b/chrome/browser/ui/webui/chromeos/system_info_ui.cc
index 2c0d944bd74be319f76e0e18b9ae563b5fff7991..6791b95f1c9d7c0d01a7d39dfcbd1190c2fb1a2b 100644
--- a/chrome/browser/ui/webui/chromeos/system_info_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/system_info_ui.cc
@@ -18,8 +18,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/system/sysinfo_provider.h"
-#include "chrome/browser/chromeos/system/syslogs_provider.h"
+#include "chrome/browser/chromeos/system/syslogs_fetcher_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/common/chrome_paths.h"
@@ -58,24 +57,16 @@ class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource {
private:
~SystemInfoUIHTMLSource() {}
- void SyslogsComplete(chromeos::system::LogDictionaryType* sys_info,
- std::string* ignored_content);
void SysInfoComplete(chromeos::system::SysInfoResponse* response);
void RequestComplete();
void WaitForData();
- CancelableRequestConsumer logs_consumer_;
- CancelableRequestConsumer sys_info_consumer_;
-
// Stored data from StartDataRequest()
std::string path_;
int request_id_;
- int pending_requests_;
- chromeos::system::LogDictionaryType* logs_;
chromeos::system::SysInfoResponse* sys_info_;
- scoped_ptr<chromeos::system::SysInfoProvider> sys_info_provider_;
-
+ base::WeakPtrFactory<SystemInfoUIHTMLSource> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource);
};
@@ -101,8 +92,8 @@ class SystemInfoHandler : public WebUIMessageHandler,
SystemInfoUIHTMLSource::SystemInfoUIHTMLSource()
: DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()),
- request_id_(0), logs_(NULL), sys_info_(NULL),
- sys_info_provider_(chromeos::system::SysInfoProvider::Create()) {
+ request_id_(0), sys_info_(NULL),
+ weak_ptr_factory_(this) {
rkc1 2012/08/04 01:15:05 use ALLOW_THIS_IN_INITIALIZER_LIST everywhere you
tudalex(Chromium) 2012/08/05 01:15:12 Done.
}
void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path,
@@ -110,34 +101,16 @@ void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path,
int request_id) {
path_ = path;
request_id_ = request_id;
- pending_requests_ = 0;
-
- chromeos::system::SyslogsProvider* provider =
- chromeos::system::SyslogsProvider::GetInstance();
- if (provider) {
- provider->RequestSyslogs(
- false, // don't compress.
- chromeos::system::SyslogsProvider::SYSLOGS_SYSINFO,
- &logs_consumer_,
- base::Bind(&SystemInfoUIHTMLSource::SyslogsComplete,
- base::Unretained(this)));
- pending_requests_++;
- }
- sys_info_provider_->Fetch(&sys_info_consumer_,
- base::Bind(
- &SystemInfoUIHTMLSource::SysInfoComplete,
- base::Unretained(this)));
- pending_requests_++;
-}
+ chromeos::system::SysLogsFetcher * fetcher =
+ chromeos::system::SysLogsFetcherFactory::GetInstance()->GetFetcher();
+ fetcher->Fetch(base::Bind(
+ &SystemInfoUIHTMLSource::SysInfoComplete,
+ weak_ptr_factory_.GetWeakPtr()));
-void SystemInfoUIHTMLSource::SyslogsComplete(
- chromeos::system::LogDictionaryType* sys_info,
- std::string* ignored_content) {
- logs_ = sys_info;
- RequestComplete();
}
+
void SystemInfoUIHTMLSource::SysInfoComplete(
chromeos::system::SysInfoResponse* sys_info) {
sys_info_ = sys_info;
@@ -145,8 +118,7 @@ void SystemInfoUIHTMLSource::SysInfoComplete(
}
void SystemInfoUIHTMLSource::RequestComplete() {
- if (--pending_requests_)
- return;
+
DictionaryValue strings;
strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE));
@@ -164,36 +136,20 @@ void SystemInfoUIHTMLSource::RequestComplete() {
l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE));
SetFontAndTextDirection(&strings);
- if (logs_ || sys_info_) {
- ListValue* details = new ListValue();
- strings.Set("details", details);
- if (logs_) {
- chromeos::system::LogDictionaryType::iterator it;
- for (it = logs_->begin(); it != logs_->end(); ++it) {
- DictionaryValue* val = new DictionaryValue;
- val->SetString("stat_name", it->first);
- val->SetString("stat_value", it->second);
- details->Append(val);
- }
- delete logs_;
- }
- if (sys_info_) {
- chromeos::system::SysInfoResponse::iterator it;
- for (it = sys_info_->begin(); it != sys_info_->end(); ++it) {
- DictionaryValue* val = new DictionaryValue;
- // Prefix stats coming from debugd with 'debugd-' for now. The code that
- // displays stats can only handle one stat with a given name, so this
- // prevents names from overlapping. Once the duplicates have been
- // removed from userfeedback's list by
- // <https://gerrit.chromium.org/gerrit/25106>, the prefix can go away.
- val->SetString("stat_name", "debugd-" + it->first);
- val->SetString("stat_value", it->second);
- details->Append(val);
- }
- delete sys_info_;
- }
- strings.SetString("anchor", path_);
+ ListValue* details = new ListValue();
+ strings.Set("details", details);
+
+ chromeos::system::SysInfoResponse::iterator it;
+ for (it = sys_info_->begin(); it != sys_info_->end(); ++it) {
rkc1 2012/08/04 01:15:05 Add a check for sys_info_ being NULL.
tudalex(Chromium) 2012/08/05 01:15:12 Done.
+ DictionaryValue* val = new DictionaryValue;
+ val->SetString("stat_name", it->first);
+ val->SetString("stat_value", it->second);
+ details->Append(val);
}
+ delete sys_info_;
+
+ strings.SetString("anchor", path_);
+
static const base::StringPiece systeminfo_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_ABOUT_SYS_HTML, ui::SCALE_FACTOR_NONE));

Powered by Google App Engine
This is Rietveld 408576698