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

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/command_line_log_source.h"
10 #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h"
11 #include "chrome/browser/chromeos/system_logs/memory_details_log_source.h"
Lei Zhang 2012/08/21 19:56:55 nit: alphabetical ordering
tudalex(Chromium) 2012/08/21 21:21:12 Done.
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
Lei Zhang 2012/08/21 19:56:55 nit: no blank lines at the top of functions.
tudalex(Chromium) 2012/08/21 21:21:12 Done.
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 SystemLogsFetcher::~SystemLogsFetcher() {}
35
36 void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 DCHECK(callback_.is_null());
39 DCHECK(!callback.is_null());
40
41 callback_ = callback;
42 for (size_t i = 0; i < data_sources_.size(); ++i) {
43 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse,
44 weak_ptr_factory_.GetWeakPtr()));
45 }
46 }
47
48 void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50
51 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.
52 it != response->end();
53 ++it) {
54 // It is false if the insert if there is already an element with the same
55 // key.
56 DCHECK(response_->insert(*it).second);
Lei Zhang 2012/08/21 19:56:55 If you do this inside a DCHECK(), it won't actuall
rkc1 2012/08/21 20:02:33 That's intended, we don't want to crash in product
Lei Zhang 2012/08/21 20:08:15 In that case, put the entire loop inside a #if !de
satorux1 2012/08/21 20:48:31 I think Lei was right, and it was a great catch. W
rkc1 2012/08/21 20:50:01 Yeah, I realized that. tudalex@ is correcting it.
tudalex(Chromium) 2012/08/21 21:21:12 Lei was right in the first place. Moved it outside
57 }
58
59
60 --num_pending_requests_;
61 if (num_pending_requests_ > 0)
62 return;
63
64 callback_.Run(response_.Pass());
65 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
66 }
67
68 } // namespace chromeos
69
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698