| 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 "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 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 343 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
| 344 thread.reset(); | 344 thread.reset(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 MSVC_POP_WARNING() | 347 MSVC_POP_WARNING() |
| 348 MSVC_ENABLE_OPTIMIZE(); | 348 MSVC_ENABLE_OPTIMIZE(); |
| 349 | 349 |
| 350 #if defined(OS_WIN) | 350 #if defined(OS_WIN) |
| 351 // Creates a memory pressure monitor using automatic thresholds, or those | 351 // Creates a memory pressure monitor using automatic thresholds, or those |
| 352 // specified on the command-line. Ownership is passed to the caller. | 352 // specified on the command-line. Ownership is passed to the caller. |
| 353 base::win::MemoryPressureMonitor* CreateWinMemoryPressureMonitor( | 353 std::unique_ptr<base::win::MemoryPressureMonitor> |
| 354 const base::CommandLine& parsed_command_line) { | 354 CreateWinMemoryPressureMonitor(const base::CommandLine& parsed_command_line) { |
| 355 std::vector<std::string> thresholds = base::SplitString( | 355 std::vector<std::string> thresholds = |
| 356 parsed_command_line.GetSwitchValueASCII( | 356 base::SplitString(parsed_command_line.GetSwitchValueASCII( |
| 357 switches::kMemoryPressureThresholdsMb), | 357 switches::kMemoryPressureThresholdsMb), |
| 358 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 358 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 359 | 359 |
| 360 int moderate_threshold_mb = 0; | 360 int moderate_threshold_mb = 0; |
| 361 int critical_threshold_mb = 0; | 361 int critical_threshold_mb = 0; |
| 362 if (thresholds.size() == 2 && | 362 if (thresholds.size() == 2 && |
| 363 base::StringToInt(thresholds[0], &moderate_threshold_mb) && | 363 base::StringToInt(thresholds[0], &moderate_threshold_mb) && |
| 364 base::StringToInt(thresholds[1], &critical_threshold_mb) && | 364 base::StringToInt(thresholds[1], &critical_threshold_mb) && |
| 365 moderate_threshold_mb >= critical_threshold_mb && | 365 moderate_threshold_mb >= critical_threshold_mb && |
| 366 critical_threshold_mb >= 0) { | 366 critical_threshold_mb >= 0) { |
| 367 return new base::win::MemoryPressureMonitor(moderate_threshold_mb, | 367 return base::MakeUnique<base::win::MemoryPressureMonitor>( |
| 368 critical_threshold_mb); | 368 moderate_threshold_mb, critical_threshold_mb); |
| 369 } | 369 } |
| 370 | 370 |
| 371 // In absence of valid switches use the automatic defaults. | 371 // In absence of valid switches use the automatic defaults. |
| 372 return new base::win::MemoryPressureMonitor(); | 372 return base::MakeUnique<base::win::MemoryPressureMonitor>(); |
| 373 } | 373 } |
| 374 #endif // defined(OS_WIN) | 374 #endif // defined(OS_WIN) |
| 375 | 375 |
| 376 } // namespace | 376 } // namespace |
| 377 | 377 |
| 378 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 378 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 379 namespace internal { | 379 namespace internal { |
| 380 | 380 |
| 381 // Forwards GPUInfo updates to ui::XVisualManager | 381 // Forwards GPUInfo updates to ui::XVisualManager |
| 382 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { | 382 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 | 1392 |
| 1393 return result_code_; | 1393 return result_code_; |
| 1394 } | 1394 } |
| 1395 | 1395 |
| 1396 bool BrowserMainLoop::UsingInProcessGpu() const { | 1396 bool BrowserMainLoop::UsingInProcessGpu() const { |
| 1397 return parsed_command_line_.HasSwitch(switches::kSingleProcess) || | 1397 return parsed_command_line_.HasSwitch(switches::kSingleProcess) || |
| 1398 parsed_command_line_.HasSwitch(switches::kInProcessGPU); | 1398 parsed_command_line_.HasSwitch(switches::kInProcessGPU); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 void BrowserMainLoop::InitializeMemoryManagementComponent() { | 1401 void BrowserMainLoop::InitializeMemoryManagementComponent() { |
| 1402 // TODO(chrisha): Abstract away this construction mess to a helper function, |
| 1403 // once MemoryPressureMonitor is made a concrete class. |
| 1404 #if defined(OS_CHROMEOS) |
| 1405 if (chromeos::switches::MemoryPressureHandlingEnabled()) { |
| 1406 memory_pressure_monitor_ = |
| 1407 base::MakeUnique<base::chromeos::MemoryPressureMonitor> |
| 1408 chromeos::switches::GetMemoryPressureThresholds()); |
| 1409 } |
| 1410 #elif defined(OS_MACOSX) |
| 1411 memory_pressure_monitor_ = |
| 1412 base::MakeUnique<base::mac::MemoryPressureMonitor>(); |
| 1413 #elif defined(OS_WIN) |
| 1414 memory_pressure_monitor_ = |
| 1415 std::move(CreateWinMemoryPressureMonitor(parsed_command_line_)); |
| 1416 #endif |
| 1417 |
| 1402 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 1418 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 1403 // Disable MemoryPressureListener when memory coordinator is enabled. | 1419 // Disable MemoryPressureListener when memory coordinator is enabled. |
| 1404 base::MemoryPressureListener::SetNotificationsSuppressed(true); | 1420 base::MemoryPressureListener::SetNotificationsSuppressed(true); |
| 1405 // base::Unretained is safe because the lifetime of MemoryCoordinator is | 1421 // base::Unretained is safe because the lifetime of MemoryCoordinator is |
| 1406 // tied to the lifetime of the browser process. | 1422 // tied to the lifetime of the browser process. |
| 1407 base::MemoryCoordinatorProxy::GetInstance()-> | 1423 base::MemoryCoordinatorProxy::GetInstance()-> |
| 1408 SetGetCurrentMemoryStateCallback(base::Bind( | 1424 SetGetCurrentMemoryStateCallback(base::Bind( |
| 1409 &MemoryCoordinator::GetCurrentMemoryState, | 1425 &MemoryCoordinator::GetCurrentMemoryState, |
| 1410 base::Unretained(MemoryCoordinator::GetInstance()))); | 1426 base::Unretained(MemoryCoordinator::GetInstance()))); |
| 1411 base::MemoryCoordinatorProxy::GetInstance()-> | 1427 base::MemoryCoordinatorProxy::GetInstance()-> |
| 1412 SetSetCurrentMemoryStateForTestingCallback(base::Bind( | 1428 SetSetCurrentMemoryStateForTestingCallback(base::Bind( |
| 1413 &MemoryCoordinator::SetCurrentMemoryStateForTesting, | 1429 &MemoryCoordinator::SetCurrentMemoryStateForTesting, |
| 1414 base::Unretained(MemoryCoordinator::GetInstance()))); | 1430 base::Unretained(MemoryCoordinator::GetInstance()))); |
| 1415 return; | 1431 |
| 1432 if (memory_pressure_monitor_) { |
| 1433 memory_pressure_monitor_->SetDispatchCallback( |
| 1434 base::Bind(&MemoryCoordinator::RecordMemoryPressure, |
| 1435 base::Unretained(MemoryCoordinator::GetInstance()))); |
| 1436 } |
| 1416 } | 1437 } |
| 1417 | |
| 1418 // TODO(chrisha): Abstract away this construction mess to a helper function, | |
| 1419 // once MemoryPressureMonitor is made a concrete class. | |
| 1420 #if defined(OS_CHROMEOS) | |
| 1421 if (chromeos::switches::MemoryPressureHandlingEnabled()) { | |
| 1422 memory_pressure_monitor_.reset(new base::chromeos::MemoryPressureMonitor( | |
| 1423 chromeos::switches::GetMemoryPressureThresholds())); | |
| 1424 } | |
| 1425 #elif defined(OS_MACOSX) | |
| 1426 memory_pressure_monitor_.reset(new base::mac::MemoryPressureMonitor()); | |
| 1427 #elif defined(OS_WIN) | |
| 1428 memory_pressure_monitor_.reset(CreateWinMemoryPressureMonitor( | |
| 1429 parsed_command_line_)); | |
| 1430 #endif | |
| 1431 } | 1438 } |
| 1432 | 1439 |
| 1433 bool BrowserMainLoop::InitializeToolkit() { | 1440 bool BrowserMainLoop::InitializeToolkit() { |
| 1434 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); | 1441 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit"); |
| 1435 | 1442 |
| 1436 // TODO(evan): this function is rather subtle, due to the variety | 1443 // TODO(evan): this function is rather subtle, due to the variety |
| 1437 // of intersecting ifdefs we have. To keep it easy to follow, there | 1444 // of intersecting ifdefs we have. To keep it easy to follow, there |
| 1438 // are no #else branches on any #ifs. | 1445 // are no #else branches on any #ifs. |
| 1439 // TODO(stevenjb): Move platform specific code into platform specific Parts | 1446 // TODO(stevenjb): Move platform specific code into platform specific Parts |
| 1440 // (Need to add InitializeToolkit stage to BrowserParts). | 1447 // (Need to add InitializeToolkit stage to BrowserParts). |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner = | 1606 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner = |
| 1600 audio_thread_->task_runner(); | 1607 audio_thread_->task_runner(); |
| 1601 audio_manager_ = media::AudioManager::Create(std::move(audio_task_runner), | 1608 audio_manager_ = media::AudioManager::Create(std::move(audio_task_runner), |
| 1602 std::move(worker_task_runner), | 1609 std::move(worker_task_runner), |
| 1603 MediaInternals::GetInstance()); | 1610 MediaInternals::GetInstance()); |
| 1604 } | 1611 } |
| 1605 CHECK(audio_manager_); | 1612 CHECK(audio_manager_); |
| 1606 } | 1613 } |
| 1607 | 1614 |
| 1608 } // namespace content | 1615 } // namespace content |
| OLD | NEW |