| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.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" | |
| 11 #include "chrome/browser/chromeos/system_logs/dbus_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" | |
| 14 #include "chrome/browser/chromeos/system_logs/memory_details_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" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 SystemLogsFetcher::SystemLogsFetcher() | |
| 24 : response_(new SystemLogsResponse), | |
| 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 } | |
| 41 | |
| 42 SystemLogsFetcher::~SystemLogsFetcher() {} | |
| 43 | |
| 44 void SystemLogsFetcher::Fetch(const SysLogsFetcherCallback& callback) { | |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 46 DCHECK(callback_.is_null()); | |
| 47 DCHECK(!callback.is_null()); | |
| 48 | |
| 49 callback_ = callback; | |
| 50 for (size_t i = 0; i < data_sources_.size(); ++i) { | |
| 51 data_sources_[i]->Fetch(base::Bind(&SystemLogsFetcher::AddResponse, | |
| 52 weak_ptr_factory_.GetWeakPtr())); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void SystemLogsFetcher::AddResponse(SystemLogsResponse* response) { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 58 | |
| 59 for (SystemLogsResponse::const_iterator it = response->begin(); | |
| 60 it != response->end(); | |
| 61 ++it) { | |
| 62 // It is an error to insert an element with a pre-existing key. | |
| 63 bool ok = response_->insert(*it).second; | |
| 64 DCHECK(ok) << "Duplicate key found: " << it->first; | |
| 65 } | |
| 66 | |
| 67 --num_pending_requests_; | |
| 68 if (num_pending_requests_ > 0) | |
| 69 return; | |
| 70 | |
| 71 callback_.Run(response_.Pass()); | |
| 72 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | |
| 73 } | |
| 74 | |
| 75 } // namespace chromeos | |
| OLD | NEW |