| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 new base::win::MemoryPressureMonitor(); |
| 373 } | 373 } |
| 374 #endif // defined(OS_WIN) | 374 #endif // defined(OS_WIN) |
| 375 | 375 |
| 376 } // namespace | 376 } // namespace |
| 377 | 377 |
| 378 // The currently-running BrowserMainLoop. There can be one or zero. | 378 // The currently-running BrowserMainLoop. There can be one or zero. |
| 379 BrowserMainLoop* g_current_browser_main_loop = NULL; | 379 BrowserMainLoop* g_current_browser_main_loop = NULL; |
| 380 | 380 |
| 381 // For measuring memory usage after each task. Behind a command line flag. | |
| 382 class BrowserMainLoop::MemoryObserver : public base::MessageLoop::TaskObserver { | |
| 383 public: | |
| 384 MemoryObserver() {} | |
| 385 ~MemoryObserver() override {} | |
| 386 | |
| 387 void WillProcessTask(const base::PendingTask& pending_task) override {} | |
| 388 | |
| 389 void DidProcessTask(const base::PendingTask& pending_task) override { | |
| 390 #if !defined(OS_IOS) // No ProcessMetrics on IOS. | |
| 391 scoped_ptr<base::ProcessMetrics> process_metrics( | |
| 392 base::ProcessMetrics::CreateCurrentProcessMetrics()); | |
| 393 size_t private_bytes; | |
| 394 process_metrics->GetMemoryBytes(&private_bytes, NULL); | |
| 395 LOCAL_HISTOGRAM_MEMORY_KB("Memory.BrowserUsed", private_bytes >> 10); | |
| 396 #endif | |
| 397 } | |
| 398 private: | |
| 399 DISALLOW_COPY_AND_ASSIGN(MemoryObserver); | |
| 400 }; | |
| 401 | |
| 402 | 381 |
| 403 // BrowserMainLoop construction / destruction ============================= | 382 // BrowserMainLoop construction / destruction ============================= |
| 404 | 383 |
| 405 BrowserMainLoop* BrowserMainLoop::GetInstance() { | 384 BrowserMainLoop* BrowserMainLoop::GetInstance() { |
| 406 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 385 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 407 return g_current_browser_main_loop; | 386 return g_current_browser_main_loop; |
| 408 } | 387 } |
| 409 | 388 |
| 410 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) | 389 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) |
| 411 : parameters_(parameters), | 390 : parameters_(parameters), |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 #endif | 647 #endif |
| 669 | 648 |
| 670 #if defined(USE_OZONE) | 649 #if defined(USE_OZONE) |
| 671 client_native_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); | 650 client_native_pixmap_factory_ = ui::ClientNativePixmapFactory::Create(); |
| 672 ui::ClientNativePixmapFactory::SetInstance( | 651 ui::ClientNativePixmapFactory::SetInstance( |
| 673 client_native_pixmap_factory_.get()); | 652 client_native_pixmap_factory_.get()); |
| 674 ui::ClientNativePixmapFactory::GetInstance()->Initialize( | 653 ui::ClientNativePixmapFactory::GetInstance()->Initialize( |
| 675 ui::OzonePlatform::GetInstance()->OpenClientNativePixmapDevice()); | 654 ui::OzonePlatform::GetInstance()->OpenClientNativePixmapDevice()); |
| 676 #endif | 655 #endif |
| 677 | 656 |
| 678 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { | |
| 679 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver"); | |
| 680 memory_observer_.reset(new MemoryObserver()); | |
| 681 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); | |
| 682 } | |
| 683 | |
| 684 if (parsed_command_line_.HasSwitch( | 657 if (parsed_command_line_.HasSwitch( |
| 685 switches::kEnableAggressiveDOMStorageFlushing)) { | 658 switches::kEnableAggressiveDOMStorageFlushing)) { |
| 686 TRACE_EVENT0("startup", | 659 TRACE_EVENT0("startup", |
| 687 "BrowserMainLoop::Subsystem:EnableAggressiveCommitDelay"); | 660 "BrowserMainLoop::Subsystem:EnableAggressiveCommitDelay"); |
| 688 DOMStorageArea::EnableAggressiveCommitDelay(); | 661 DOMStorageArea::EnableAggressiveCommitDelay(); |
| 689 } | 662 } |
| 690 | 663 |
| 691 // Enable memory-infra dump providers. | 664 // Enable memory-infra dump providers. |
| 692 InitSkiaEventTracer(); | 665 InitSkiaEventTracer(); |
| 693 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( | 666 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 DCHECK(is_tracing_startup_for_duration_); | 1436 DCHECK(is_tracing_startup_for_duration_); |
| 1464 | 1437 |
| 1465 is_tracing_startup_for_duration_ = false; | 1438 is_tracing_startup_for_duration_ = false; |
| 1466 TracingController::GetInstance()->StopTracing( | 1439 TracingController::GetInstance()->StopTracing( |
| 1467 TracingController::CreateFileSink( | 1440 TracingController::CreateFileSink( |
| 1468 startup_trace_file_, | 1441 startup_trace_file_, |
| 1469 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1442 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1470 } | 1443 } |
| 1471 | 1444 |
| 1472 } // namespace content | 1445 } // namespace content |
| OLD | NEW |