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

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/feature_list.h" 13 #include "base/feature_list.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/memory_pressure_monitor.h" 17 #include "base/memory/memory_pressure_monitor.h"
18 #include "base/memory/ptr_util.h"
17 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
19 #include "base/pending_task.h" 21 #include "base/pending_task.h"
20 #include "base/power_monitor/power_monitor.h" 22 #include "base/power_monitor/power_monitor.h"
21 #include "base/power_monitor/power_monitor_device_source.h" 23 #include "base/power_monitor/power_monitor_device_source.h"
22 #include "base/process/process_metrics.h" 24 #include "base/process/process_metrics.h"
23 #include "base/profiler/scoped_profile.h" 25 #include "base/profiler/scoped_profile.h"
24 #include "base/run_loop.h" 26 #include "base/run_loop.h"
25 #include "base/single_thread_task_runner.h" 27 #include "base/single_thread_task_runner.h"
26 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 #endif 191 #endif
190 192
191 namespace content { 193 namespace content {
192 namespace { 194 namespace {
193 195
194 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 196 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
195 void SetupSandbox(const base::CommandLine& parsed_command_line) { 197 void SetupSandbox(const base::CommandLine& parsed_command_line) {
196 TRACE_EVENT0("startup", "SetupSandbox"); 198 TRACE_EVENT0("startup", "SetupSandbox");
197 base::FilePath sandbox_binary; 199 base::FilePath sandbox_binary;
198 200
199 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( 201 std::unique_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host(
200 sandbox::SetuidSandboxHost::Create()); 202 sandbox::SetuidSandboxHost::Create());
201 203
202 const bool want_setuid_sandbox = 204 const bool want_setuid_sandbox =
203 !parsed_command_line.HasSwitch(switches::kNoSandbox) && 205 !parsed_command_line.HasSwitch(switches::kNoSandbox) &&
204 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox) && 206 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox) &&
205 !setuid_sandbox_host->IsDisabledViaEnvironment(); 207 !setuid_sandbox_host->IsDisabledViaEnvironment();
206 208
207 static const char no_suid_error[] = 209 static const char no_suid_error[] =
208 "Running without the SUID sandbox! See " 210 "Running without the SUID sandbox! See "
209 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_s andbox_development.md " 211 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_s andbox_development.md "
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 void OnStoppedStartupTracing(const base::FilePath& trace_file) { 293 void OnStoppedStartupTracing(const base::FilePath& trace_file) {
292 VLOG(0) << "Completed startup tracing to " << trace_file.value(); 294 VLOG(0) << "Completed startup tracing to " << trace_file.value();
293 } 295 }
294 296
295 // Disable optimizations for this block of functions so the compiler doesn't 297 // Disable optimizations for this block of functions so the compiler doesn't
296 // merge them all together. This makes it possible to tell what thread was 298 // merge them all together. This makes it possible to tell what thread was
297 // unresponsive by inspecting the callstack. 299 // unresponsive by inspecting the callstack.
298 MSVC_DISABLE_OPTIMIZE() 300 MSVC_DISABLE_OPTIMIZE()
299 MSVC_PUSH_DISABLE_WARNING(4748) 301 MSVC_PUSH_DISABLE_WARNING(4748)
300 302
301 NOINLINE void ResetThread_DB(scoped_ptr<BrowserProcessSubThread> thread) { 303 NOINLINE void ResetThread_DB(std::unique_ptr<BrowserProcessSubThread> thread) {
302 volatile int inhibit_comdat = __LINE__; 304 volatile int inhibit_comdat = __LINE__;
303 ALLOW_UNUSED_LOCAL(inhibit_comdat); 305 ALLOW_UNUSED_LOCAL(inhibit_comdat);
304 thread.reset(); 306 thread.reset();
305 } 307 }
306 308
307 NOINLINE void ResetThread_FILE(scoped_ptr<BrowserProcessSubThread> thread) { 309 NOINLINE void ResetThread_FILE(
310 std::unique_ptr<BrowserProcessSubThread> thread) {
308 volatile int inhibit_comdat = __LINE__; 311 volatile int inhibit_comdat = __LINE__;
309 ALLOW_UNUSED_LOCAL(inhibit_comdat); 312 ALLOW_UNUSED_LOCAL(inhibit_comdat);
310 thread.reset(); 313 thread.reset();
311 } 314 }
312 315
313 NOINLINE void ResetThread_FILE_USER_BLOCKING( 316 NOINLINE void ResetThread_FILE_USER_BLOCKING(
314 scoped_ptr<BrowserProcessSubThread> thread) { 317 std::unique_ptr<BrowserProcessSubThread> thread) {
315 volatile int inhibit_comdat = __LINE__; 318 volatile int inhibit_comdat = __LINE__;
316 ALLOW_UNUSED_LOCAL(inhibit_comdat); 319 ALLOW_UNUSED_LOCAL(inhibit_comdat);
317 thread.reset(); 320 thread.reset();
318 } 321 }
319 322
320 NOINLINE void ResetThread_PROCESS_LAUNCHER( 323 NOINLINE void ResetThread_PROCESS_LAUNCHER(
321 scoped_ptr<BrowserProcessSubThread> thread) { 324 std::unique_ptr<BrowserProcessSubThread> thread) {
322 volatile int inhibit_comdat = __LINE__; 325 volatile int inhibit_comdat = __LINE__;
323 ALLOW_UNUSED_LOCAL(inhibit_comdat); 326 ALLOW_UNUSED_LOCAL(inhibit_comdat);
324 thread.reset(); 327 thread.reset();
325 } 328 }
326 329
327 NOINLINE void ResetThread_CACHE(scoped_ptr<BrowserProcessSubThread> thread) { 330 NOINLINE void ResetThread_CACHE(
331 std::unique_ptr<BrowserProcessSubThread> thread) {
328 volatile int inhibit_comdat = __LINE__; 332 volatile int inhibit_comdat = __LINE__;
329 ALLOW_UNUSED_LOCAL(inhibit_comdat); 333 ALLOW_UNUSED_LOCAL(inhibit_comdat);
330 thread.reset(); 334 thread.reset();
331 } 335 }
332 336
333 NOINLINE void ResetThread_IO(scoped_ptr<BrowserProcessSubThread> thread) { 337 NOINLINE void ResetThread_IO(std::unique_ptr<BrowserProcessSubThread> thread) {
334 volatile int inhibit_comdat = __LINE__; 338 volatile int inhibit_comdat = __LINE__;
335 ALLOW_UNUSED_LOCAL(inhibit_comdat); 339 ALLOW_UNUSED_LOCAL(inhibit_comdat);
336 thread.reset(); 340 thread.reset();
337 } 341 }
338 342
339 NOINLINE void ResetThread_IndexedDb(scoped_ptr<base::Thread> thread) { 343 NOINLINE void ResetThread_IndexedDb(std::unique_ptr<base::Thread> thread) {
340 volatile int inhibit_comdat = __LINE__; 344 volatile int inhibit_comdat = __LINE__;
341 ALLOW_UNUSED_LOCAL(inhibit_comdat); 345 ALLOW_UNUSED_LOCAL(inhibit_comdat);
342 thread.reset(); 346 thread.reset();
343 } 347 }
344 348
345 MSVC_POP_WARNING() 349 MSVC_POP_WARNING()
346 MSVC_ENABLE_OPTIMIZE(); 350 MSVC_ENABLE_OPTIMIZE();
347 351
348 #if defined(OS_WIN) 352 #if defined(OS_WIN)
349 // Creates a memory pressure monitor using automatic thresholds, or those 353 // Creates a memory pressure monitor using automatic thresholds, or those
(...skipping 28 matching lines...) Expand all
378 382
379 // For measuring memory usage after each task. Behind a command line flag. 383 // For measuring memory usage after each task. Behind a command line flag.
380 class BrowserMainLoop::MemoryObserver : public base::MessageLoop::TaskObserver { 384 class BrowserMainLoop::MemoryObserver : public base::MessageLoop::TaskObserver {
381 public: 385 public:
382 MemoryObserver() {} 386 MemoryObserver() {}
383 ~MemoryObserver() override {} 387 ~MemoryObserver() override {}
384 388
385 void WillProcessTask(const base::PendingTask& pending_task) override {} 389 void WillProcessTask(const base::PendingTask& pending_task) override {}
386 390
387 void DidProcessTask(const base::PendingTask& pending_task) override { 391 void DidProcessTask(const base::PendingTask& pending_task) override {
388 scoped_ptr<base::ProcessMetrics> process_metrics( 392 std::unique_ptr<base::ProcessMetrics> process_metrics(
389 base::ProcessMetrics::CreateCurrentProcessMetrics()); 393 base::ProcessMetrics::CreateCurrentProcessMetrics());
390 size_t private_bytes; 394 size_t private_bytes;
391 process_metrics->GetMemoryBytes(&private_bytes, NULL); 395 process_metrics->GetMemoryBytes(&private_bytes, NULL);
392 LOCAL_HISTOGRAM_MEMORY_KB("Memory.BrowserUsed", private_bytes >> 10); 396 LOCAL_HISTOGRAM_MEMORY_KB("Memory.BrowserUsed", private_bytes >> 10);
393 } 397 }
394 private: 398 private:
395 DISALLOW_COPY_AND_ASSIGN(MemoryObserver); 399 DISALLOW_COPY_AND_ASSIGN(MemoryObserver);
396 }; 400 };
397 401
398 402
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 InitializeMainThread(); 543 InitializeMainThread();
540 } 544 }
541 545
542 void BrowserMainLoop::PostMainMessageLoopStart() { 546 void BrowserMainLoop::PostMainMessageLoopStart() {
543 { 547 {
544 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SystemMonitor"); 548 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SystemMonitor");
545 system_monitor_.reset(new base::SystemMonitor); 549 system_monitor_.reset(new base::SystemMonitor);
546 } 550 }
547 { 551 {
548 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:PowerMonitor"); 552 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:PowerMonitor");
549 scoped_ptr<base::PowerMonitorSource> power_monitor_source( 553 std::unique_ptr<base::PowerMonitorSource> power_monitor_source(
550 new base::PowerMonitorDeviceSource()); 554 new base::PowerMonitorDeviceSource());
551 power_monitor_.reset( 555 power_monitor_.reset(
552 new base::PowerMonitor(std::move(power_monitor_source))); 556 new base::PowerMonitor(std::move(power_monitor_source)));
553 } 557 }
554 { 558 {
555 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:HighResTimerManager"); 559 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:HighResTimerManager");
556 hi_res_timer_manager_.reset(new base::HighResolutionTimerManager); 560 hi_res_timer_manager_.reset(new base::HighResolutionTimerManager);
557 } 561 }
558 { 562 {
559 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:NetworkChangeNotifier"); 563 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:NetworkChangeNotifier");
560 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 564 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 return result_code_; 755 return result_code_;
752 } 756 }
753 757
754 void BrowserMainLoop::CreateStartupTasks() { 758 void BrowserMainLoop::CreateStartupTasks() {
755 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); 759 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks");
756 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::CreateStartupTasks"); 760 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::CreateStartupTasks");
757 761
758 // First time through, we really want to create all the tasks 762 // First time through, we really want to create all the tasks
759 if (!startup_task_runner_.get()) { 763 if (!startup_task_runner_.get()) {
760 #if defined(OS_ANDROID) 764 #if defined(OS_ANDROID)
761 startup_task_runner_ = make_scoped_ptr( 765 startup_task_runner_ = base::WrapUnique(
762 new StartupTaskRunner(base::Bind(&BrowserStartupComplete), 766 new StartupTaskRunner(base::Bind(&BrowserStartupComplete),
763 base::ThreadTaskRunnerHandle::Get())); 767 base::ThreadTaskRunnerHandle::Get()));
764 #else 768 #else
765 startup_task_runner_ = make_scoped_ptr( 769 startup_task_runner_ = base::WrapUnique(new StartupTaskRunner(
766 new StartupTaskRunner(base::Callback<void(int)>(), 770 base::Callback<void(int)>(), base::ThreadTaskRunnerHandle::Get()));
767 base::ThreadTaskRunnerHandle::Get()));
768 #endif 771 #endif
769 StartupTask pre_create_threads = 772 StartupTask pre_create_threads =
770 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); 773 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this));
771 startup_task_runner_->AddTask(pre_create_threads); 774 startup_task_runner_->AddTask(pre_create_threads);
772 775
773 StartupTask create_threads = 776 StartupTask create_threads =
774 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); 777 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this));
775 startup_task_runner_->AddTask(create_threads); 778 startup_task_runner_->AddTask(create_threads);
776 779
777 StartupTask browser_thread_started = base::Bind( 780 StartupTask browser_thread_started = base::Bind(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; 815 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI;
813 816
814 // Start threads in the order they occur in the BrowserThread::ID 817 // Start threads in the order they occur in the BrowserThread::ID
815 // enumeration, except for BrowserThread::UI which is the main 818 // enumeration, except for BrowserThread::UI which is the main
816 // thread. 819 // thread.
817 // 820 //
818 // Must be size_t so we can increment it. 821 // Must be size_t so we can increment it.
819 for (size_t thread_id = BrowserThread::UI + 1; 822 for (size_t thread_id = BrowserThread::UI + 1;
820 thread_id < BrowserThread::ID_COUNT; 823 thread_id < BrowserThread::ID_COUNT;
821 ++thread_id) { 824 ++thread_id) {
822 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; 825 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = NULL;
823 base::Thread::Options options; 826 base::Thread::Options options;
824 827
825 switch (thread_id) { 828 switch (thread_id) {
826 case BrowserThread::DB: 829 case BrowserThread::DB:
827 TRACE_EVENT_BEGIN1("startup", 830 TRACE_EVENT_BEGIN1("startup",
828 "BrowserMainLoop::CreateThreads:start", 831 "BrowserMainLoop::CreateThreads:start",
829 "Thread", "BrowserThread::DB"); 832 "Thread", "BrowserThread::DB");
830 thread_to_start = &db_thread_; 833 thread_to_start = &db_thread_;
831 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 834 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
832 break; 835 break;
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 DCHECK(is_tracing_startup_for_duration_); 1450 DCHECK(is_tracing_startup_for_duration_);
1448 1451
1449 is_tracing_startup_for_duration_ = false; 1452 is_tracing_startup_for_duration_ = false;
1450 TracingController::GetInstance()->StopTracing( 1453 TracingController::GetInstance()->StopTracing(
1451 TracingController::CreateFileSink( 1454 TracingController::CreateFileSink(
1452 startup_trace_file_, 1455 startup_trace_file_,
1453 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); 1456 base::Bind(OnStoppedStartupTracing, startup_trace_file_)));
1454 } 1457 }
1455 1458
1456 } // namespace content 1459 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698