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_logs/system_logs_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "chrome/browser/chromeos/system_logs/commandline_log_source.h" | |
| 10 #include "chrome/browser/chromeos/system_logs/debugd_log_source.h" | |
| 11 #include "chrome/browser/chromeos/system_logs/memorydetails_log_source.h" | |
| 12 #include "chrome/browser/chromeos/system_logs/lsbrelease_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 : request_(SysLogsFetcherCallback()), | |
| 21 response_(new SystemLogsResponse), | |
|
satorux1
2012/08/16 10:50:57
when will it be deleted? make it a scoped_ptr? If
tudalex(Chromium)
2012/08/16 22:33:03
Done.
| |
| 22 num_pending_requests_(0), | |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | |
| 24 | |
| 25 // Debug Daemon data source. | |
| 26 data_sources_.push_back(new DebugDaemonLogSource()); | |
| 27 | |
| 28 // Chrome data sources. | |
| 29 data_sources_.push_back(new CommandLineLogSource()); | |
| 30 data_sources_.push_back(new LsbReleaseLogSource()); | |
| 31 data_sources_.push_back(new MemoryDetailsLogSource()); | |
| 32 num_pending_requests_ = data_sources_.size(); | |
| 33 } | |
| 34 | |
| 35 void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& request) { | |
|
satorux1
2012/08/16 10:50:57
request -> callback
tudalex(Chromium)
2012/08/16 22:33:03
Done.
| |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 37 | |
| 38 request_ = request; | |
| 39 for (size_t i = 0; i < data_sources_.size(); ++i) { | |
| 40 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse, | |
| 41 weak_ptr_factory_.GetWeakPtr())); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) { | |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 47 | |
| 48 for (SystemLogsResponse::iterator it = response->begin(); | |
| 49 it != response->end(); | |
| 50 ++it) { | |
|
satorux1
2012/08/16 10:50:57
you might want to use size_t i = 0 here and elsewh
tudalex(Chromium)
2012/08/16 22:33:03
response is a map and I don't know any ot her nice
satorux1
2012/08/17 17:46:29
sorry, i wasn't aware this was a map. insert() lgt
| |
| 51 (*response_)[it->first] = it->second; | |
| 52 } | |
| 53 | |
| 54 --num_pending_requests_; | |
| 55 if (num_pending_requests_ > 0) | |
| 56 return; | |
| 57 request_.Run(response_); | |
| 58 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | |
| 59 } | |
| 60 | |
| 61 } // namespace chromeos | |
| 62 | |
| OLD | NEW |