blob: e3b2add8920c77dd6f2e7c40238c97befb1e2325 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// 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/command_line_log_source.h"
#include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h"
#include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h"
#include "chrome/browser/chromeos/system_logs/memory_details_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();
}
SystemLogsFetcher::~SystemLogsFetcher() {}
void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(callback_.is_null());
DCHECK(!callback.is_null());
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));
for (SystemLogsResponse::const_iterator it = response->begin();
it != response->end();
++it) {
// It is false if the insert if there is already an element with the same
// key.
bool ok = response_->insert(*it).second;
DCHECK(ok) << "Duplicate key found: " << it->first;
}
--num_pending_requests_;
if (num_pending_requests_ > 0)
return;
callback_.Run(response_.Pass());
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
}
} // namespace chromeos
|