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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "chrome/browser/chromeos/system_logs/commandline_log_source.h"
10 #include "chrome/browser/chromeos/system_logs/debugd_log_source.h"
11 #include "chrome/browser/chromeos/system_logs/memorydetails_log_source.h"
12 #include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h"
13 #include "content/public/browser/browser_thread.h"
14
15 using content::BrowserThread;
16
17 namespace chromeos {
18
19 SystemLogsFetcher::SystemLogsFetcher()
20 : response_(new SystemLogsResponse),
21 num_pending_requests_(0),
22 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
23
24 // Debug Daemon data source.
25 data_sources_.push_back(new DebugDaemonLogSource());
26
27 // Chrome data sources.
28 data_sources_.push_back(new CommandLineLogSource());
29 data_sources_.push_back(new LsbReleaseLogSource());
30 data_sources_.push_back(new MemoryDetailsLogSource());
31 num_pending_requests_ = data_sources_.size();
32 }
33
34 void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) {
35 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.
36
37 callback_ = callback;
38 for (size_t i = 0; i < data_sources_.size(); ++i) {
39 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse,
40 weak_ptr_factory_.GetWeakPtr()));
41 }
42 }
43
44 void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46
47 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.
48
49 --num_pending_requests_;
50 if (num_pending_requests_ > 0)
51 return;
52
53 callback_.Run(response_.Pass());
54 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
55 }
56
57 } // namespace chromeos
58
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698