| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/base/android/media_service_throttler.h" | 5 #include "media/base/android/media_service_throttler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "base/time/default_tick_clock.h" | 10 #include "base/time/default_tick_clock.h" |
| 11 #include "media/base/android/media_server_crash_listener.h" | 11 #include "media/base/android/media_server_crash_listener.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 static base::LazyInstance<MediaServiceThrottler>::Leaky | |
| 18 g_media_service_throttler = LAZY_INSTANCE_INITIALIZER; | |
| 19 | |
| 20 // Period of inactivity after which we stop listening for MediaServer crashes. | 17 // Period of inactivity after which we stop listening for MediaServer crashes. |
| 21 // NOTE: Server crashes don't count as acticity. Only calls to | 18 // NOTE: Server crashes don't count as acticity. Only calls to |
| 22 // GetDelayForClientCreation() do. | 19 // GetDelayForClientCreation() do. |
| 23 constexpr base::TimeDelta kReleaseInactivityDelay = | 20 constexpr base::TimeDelta kReleaseInactivityDelay = |
| 24 base::TimeDelta::FromMinutes(1); | 21 base::TimeDelta::FromMinutes(1); |
| 25 | 22 |
| 26 // Elapsed time between crashes needed to completely reset the media server | 23 // Elapsed time between crashes needed to completely reset the media server |
| 27 // crash count. | 24 // crash count. |
| 28 constexpr base::TimeDelta kTimeUntilCrashReset = | 25 constexpr base::TimeDelta kTimeUntilCrashReset = |
| 29 base::TimeDelta::FromMinutes(1); | 26 base::TimeDelta::FromMinutes(1); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // | 74 // |
| 78 // NOTE: Since we use the floor function and a decay rate of 1 crash/minute when | 75 // NOTE: Since we use the floor function and a decay rate of 1 crash/minute when |
| 79 // calculating the effective # of crashes, a single crash per minute will result | 76 // calculating the effective # of crashes, a single crash per minute will result |
| 80 // in 0 effective crashes (since floor(1.0 - 'tiny decay') is 0). If we | 77 // in 0 effective crashes (since floor(1.0 - 'tiny decay') is 0). If we |
| 81 // experience slightly more than 1 crash per 60 seconds, the effective number of | 78 // experience slightly more than 1 crash per 60 seconds, the effective number of |
| 82 // crashes will go up as expected. | 79 // crashes will go up as expected. |
| 83 } | 80 } |
| 84 | 81 |
| 85 // static | 82 // static |
| 86 MediaServiceThrottler* MediaServiceThrottler::GetInstance() { | 83 MediaServiceThrottler* MediaServiceThrottler::GetInstance() { |
| 87 return g_media_service_throttler.Pointer(); | 84 static MediaServiceThrottler* instance = new MediaServiceThrottler(); |
| 85 return instance; |
| 88 } | 86 } |
| 89 | 87 |
| 90 MediaServiceThrottler::~MediaServiceThrottler() {} | 88 MediaServiceThrottler::~MediaServiceThrottler() {} |
| 91 | 89 |
| 92 MediaServiceThrottler::MediaServiceThrottler() | 90 MediaServiceThrottler::MediaServiceThrottler() |
| 93 : clock_(new base::DefaultTickClock()), | 91 : clock_(new base::DefaultTickClock()), |
| 94 current_crashes_(0), | 92 current_crashes_(0), |
| 95 crash_listener_task_runner_(base::ThreadTaskRunnerHandle::Get()) { | 93 crash_listener_task_runner_(base::ThreadTaskRunnerHandle::Get()) { |
| 96 // base::Unretained is safe because the MediaServiceThrottler is supposed to | 94 // base::Unretained is safe because the MediaServiceThrottler is supposed to |
| 97 // live until the process dies. | 95 // live until the process dies. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // Set the task runner so |crash_listener_| be deleted on the right thread. | 225 // Set the task runner so |crash_listener_| be deleted on the right thread. |
| 228 crash_listener_task_runner_ = crash_listener_task_runner; | 226 crash_listener_task_runner_ = crash_listener_task_runner; |
| 229 | 227 |
| 230 // Re-create the crash listener. | 228 // Re-create the crash listener. |
| 231 crash_listener_ = base::MakeUnique<MediaServerCrashListener>( | 229 crash_listener_ = base::MakeUnique<MediaServerCrashListener>( |
| 232 MediaServerCrashListener::OnMediaServerCrashCB(), | 230 MediaServerCrashListener::OnMediaServerCrashCB(), |
| 233 crash_listener_task_runner_); | 231 crash_listener_task_runner_); |
| 234 } | 232 } |
| 235 | 233 |
| 236 } // namespace media | 234 } // namespace media |
| OLD | NEW |