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"
8 #include "base/bind_helpers.h"
9 #include "content/public/browser/browser_thread.h"
11 using content::BrowserThread
;
13 namespace system_logs
{
15 SystemLogsFetcherBase::SystemLogsFetcherBase()
16 : response_(new SystemLogsResponse
),
17 num_pending_requests_(0) {
20 SystemLogsFetcherBase::~SystemLogsFetcherBase() {}
22 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback
& callback
) {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
24 DCHECK(callback_
.is_null());
25 DCHECK(!callback
.is_null());
28 for (size_t i
= 0; i
< data_sources_
.size(); ++i
) {
29 data_sources_
[i
]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse
,
34 void SystemLogsFetcherBase::AddResponse(SystemLogsResponse
* response
) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
37 for (SystemLogsResponse::const_iterator it
= response
->begin();
38 it
!= response
->end();
40 // It is an error to insert an element with a pre-existing key.
41 bool ok
= response_
->insert(*it
).second
;
42 DCHECK(ok
) << "Duplicate key found: " << it
->first
;
45 --num_pending_requests_
;
46 if (num_pending_requests_
> 0)
49 callback_
.Run(response_
.Pass());
50 BrowserThread::DeleteSoon(BrowserThread::UI
, FROM_HERE
, this);
53 } // namespace system_logs