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

Unified Diff: chrome/browser/chromeos/syslogs/syslogs_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/syslogs/syslogs_fetcher.cc
diff --git a/chrome/browser/chromeos/syslogs/syslogs_fetcher.cc b/chrome/browser/chromeos/syslogs/syslogs_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0028c7e2ad5bc102ce3386d55d99e0344425e809
--- /dev/null
+++ b/chrome/browser/chromeos/syslogs/syslogs_fetcher.cc
@@ -0,0 +1,51 @@
+// 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/syslogs/syslogs_fetcher.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+
+SysLogsFetcher::SysLogsFetcher(SysLogsDataSources backends)
+ : data_sources_(backends), response_(new SysLogsResponse),
+ responses_(backends.size()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
+
+void SysLogsFetcher::Fetch(SysLogsFetcherCallback request) {
+ request_ = request;
+ SysLogsDataSources::iterator it;
+ responses_ = data_sources_.size();
+ for (it = data_sources_.begin(); it != data_sources_.end(); ++it) {
+ (*it)->Fetch(base::Bind(&SysLogsFetcher::AddData,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+}
+
+void SysLogsFetcher::AddData(SysLogsResponse *data) {
+ base::AutoLock lock(response_lock_);
+
+ SysLogsResponse::iterator it;
+ for (it = data->begin(); it != data->end(); ++it){
+ (*response_)[it->first] = it->second;
+ }
+ delete data;
+
+ if (--responses_)
+ return;
+
+ SysLogsDataSources::iterator ds_it;
+ for (ds_it = data_sources_.begin(); ds_it != data_sources_.end(); ++ds_it) {
+ delete *ds_it;
+ }
+ request_.Run(response_);
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698