| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/system_logs/system_logs_fetcher.h" | 5 #include "chrome/browser/chromeos/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 "chrome/browser/chromeos/system_logs/chrome_internal_log_source.h" | 9 #include "chrome/browser/chromeos/system_logs/chrome_internal_log_source.h" |
| 10 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h" | 10 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h" |
| 11 #include "chrome/browser/chromeos/system_logs/dbus_log_source.h" | 11 #include "chrome/browser/chromeos/system_logs/dbus_log_source.h" |
| 12 #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h" | 12 #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h" |
| 13 #include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h" | 13 #include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h" |
| 14 #include "chrome/browser/chromeos/system_logs/memory_details_log_source.h" | 14 #include "chrome/browser/chromeos/system_logs/memory_details_log_source.h" |
| 15 #include "chrome/browser/chromeos/system_logs/network_event_log_source.h" | 15 #include "chrome/browser/chromeos/system_logs/network_event_log_source.h" |
| 16 #include "chrome/browser/chromeos/system_logs/touch_log_source.h" | 16 #include "chrome/browser/chromeos/system_logs/touch_log_source.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace chromeos { | 21 namespace chromeos { |
| 22 | 22 |
| 23 SystemLogsFetcher::SystemLogsFetcher() | 23 SystemLogsFetcherBase::SystemLogsFetcherBase() |
| 24 : response_(new SystemLogsResponse), | 24 : response_(new SystemLogsResponse), |
| 25 num_pending_requests_(0), | 25 num_pending_requests_(0) { |
| 26 weak_ptr_factory_(this) { | |
| 27 // Debug Daemon data source. | |
| 28 data_sources_.push_back(new DebugDaemonLogSource()); | |
| 29 | |
| 30 // Chrome data sources. | |
| 31 data_sources_.push_back(new ChromeInternalLogSource()); | |
| 32 data_sources_.push_back(new CommandLineLogSource()); | |
| 33 data_sources_.push_back(new DBusLogSource()); | |
| 34 data_sources_.push_back(new LsbReleaseLogSource()); | |
| 35 data_sources_.push_back(new MemoryDetailsLogSource()); | |
| 36 data_sources_.push_back(new NetworkEventLogSource()); | |
| 37 data_sources_.push_back(new TouchLogSource()); | |
| 38 | |
| 39 num_pending_requests_ = data_sources_.size(); | |
| 40 } | 26 } |
| 41 | 27 |
| 42 SystemLogsFetcher::~SystemLogsFetcher() {} | 28 SystemLogsFetcherBase::~SystemLogsFetcherBase() {} |
| 43 | 29 |
| 44 void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) { | 30 void SystemLogsFetcherBase::Fetch(const SysLogsFetcherCallback& callback) { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 46 DCHECK(callback_.is_null()); | 32 DCHECK(callback_.is_null()); |
| 47 DCHECK(!callback.is_null()); | 33 DCHECK(!callback.is_null()); |
| 48 | 34 |
| 49 callback_ = callback; | 35 callback_ = callback; |
| 50 for (size_t i = 0; i < data_sources_.size(); ++i) { | 36 for (size_t i = 0; i < data_sources_.size(); ++i) { |
| 51 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse, | 37 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcherBase::AddResponse, |
| 52 weak_ptr_factory_.GetWeakPtr())); | 38 GetWeakPtr())); |
| 53 } | 39 } |
| 54 } | 40 } |
| 55 | 41 |
| 56 void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) { | 42 void SystemLogsFetcherBase::AddResponse(SystemLogsResponse* response) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 44 |
| 59 for (SystemLogsResponse::const_iterator it = response->begin(); | 45 for (SystemLogsResponse::const_iterator it = response->begin(); |
| 60 it != response->end(); | 46 it != response->end(); |
| 61 ++it) { | 47 ++it) { |
| 62 // It is an error to insert an element with a pre-existing key. | 48 // It is an error to insert an element with a pre-existing key. |
| 63 bool ok = response_->insert(*it).second; | 49 bool ok = response_->insert(*it).second; |
| 64 DCHECK(ok) << "Duplicate key found: " << it->first; | 50 DCHECK(ok) << "Duplicate key found: " << it->first; |
| 65 } | 51 } |
| 66 | 52 |
| 67 --num_pending_requests_; | 53 --num_pending_requests_; |
| 68 if (num_pending_requests_ > 0) | 54 if (num_pending_requests_ > 0) |
| 69 return; | 55 return; |
| 70 | 56 |
| 71 callback_.Run(response_.Pass()); | 57 callback_.Run(response_.Pass()); |
| 72 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 58 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 73 } | 59 } |
| 74 | 60 |
| 75 } // namespace chromeos | 61 } // namespace chromeos |
| OLD | NEW |