Chromium Code Reviews| 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..81aa8e090f1da56ba76e3358c3d8bca89742da1d |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/system_logs/system_logs_fetcher.cc |
| @@ -0,0 +1,68 @@ |
| +// 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/lsbrelease_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& request) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + request_ = request; |
| + SysLogsDataSources::iterator it; |
| + for (it = data_sources_.begin(); it != data_sources_.end(); ++it) { |
| + (*it)->Fetch(base::Bind(&SystemLogsFetcher::AddData, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +void SystemLogsFetcher::AddData(SystemLogsResponse* response) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + for (SystemLogsResponse::iterator it = response->begin(); |
| + it != response->end(); |
| + ++it) { |
| + (*response_)[it->first] = it->second; |
| + } |
| + delete response; |
|
satorux1
2012/08/13 19:33:36
oh i see. so the response is deleted here. as ment
tudalex(Chromium)
2012/08/14 03:24:00
Done.
|
| + |
| + if (--num_pending_requests_) |
|
satorux1
2012/08/13 19:33:36
this is hard to read. please do
--num_pending_req
tudalex(Chromium)
2012/08/14 03:24:00
Done.
|
| + return; |
| + |
| + |
| + for (SysLogsDataSources::iterator it = data_sources_.begin(); |
|
satorux1
2012/08/13 19:33:36
Please use ScopedVector for data_sources_ instead
tudalex(Chromium)
2012/08/14 03:24:00
Done.
|
| + it != data_sources_.end(); |
| + ++it) { |
| + delete *it; |
| + } |
| + request_.Run(response_); |
| + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| +} |
| + |
| +} // namespace chromeos |
| + |