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