Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
7 #include <string> 8 #include <string>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
14 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/download/download_prefs.h" 19 #include "chrome/browser/download/download_prefs.h"
20 #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"
21 #include "chrome/browser/extensions/api/log_private/filter_handler.h" 21 #include "chrome/browser/extensions/api/log_private/filter_handler.h"
22 #include "chrome/browser/extensions/api/log_private/log_parser.h" 22 #include "chrome/browser/extensions/api/log_private/log_parser.h"
23 #include "chrome/browser/extensions/api/log_private/syslog_parser.h" 23 #include "chrome/browser/extensions/api/log_private/syslog_parser.h"
24 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h" 24 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h"
25 #include "chrome/browser/io_thread.h" 25 #include "chrome/browser/io_thread.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 61 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
62 } 62 }
63 63
64 // Checks if we are running on sequenced task runner thread. 64 // Checks if we are running on sequenced task runner thread.
65 bool IsRunningOnSequenceThread() { 65 bool IsRunningOnSequenceThread() {
66 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); 66 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
67 return pool->IsRunningSequenceOnCurrentThread( 67 return pool->IsRunningSequenceOnCurrentThread(
68 pool->GetNamedSequenceToken(FileResource::kSequenceToken)); 68 pool->GetNamedSequenceToken(FileResource::kSequenceToken));
69 } 69 }
70 70
71 scoped_ptr<LogParser> CreateLogParser(const std::string& log_type) { 71 std::unique_ptr<LogParser> CreateLogParser(const std::string& log_type) {
72 if (log_type == "syslog") 72 if (log_type == "syslog")
73 return scoped_ptr<LogParser>(new SyslogParser()); 73 return std::unique_ptr<LogParser>(new SyslogParser());
74 // TODO(shinfan): Add more parser here 74 // TODO(shinfan): Add more parser here
75 75
76 NOTREACHED() << "Invalid log type: " << log_type; 76 NOTREACHED() << "Invalid log type: " << log_type;
77 return scoped_ptr<LogParser>(); 77 return std::unique_ptr<LogParser>();
78 } 78 }
79 79
80 void CollectLogInfo(FilterHandler* filter_handler, 80 void CollectLogInfo(FilterHandler* filter_handler,
81 system_logs::SystemLogsResponse* logs, 81 system_logs::SystemLogsResponse* logs,
82 std::vector<api::log_private::LogEntry>* output) { 82 std::vector<api::log_private::LogEntry>* output) {
83 for (system_logs::SystemLogsResponse::const_iterator 83 for (system_logs::SystemLogsResponse::const_iterator
84 request_it = logs->begin(); request_it != logs->end(); ++request_it) { 84 request_it = logs->begin(); request_it != logs->end(); ++request_it) {
85 if (!filter_handler->IsValidSource(request_it->first)) { 85 if (!filter_handler->IsValidSource(request_it->first)) {
86 continue; 86 continue;
87 } 87 }
88 scoped_ptr<LogParser> parser(CreateLogParser(request_it->first)); 88 std::unique_ptr<LogParser> parser(CreateLogParser(request_it->first));
89 if (parser) { 89 if (parser) {
90 parser->Parse(request_it->second, output, filter_handler); 90 parser->Parse(request_it->second, output, filter_handler);
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 // Returns directory location of app-specific logs that are initiated with 95 // Returns directory location of app-specific logs that are initiated with
96 // logPrivate.startEventRecorder() calls - /home/chronos/user/log/apps 96 // logPrivate.startEventRecorder() calls - /home/chronos/user/log/apps
97 base::FilePath GetAppLogDirectory() { 97 base::FilePath GetAppLogDirectory() {
98 return logging::GetSessionLogDir(*base::CommandLine::ForCurrentProcess()) 98 return logging::GetSessionLogDir(*base::CommandLine::ForCurrentProcess())
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 234 }
235 235
236 void LogPrivateAPI::PostPendingEntries() { 236 void LogPrivateAPI::PostPendingEntries() {
237 BrowserThread::PostTask( 237 BrowserThread::PostTask(
238 BrowserThread::UI, FROM_HERE, 238 BrowserThread::UI, FROM_HERE,
239 base::Bind(&LogPrivateAPI:: AddEntriesOnUI, 239 base::Bind(&LogPrivateAPI:: AddEntriesOnUI,
240 base::Unretained(this), 240 base::Unretained(this),
241 base::Passed(&pending_entries_))); 241 base::Passed(&pending_entries_)));
242 } 242 }
243 243
244 void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) { 244 void LogPrivateAPI::AddEntriesOnUI(std::unique_ptr<base::ListValue> value) {
245 DCHECK_CURRENTLY_ON(BrowserThread::UI); 245 DCHECK_CURRENTLY_ON(BrowserThread::UI);
246 246
247 for (std::set<std::string>::iterator ix = net_internal_watches_.begin(); 247 for (std::set<std::string>::iterator ix = net_internal_watches_.begin();
248 ix != net_internal_watches_.end(); ++ix) { 248 ix != net_internal_watches_.end(); ++ix) {
249 // Create the event's arguments value. 249 // Create the event's arguments value.
250 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 250 std::unique_ptr<base::ListValue> event_args(new base::ListValue());
251 event_args->Append(value->DeepCopy()); 251 event_args->Append(value->DeepCopy());
252 scoped_ptr<Event> event( 252 std::unique_ptr<Event> event(
253 new Event(::extensions::events::LOG_PRIVATE_ON_CAPTURED_EVENTS, 253 new Event(::extensions::events::LOG_PRIVATE_ON_CAPTURED_EVENTS,
254 ::events::kOnCapturedEvents, std::move(event_args))); 254 ::events::kOnCapturedEvents, std::move(event_args)));
255 EventRouter::Get(browser_context_) 255 EventRouter::Get(browser_context_)
256 ->DispatchEventToExtension(*ix, std::move(event)); 256 ->DispatchEventToExtension(*ix, std::move(event));
257 } 257 }
258 } 258 }
259 259
260 void LogPrivateAPI::CreateTempNetLogFile(const std::string& owner_extension_id, 260 void LogPrivateAPI::CreateTempNetLogFile(const std::string& owner_extension_id,
261 base::ScopedFILE* file) { 261 base::ScopedFILE* file) {
262 DCHECK(IsRunningOnSequenceThread()); 262 DCHECK(IsRunningOnSequenceThread());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 396 }
397 397
398 LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() { 398 LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() {
399 } 399 }
400 400
401 LogPrivateGetHistoricalFunction::~LogPrivateGetHistoricalFunction() { 401 LogPrivateGetHistoricalFunction::~LogPrivateGetHistoricalFunction() {
402 } 402 }
403 403
404 bool LogPrivateGetHistoricalFunction::RunAsync() { 404 bool LogPrivateGetHistoricalFunction::RunAsync() {
405 // Get parameters 405 // Get parameters
406 scoped_ptr<api::log_private::GetHistorical::Params> params( 406 std::unique_ptr<api::log_private::GetHistorical::Params> params(
407 api::log_private::GetHistorical::Params::Create(*args_)); 407 api::log_private::GetHistorical::Params::Create(*args_));
408 EXTENSION_FUNCTION_VALIDATE(params.get()); 408 EXTENSION_FUNCTION_VALIDATE(params.get());
409 filter_handler_.reset(new FilterHandler(params->filter)); 409 filter_handler_.reset(new FilterHandler(params->filter));
410 410
411 system_logs::SystemLogsFetcherBase* fetcher; 411 system_logs::SystemLogsFetcherBase* fetcher;
412 if ((params->filter).scrub) { 412 if ((params->filter).scrub) {
413 fetcher = new system_logs::ScrubbedSystemLogsFetcher(); 413 fetcher = new system_logs::ScrubbedSystemLogsFetcher();
414 } else { 414 } else {
415 fetcher = new system_logs::AboutSystemLogsFetcher(); 415 fetcher = new system_logs::AboutSystemLogsFetcher();
416 } 416 }
417 fetcher->Fetch( 417 fetcher->Fetch(
418 base::Bind(&LogPrivateGetHistoricalFunction::OnSystemLogsLoaded, this)); 418 base::Bind(&LogPrivateGetHistoricalFunction::OnSystemLogsLoaded, this));
419 419
420 return true; 420 return true;
421 } 421 }
422 422
423 void LogPrivateGetHistoricalFunction::OnSystemLogsLoaded( 423 void LogPrivateGetHistoricalFunction::OnSystemLogsLoaded(
424 scoped_ptr<system_logs::SystemLogsResponse> sys_info) { 424 std::unique_ptr<system_logs::SystemLogsResponse> sys_info) {
425
426 // Prepare result 425 // Prepare result
427 api::log_private::Result result; 426 api::log_private::Result result;
428 CollectLogInfo(filter_handler_.get(), sys_info.get(), &result.data); 427 CollectLogInfo(filter_handler_.get(), sys_info.get(), &result.data);
429 api::log_private::Filter::Populate( 428 api::log_private::Filter::Populate(
430 *((filter_handler_->GetFilter())->ToValue()), &result.filter); 429 *((filter_handler_->GetFilter())->ToValue()), &result.filter);
431 SetResult(result.ToValue().release()); 430 SetResult(result.ToValue().release());
432 SendResponse(true); 431 SendResponse(true);
433 } 432 }
434 433
435 LogPrivateStartEventRecorderFunction::LogPrivateStartEventRecorderFunction() { 434 LogPrivateStartEventRecorderFunction::LogPrivateStartEventRecorderFunction() {
436 } 435 }
437 436
438 LogPrivateStartEventRecorderFunction::~LogPrivateStartEventRecorderFunction() { 437 LogPrivateStartEventRecorderFunction::~LogPrivateStartEventRecorderFunction() {
439 } 438 }
440 439
441 bool LogPrivateStartEventRecorderFunction::RunAsync() { 440 bool LogPrivateStartEventRecorderFunction::RunAsync() {
442 scoped_ptr<api::log_private::StartEventRecorder::Params> params( 441 std::unique_ptr<api::log_private::StartEventRecorder::Params> params(
443 api::log_private::StartEventRecorder::Params::Create(*args_)); 442 api::log_private::StartEventRecorder::Params::Create(*args_));
444 EXTENSION_FUNCTION_VALIDATE(params.get()); 443 EXTENSION_FUNCTION_VALIDATE(params.get());
445 switch (params->event_type) { 444 switch (params->event_type) {
446 case api::log_private::EVENT_TYPE_NETWORK: 445 case api::log_private::EVENT_TYPE_NETWORK:
447 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context())) 446 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context()))
448 ->StartNetInternalsWatch( 447 ->StartNetInternalsWatch(
449 extension_id(), 448 extension_id(),
450 params->sink, 449 params->sink,
451 base::Bind( 450 base::Bind(
452 &LogPrivateStartEventRecorderFunction::OnEventRecorderStarted, 451 &LogPrivateStartEventRecorderFunction::OnEventRecorderStarted,
(...skipping 11 matching lines...) Expand all
464 SendResponse(true); 463 SendResponse(true);
465 } 464 }
466 465
467 LogPrivateStopEventRecorderFunction::LogPrivateStopEventRecorderFunction() { 466 LogPrivateStopEventRecorderFunction::LogPrivateStopEventRecorderFunction() {
468 } 467 }
469 468
470 LogPrivateStopEventRecorderFunction::~LogPrivateStopEventRecorderFunction() { 469 LogPrivateStopEventRecorderFunction::~LogPrivateStopEventRecorderFunction() {
471 } 470 }
472 471
473 bool LogPrivateStopEventRecorderFunction::RunAsync() { 472 bool LogPrivateStopEventRecorderFunction::RunAsync() {
474 scoped_ptr<api::log_private::StopEventRecorder::Params> params( 473 std::unique_ptr<api::log_private::StopEventRecorder::Params> params(
475 api::log_private::StopEventRecorder::Params::Create(*args_)); 474 api::log_private::StopEventRecorder::Params::Create(*args_));
476 EXTENSION_FUNCTION_VALIDATE(params.get()); 475 EXTENSION_FUNCTION_VALIDATE(params.get());
477 switch (params->event_type) { 476 switch (params->event_type) {
478 case api::log_private::EVENT_TYPE_NETWORK: 477 case api::log_private::EVENT_TYPE_NETWORK:
479 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context())) 478 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context()))
480 ->StopNetInternalsWatch( 479 ->StopNetInternalsWatch(
481 extension_id(), 480 extension_id(),
482 base::Bind( 481 base::Bind(
483 &LogPrivateStopEventRecorderFunction::OnEventRecorderStopped, 482 &LogPrivateStopEventRecorderFunction::OnEventRecorderStopped,
484 this)); 483 this));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 515 }
517 516
518 void LogPrivateDumpLogsFunction::OnStoreLogsCompleted( 517 void LogPrivateDumpLogsFunction::OnStoreLogsCompleted(
519 const base::FilePath& log_path, 518 const base::FilePath& log_path,
520 bool succeeded) { 519 bool succeeded) {
521 if (succeeded) { 520 if (succeeded) {
522 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context())) 521 LogPrivateAPI::Get(Profile::FromBrowserContext(browser_context()))
523 ->RegisterTempFile(extension_id(), log_path); 522 ->RegisterTempFile(extension_id(), log_path);
524 } 523 }
525 524
526 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); 525 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue());
527 extensions::GrantedFileEntry file_entry = 526 extensions::GrantedFileEntry file_entry =
528 extensions::app_file_handler_util::CreateFileEntry( 527 extensions::app_file_handler_util::CreateFileEntry(
529 Profile::FromBrowserContext(browser_context()), 528 Profile::FromBrowserContext(browser_context()),
530 extension(), 529 extension(),
531 render_frame_host()->GetProcess()->GetID(), 530 render_frame_host()->GetProcess()->GetID(),
532 log_path, 531 log_path,
533 false); 532 false);
534 533
535 base::DictionaryValue* entry = new base::DictionaryValue(); 534 base::DictionaryValue* entry = new base::DictionaryValue();
536 entry->SetString("fileSystemId", file_entry.filesystem_id); 535 entry->SetString("fileSystemId", file_entry.filesystem_id);
537 entry->SetString("baseName", file_entry.registered_name); 536 entry->SetString("baseName", file_entry.registered_name);
538 entry->SetString("id", file_entry.id); 537 entry->SetString("id", file_entry.id);
539 entry->SetBoolean("isDirectory", false); 538 entry->SetBoolean("isDirectory", false);
540 base::ListValue* entry_list = new base::ListValue(); 539 base::ListValue* entry_list = new base::ListValue();
541 entry_list->Append(entry); 540 entry_list->Append(entry);
542 response->Set("entries", entry_list); 541 response->Set("entries", entry_list);
543 response->SetBoolean("multiple", false); 542 response->SetBoolean("multiple", false);
544 SetResult(response.release()); 543 SetResult(response.release());
545 SendResponse(succeeded); 544 SendResponse(succeeded);
546 } 545 }
547 546
548 } // namespace extensions 547 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698