| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/feedback/system_logs/system_logs_fetcher_base.h" | 5 #include "chrome/browser/feedback/system_logs/system_logs_fetcher_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 | 10 |
| 11 using content::BrowserThread; | 11 using content::BrowserThread; |
| 12 | 12 |
| 13 namespace system_logs { | 13 namespace system_logs { |
| 14 | 14 |
| 15 SystemLogsSource::SystemLogsSource(const std::string& source_name) | 15 SystemLogsSource::SystemLogsSource(const std::string& source_name) |
| 16 : source_name_(source_name) { | 16 : source_name_(source_name) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 SystemLogsSource::~SystemLogsSource() { | 19 SystemLogsSource::~SystemLogsSource() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 SystemLogsFetcherBase::SystemLogsFetcherBase() | 22 SystemLogsFetcherBase::SystemLogsFetcherBase() |
| 23 : response_(new SystemLogsResponse), | 23 : response_(new SystemLogsResponse), |
| 24 num_pending_requests_(0) { | 24 num_pending_requests_(0) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 SystemLogsFetcherBase::~SystemLogsFetcherBase() {} | 27 SystemLogsFetcherBase::~SystemLogsFetcherBase() {} |
| 28 | 28 |
| 29 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) { | 29 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 DCHECK(callback_.is_null()); | 31 DCHECK(callback_.is_null()); |
| 32 DCHECK(!callback.is_null()); | 32 DCHECK(!callback.is_null()); |
| 33 | 33 |
| 34 callback_ = callback; | 34 callback_ = callback; |
| 35 for (size_t i = 0; i < data_sources_.size(); ++i) { | 35 for (size_t i = 0; i < data_sources_.size(); ++i) { |
| 36 VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name(); | 36 VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name(); |
| 37 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse, | 37 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse, |
| 38 AsWeakPtr(), | 38 AsWeakPtr(), |
| 39 data_sources_[i]->source_name())); | 39 data_sources_[i]->source_name())); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SystemLogsFetcherBase::AddResponse(const std::string& source_name, | 43 void SystemLogsFetcherBase::AddResponse(const std::string& source_name, |
| 44 SystemLogsResponse* response) { | 44 SystemLogsResponse* response) { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 46 | 46 |
| 47 VLOG(1) << "Received SystemLogSource: " << source_name; | 47 VLOG(1) << "Received SystemLogSource: " << source_name; |
| 48 | 48 |
| 49 for (SystemLogsResponse::const_iterator it = response->begin(); | 49 for (SystemLogsResponse::const_iterator it = response->begin(); |
| 50 it != response->end(); | 50 it != response->end(); |
| 51 ++it) { | 51 ++it) { |
| 52 // It is an error to insert an element with a pre-existing key. | 52 // It is an error to insert an element with a pre-existing key. |
| 53 bool ok = response_->insert(*it).second; | 53 bool ok = response_->insert(*it).second; |
| 54 DCHECK(ok) << "Duplicate key found: " << it->first; | 54 DCHECK(ok) << "Duplicate key found: " << it->first; |
| 55 } | 55 } |
| 56 | 56 |
| 57 --num_pending_requests_; | 57 --num_pending_requests_; |
| 58 if (num_pending_requests_ > 0) | 58 if (num_pending_requests_ > 0) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 callback_.Run(response_.Pass()); | 61 callback_.Run(response_.Pass()); |
| 62 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 62 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace system_logs | 65 } // namespace system_logs |
| OLD | NEW |