Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / feedback / system_logs / system_logs_fetcher_base.cc
blob7a0b938005f75e5395aebde539ba34f42360c312
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
3 // found in the LICENSE file.
5 #include "chrome/browser/feedback/system_logs/system_logs_fetcher_base.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "content/public/browser/browser_thread.h"
11 using content::BrowserThread;
13 namespace system_logs {
15 SystemLogsSource::SystemLogsSource(const std::string& source_name)
16 : source_name_(source_name) {
19 SystemLogsSource::~SystemLogsSource() {
22 SystemLogsFetcherBase::SystemLogsFetcherBase()
23 : response_(new SystemLogsResponse),
24 num_pending_requests_(0) {
27 SystemLogsFetcherBase::~SystemLogsFetcherBase() {}
29 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) {
30 DCHECK_CURRENTLY_ON(BrowserThread::UI);
31 DCHECK(callback_.is_null());
32 DCHECK(!callback.is_null());
34 callback_ = callback;
35 for (size_t i = 0; i < data_sources_.size(); ++i) {
36 VLOG(1) << "Fetching SystemLogSource: " << data_sources_[i]->source_name();
37 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse,
38 AsWeakPtr(),
39 data_sources_[i]->source_name()));
43 void SystemLogsFetcherBase::AddResponse(const std::string& source_name,
44 SystemLogsResponse* response) {
45 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 VLOG(1) << "Received SystemLogSource: " << source_name;
49 for (SystemLogsResponse::const_iterator it = response->begin();
50 it != response->end();
51 ++it) {
52 // It is an error to insert an element with a pre-existing key.
53 bool ok = response_->insert(*it).second;
54 DCHECK(ok) << "Duplicate key found: " << it->first;
57 --num_pending_requests_;
58 if (num_pending_requests_ > 0)
59 return;
61 callback_.Run(response_.Pass());
62 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
65 } // namespace system_logs