| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 SystemLogsFetcherBase::~SystemLogsFetcherBase() {} | 29 SystemLogsFetcherBase::~SystemLogsFetcherBase() {} |
| 30 | 30 |
| 31 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) { | 31 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 DCHECK(callback_.is_null()); | 33 DCHECK(callback_.is_null()); |
| 34 DCHECK(!callback.is_null()); | 34 DCHECK(!callback.is_null()); |
| 35 | 35 |
| 36 callback_ = callback; | 36 callback_ = callback; |
| 37 for (size_t i = 0; i < data_sources_.size(); ++i) { | 37 for (size_t i = 0; i < data_sources_.size(); ++i) { |
| 38 VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name(); | 38 VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name(); |
| 39 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse, | 39 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::OnFetched, |
| 40 AsWeakPtr(), | 40 AsWeakPtr(), |
| 41 data_sources_[i]->source_name())); | 41 data_sources_[i]->source_name())); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SystemLogsFetcherBase::AddResponse(const std::string& source_name, | 45 void SystemLogsFetcherBase::OnFetched(const std::string& source_name, |
| 46 SystemLogsResponse* response) { | 46 SystemLogsResponse* response) { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 | 48 |
| 49 VLOG(1) << "Received SystemLogSource: " << source_name; | 49 VLOG(1) << "Received SystemLogSource: " << source_name; |
| 50 | 50 |
| 51 Rewrite(source_name, response); |
| 52 AddResponse(source_name, response); |
| 53 } |
| 54 |
| 55 void SystemLogsFetcherBase::Rewrite(const std::string& /* source_name */, |
| 56 SystemLogsResponse* /* response */) { |
| 57 // This implementation in the base class is intentionally empty. |
| 58 } |
| 59 |
| 60 void SystemLogsFetcherBase::AddResponse(const std::string& source_name, |
| 61 SystemLogsResponse* response) { |
| 51 for (SystemLogsResponse::const_iterator it = response->begin(); | 62 for (SystemLogsResponse::const_iterator it = response->begin(); |
| 52 it != response->end(); | 63 it != response->end(); |
| 53 ++it) { | 64 ++it) { |
| 54 // It is an error to insert an element with a pre-existing key. | 65 // It is an error to insert an element with a pre-existing key. |
| 55 bool ok = response_->insert(*it).second; | 66 bool ok = response_->insert(*it).second; |
| 56 DCHECK(ok) << "Duplicate key found: " << it->first; | 67 DCHECK(ok) << "Duplicate key found: " << it->first; |
| 57 } | 68 } |
| 58 | 69 |
| 59 --num_pending_requests_; | 70 --num_pending_requests_; |
| 60 if (num_pending_requests_ > 0) | 71 if (num_pending_requests_ > 0) |
| 61 return; | 72 return; |
| 62 | 73 |
| 63 callback_.Run(std::move(response_)); | 74 callback_.Run(std::move(response_)); |
| 64 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 75 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 65 } | 76 } |
| 66 | 77 |
| 67 } // namespace system_logs | 78 } // namespace system_logs |
| OLD | NEW |