Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/syslogs_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/singleton.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "base/threading/thread.h" | |
| 14 #include "chrome/browser/chromeos/system/debugd_log_fetcher.h" | |
| 15 #include "chrome/browser/chromeos/system/sysinfo_provider.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 | |
| 18 using content::BrowserThread; | |
| 19 | |
| 20 namespace chromeos { | |
| 21 namespace system { | |
| 22 | |
| 23 SysLogsFetcherFactory * SysLogsFetcherFactory::GetInstance() { | |
| 24 return Singleton<SysLogsFetcherFactory>::get(); | |
| 25 } | |
| 26 | |
| 27 SysLogsFetcher::SysLogsFetcher(BackendCollection backends) | |
| 28 : backends_(backends), response_(new SysInfoResponse), | |
| 29 weak_ptr_factory_(this), responses_(backends.size()) { } | |
| 30 | |
| 31 void SysLogsFetcher::Fetch(Request request) { | |
| 32 request_ = request; | |
| 33 BackendCollection::iterator it; | |
| 34 responses_ = backends_.size(); | |
| 35 for (it = backends_.begin(); it != backends_.end(); ++it) { | |
| 36 LOG(ERROR) <<"Trying to use a backend."; | |
| 37 (*it)->Fetch(base::Bind(&SysLogsFetcher::AddData, | |
| 38 weak_ptr_factory_.GetWeakPtr())); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 void SysLogsFetcher::AddData(SysInfoResponse *data) { | |
| 43 base::AutoLock lock(response_lock_); | |
| 44 LOG(ERROR) <<"Callback has been called."; | |
| 45 SysInfoResponse::iterator it; | |
| 46 for (it = data->begin(); it != data->end(); ++it) | |
| 47 (*response_)[it->first] = it->second; | |
| 48 if (--responses_) | |
| 49 return; | |
| 50 request_->ForwardResult(response_); | |
|
rkc
2012/08/02 18:40:54
Do we really need to use CancelableRequest here?
I
| |
| 51 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | |
| 52 } | |
| 53 | |
| 54 SysLogsFetcher * SysLogsFetcherFactory::GetFetcher() { | |
| 55 base::AutoLock lock(backends_lock_); | |
| 56 BackendCollection t; | |
|
rkc
2012/08/02 18:40:54
Rename the 't'
tudalex(Chromium)
2012/08/04 00:24:20
Done.
| |
| 57 t.push_back(static_cast <SysLogsInterface*>(new DebugDaemonLogFetcher())); | |
| 58 return new SysLogsFetcher(t); | |
| 59 } | |
| 60 void SysLogsFetcherFactory::RegisterHandler(SysLogsInterface * backend) { | |
| 61 base::AutoLock lock(backends_lock_); | |
| 62 backends_.push_back(backend); | |
| 63 } | |
| 64 | |
| 65 } // namespace system | |
| 66 } // namespace chromeos | |
| OLD | NEW |