| 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/public/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/persistent_histogram_allocator.h" |
| 14 #include "base/metrics/statistics_recorder.h" | 15 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/profiler/scoped_profile.h" | 16 #include "base/profiler/scoped_profile.h" |
| 16 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 19 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 20 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "components/tracing/trace_config_file.h" | 23 #include "components/tracing/trace_config_file.h" |
| 23 #include "components/tracing/tracing_switches.h" | 24 #include "components/tracing/tracing_switches.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 public: | 54 public: |
| 54 BrowserMainRunnerImpl() | 55 BrowserMainRunnerImpl() |
| 55 : initialization_started_(false), is_shutdown_(false) {} | 56 : initialization_started_(false), is_shutdown_(false) {} |
| 56 | 57 |
| 57 ~BrowserMainRunnerImpl() override { | 58 ~BrowserMainRunnerImpl() override { |
| 58 if (initialization_started_ && !is_shutdown_) | 59 if (initialization_started_ && !is_shutdown_) |
| 59 Shutdown(); | 60 Shutdown(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 int Initialize(const MainFunctionParams& parameters) override { | 63 int Initialize(const MainFunctionParams& parameters) override { |
| 64 // Create persistent/shared memory and allow histograms to be stored in it. |
| 65 // Memory that is not actualy used won't be physically mapped by the system. |
| 66 // BrowserMetrics usage peaked around 1.9MiB as of 2016-02-20. |
| 67 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
| 68 3 << 20, // 3 MiB |
| 69 0x935DDD43, // SHA1(BrowserMetrics) |
| 70 "BrowserMetrics"); |
| 71 base::GlobalHistogramAllocator::Disable(); // Enabled by experiment only. |
| 72 |
| 63 SCOPED_UMA_HISTOGRAM_LONG_TIMER( | 73 SCOPED_UMA_HISTOGRAM_LONG_TIMER( |
| 64 "Startup.BrowserMainRunnerImplInitializeLongTime"); | 74 "Startup.BrowserMainRunnerImplInitializeLongTime"); |
| 65 | 75 |
| 66 // TODO(vadimt, yiyaoliu): Remove all tracked_objects references below once | 76 // TODO(vadimt, yiyaoliu): Remove all tracked_objects references below once |
| 67 // crbug.com/453640 is fixed. | 77 // crbug.com/453640 is fixed. |
| 68 tracked_objects::ThreadData::InitializeThreadContext(kMainThreadName); | 78 tracked_objects::ThreadData::InitializeThreadContext(kMainThreadName); |
| 69 base::trace_event::AllocationContextTracker::SetCurrentThreadName( | 79 base::trace_event::AllocationContextTracker::SetCurrentThreadName( |
| 70 kMainThreadName); | 80 kMainThreadName); |
| 71 TRACK_SCOPED_REGION( | 81 TRACK_SCOPED_REGION( |
| 72 "Startup", "BrowserMainRunnerImpl::Initialize"); | 82 "Startup", "BrowserMainRunnerImpl::Initialize"); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring | 227 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring |
| 218 // proper shutdown for content_browsertests. Shutdown() is not used by | 228 // proper shutdown for content_browsertests. Shutdown() is not used by |
| 219 // the actual browser. | 229 // the actual browser. |
| 220 if (base::MessageLoop::current()->is_running()) | 230 if (base::MessageLoop::current()->is_running()) |
| 221 base::MessageLoop::current()->QuitNow(); | 231 base::MessageLoop::current()->QuitNow(); |
| 222 #endif | 232 #endif |
| 223 main_loop_.reset(NULL); | 233 main_loop_.reset(NULL); |
| 224 | 234 |
| 225 notification_service_.reset(NULL); | 235 notification_service_.reset(NULL); |
| 226 | 236 |
| 237 // Dump all the persistent metrics to a file for upload during the next |
| 238 // run of the browser. Get() will return null if the allocator is not |
| 239 // enabled and so skip writing the data. |
| 240 base::GlobalHistogramAllocator* allocator = |
| 241 base::GlobalHistogramAllocator::Get(); |
| 242 if (allocator) |
| 243 allocator->WriteToPersistentLocation(); |
| 244 |
| 227 is_shutdown_ = true; | 245 is_shutdown_ = true; |
| 228 } | 246 } |
| 229 } | 247 } |
| 230 | 248 |
| 231 protected: | 249 protected: |
| 232 // True if we have started to initialize the runner. | 250 // True if we have started to initialize the runner. |
| 233 bool initialization_started_; | 251 bool initialization_started_; |
| 234 | 252 |
| 235 // True if the runner has been shut down. | 253 // True if the runner has been shut down. |
| 236 bool is_shutdown_; | 254 bool is_shutdown_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 249 BrowserMainRunner* BrowserMainRunner::Create() { | 267 BrowserMainRunner* BrowserMainRunner::Create() { |
| 250 return new BrowserMainRunnerImpl(); | 268 return new BrowserMainRunnerImpl(); |
| 251 } | 269 } |
| 252 | 270 |
| 253 // static | 271 // static |
| 254 bool BrowserMainRunner::ExitedMainMessageLoop() { | 272 bool BrowserMainRunner::ExitedMainMessageLoop() { |
| 255 return g_exited_main_message_loop; | 273 return g_exited_main_message_loop; |
| 256 } | 274 } |
| 257 | 275 |
| 258 } // namespace content | 276 } // namespace content |
| OLD | NEW |