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

Side by Side Diff: media/base/android/media_service_throttler.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 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 | « media/base/android/media_service_throttler.h ('k') | media/base/key_systems.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 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
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
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
OLDNEW
« no previous file with comments | « media/base/android/media_service_throttler.h ('k') | media/base/key_systems.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698