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

Unified Diff: chrome/browser/chromeos/system_logs/system_logs_fetcher.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/chromeos/system_logs/system_logs_fetcher.cc
diff --git a/chrome/browser/chromeos/system_logs/system_logs_fetcher.cc b/chrome/browser/chromeos/system_logs/system_logs_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c524303ab359981bd654c389322ae0002cf0146f
--- /dev/null
+++ b/chrome/browser/chromeos/system_logs/system_logs_fetcher.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "chrome/browser/chromeos/system_logs/commandline_log_source.h"
+#include "chrome/browser/chromeos/system_logs/debugd_log_source.h"
+#include "chrome/browser/chromeos/system_logs/memorydetails_log_source.h"
+#include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+SystemLogsFetcher::SystemLogsFetcher()
+ : response_(new SystemLogsResponse),
+ num_pending_requests_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+
+ // Debug Daemon data source.
+ data_sources_.push_back(new DebugDaemonLogSource());
+
+ // Chrome data sources.
+ data_sources_.push_back(new CommandLineLogSource());
+ data_sources_.push_back(new LsbReleaseLogSource());
+ data_sources_.push_back(new MemoryDetailsLogSource());
+ num_pending_requests_ = data_sources_.size();
+}
+
+void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
satorux1 2012/08/17 17:46:29 like elsewhere, might want to add DCHECK(callback
tudalex(Chromium) 2012/08/17 19:43:22 Done.
+
+ callback_ = callback;
+ for (size_t i = 0; i < data_sources_.size(); ++i) {
+ data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+}
+
+void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ response_->insert(response->begin(), response->end());
satorux1 2012/08/17 17:46:29 I think this code assume that keys are unique. How
tudalex(Chromium) 2012/08/17 19:43:22 I documented in the SystemLogsFetcher class commen
satorux1 2012/08/17 19:47:17 "be careful" is not a good practice in software de
rkc 2012/08/17 19:48:27 If a key appears from another data source, we over
tudalex(Chromium) 2012/08/17 21:34:54 Done.
+
+ --num_pending_requests_;
+ if (num_pending_requests_ > 0)
+ return;
+
+ callback_.Run(response_.Pass());
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+}
+
+} // namespace chromeos
+

Powered by Google App Engine
This is Rietveld 408576698