| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/log_private/log_private_api.h" | 5 #include "chrome/browser/extensions/api/log_private/log_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/linked_ptr.h" | |
| 17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 18 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
| 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 20 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 22 #include "chrome/browser/extensions/api/log_private/filter_handler.h" | 21 #include "chrome/browser/extensions/api/log_private/filter_handler.h" |
| 23 #include "chrome/browser/extensions/api/log_private/log_parser.h" | 22 #include "chrome/browser/extensions/api/log_private/log_parser.h" |
| 24 #include "chrome/browser/extensions/api/log_private/syslog_parser.h" | 23 #include "chrome/browser/extensions/api/log_private/syslog_parser.h" |
| 25 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h" | 24 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h" |
| 26 #include "chrome/browser/io_thread.h" | 25 #include "chrome/browser/io_thread.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 70 |
| 72 scoped_ptr<LogParser> CreateLogParser(const std::string& log_type) { | 71 scoped_ptr<LogParser> CreateLogParser(const std::string& log_type) { |
| 73 if (log_type == "syslog") | 72 if (log_type == "syslog") |
| 74 return scoped_ptr<LogParser>(new SyslogParser()); | 73 return scoped_ptr<LogParser>(new SyslogParser()); |
| 75 // TODO(shinfan): Add more parser here | 74 // TODO(shinfan): Add more parser here |
| 76 | 75 |
| 77 NOTREACHED() << "Invalid log type: " << log_type; | 76 NOTREACHED() << "Invalid log type: " << log_type; |
| 78 return scoped_ptr<LogParser>(); | 77 return scoped_ptr<LogParser>(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void CollectLogInfo( | 80 void CollectLogInfo(FilterHandler* filter_handler, |
| 82 FilterHandler* filter_handler, | 81 system_logs::SystemLogsResponse* logs, |
| 83 system_logs::SystemLogsResponse* logs, | 82 std::vector<api::log_private::LogEntry>* output) { |
| 84 std::vector<linked_ptr<api::log_private::LogEntry> >* output) { | |
| 85 for (system_logs::SystemLogsResponse::const_iterator | 83 for (system_logs::SystemLogsResponse::const_iterator |
| 86 request_it = logs->begin(); request_it != logs->end(); ++request_it) { | 84 request_it = logs->begin(); request_it != logs->end(); ++request_it) { |
| 87 if (!filter_handler->IsValidSource(request_it->first)) { | 85 if (!filter_handler->IsValidSource(request_it->first)) { |
| 88 continue; | 86 continue; |
| 89 } | 87 } |
| 90 scoped_ptr<LogParser> parser(CreateLogParser(request_it->first)); | 88 scoped_ptr<LogParser> parser(CreateLogParser(request_it->first)); |
| 91 if (parser) { | 89 if (parser) { |
| 92 parser->Parse(request_it->second, output, filter_handler); | 90 parser->Parse(request_it->second, output, filter_handler); |
| 93 } | 91 } |
| 94 } | 92 } |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 fetcher = new system_logs::AboutSystemLogsFetcher(); | 415 fetcher = new system_logs::AboutSystemLogsFetcher(); |
| 418 } | 416 } |
| 419 fetcher->Fetch( | 417 fetcher->Fetch( |
| 420 base::Bind(&LogPrivateGetHistoricalFunction::OnSystemLogsLoaded, this)); | 418 base::Bind(&LogPrivateGetHistoricalFunction::OnSystemLogsLoaded, this)); |
| 421 | 419 |
| 422 return true; | 420 return true; |
| 423 } | 421 } |
| 424 | 422 |
| 425 void LogPrivateGetHistoricalFunction::OnSystemLogsLoaded( | 423 void LogPrivateGetHistoricalFunction::OnSystemLogsLoaded( |
| 426 scoped_ptr<system_logs::SystemLogsResponse> sys_info) { | 424 scoped_ptr<system_logs::SystemLogsResponse> sys_info) { |
| 427 std::vector<linked_ptr<api::log_private::LogEntry> > data; | |
| 428 | |
| 429 CollectLogInfo(filter_handler_.get(), sys_info.get(), &data); | |
| 430 | 425 |
| 431 // Prepare result | 426 // Prepare result |
| 432 api::log_private::Result result; | 427 api::log_private::Result result; |
| 433 result.data = data; | 428 CollectLogInfo(filter_handler_.get(), sys_info.get(), &result.data); |
| 434 api::log_private::Filter::Populate( | 429 api::log_private::Filter::Populate( |
| 435 *((filter_handler_->GetFilter())->ToValue()), &result.filter); | 430 *((filter_handler_->GetFilter())->ToValue()), &result.filter); |
| 436 SetResult(result.ToValue().release()); | 431 SetResult(result.ToValue().release()); |
| 437 SendResponse(true); | 432 SendResponse(true); |
| 438 } | 433 } |
| 439 | 434 |
| 440 LogPrivateStartEventRecorderFunction::LogPrivateStartEventRecorderFunction() { | 435 LogPrivateStartEventRecorderFunction::LogPrivateStartEventRecorderFunction() { |
| 441 } | 436 } |
| 442 | 437 |
| 443 LogPrivateStartEventRecorderFunction::~LogPrivateStartEventRecorderFunction() { | 438 LogPrivateStartEventRecorderFunction::~LogPrivateStartEventRecorderFunction() { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 entry->SetBoolean("isDirectory", false); | 539 entry->SetBoolean("isDirectory", false); |
| 545 base::ListValue* entry_list = new base::ListValue(); | 540 base::ListValue* entry_list = new base::ListValue(); |
| 546 entry_list->Append(entry); | 541 entry_list->Append(entry); |
| 547 response->Set("entries", entry_list); | 542 response->Set("entries", entry_list); |
| 548 response->SetBoolean("multiple", false); | 543 response->SetBoolean("multiple", false); |
| 549 SetResult(response.release()); | 544 SetResult(response.release()); |
| 550 SendResponse(succeeded); | 545 SendResponse(succeeded); |
| 551 } | 546 } |
| 552 | 547 |
| 553 } // namespace extensions | 548 } // namespace extensions |
| OLD | NEW |