Chromium Code Reviews| Index: chrome/browser/chromeos/system/syslogs_fetcher.cc |
| diff --git a/chrome/browser/chromeos/system/syslogs_fetcher.cc b/chrome/browser/chromeos/system/syslogs_fetcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e468f3dcfc85dae48a103f53965ec5e4d964f731 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/system/syslogs_fetcher.cc |
| @@ -0,0 +1,66 @@ |
| +// 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/syslogs_fetcher.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/logging.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/thread.h" |
| +#include "chrome/browser/chromeos/system/debugd_log_fetcher.h" |
| +#include "chrome/browser/chromeos/system/sysinfo_provider.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace chromeos { |
| +namespace system { |
| + |
| +SysLogsFetcherFactory * SysLogsFetcherFactory::GetInstance() { |
| + return Singleton<SysLogsFetcherFactory>::get(); |
| +} |
| + |
| +SysLogsFetcher::SysLogsFetcher(BackendCollection backends) |
| + : backends_(backends), response_(new SysInfoResponse), |
| + weak_ptr_factory_(this), responses_(backends.size()) { } |
| + |
| +void SysLogsFetcher::Fetch(Request request) { |
| + request_ = request; |
| + BackendCollection::iterator it; |
| + responses_ = backends_.size(); |
| + for (it = backends_.begin(); it != backends_.end(); ++it) { |
| + LOG(ERROR) <<"Trying to use a backend."; |
| + (*it)->Fetch(base::Bind(&SysLogsFetcher::AddData, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +void SysLogsFetcher::AddData(SysInfoResponse *data) { |
| + base::AutoLock lock(response_lock_); |
| + LOG(ERROR) <<"Callback has been called."; |
| + SysInfoResponse::iterator it; |
| + for (it = data->begin(); it != data->end(); ++it) |
| + (*response_)[it->first] = it->second; |
| + if (--responses_) |
| + return; |
| + request_->ForwardResult(response_); |
|
rkc
2012/08/02 18:40:54
Do we really need to use CancelableRequest here?
I
|
| + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| +} |
| + |
| +SysLogsFetcher * SysLogsFetcherFactory::GetFetcher() { |
| + base::AutoLock lock(backends_lock_); |
| + BackendCollection t; |
|
rkc
2012/08/02 18:40:54
Rename the 't'
tudalex(Chromium)
2012/08/04 00:24:20
Done.
|
| + t.push_back(static_cast <SysLogsInterface*>(new DebugDaemonLogFetcher())); |
| + return new SysLogsFetcher(t); |
| +} |
| +void SysLogsFetcherFactory::RegisterHandler(SysLogsInterface * backend) { |
| + base::AutoLock lock(backends_lock_); |
| + backends_.push_back(backend); |
| +} |
| + |
| +} // namespace system |
| +} // namespace chromeos |