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

Side by Side Diff: media/audio/sounds/sounds_manager.cc

Issue 2914593002: Replace deprecated base::NonThreadSafe in media/audio in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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/audio/sounds/sounds_manager.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/audio/sounds/sounds_manager.h" 5 #include "media/audio/sounds/sounds_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "media/audio/audio_manager.h" 11 #include "media/audio/audio_manager.h"
12 #include "media/audio/sounds/audio_stream_handler.h" 12 #include "media/audio/sounds/audio_stream_handler.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 namespace { 16 namespace {
17 17
18 SoundsManager* g_instance = NULL; 18 SoundsManager* g_instance = NULL;
19 bool g_initialized_for_testing = false; 19 bool g_initialized_for_testing = false;
20 20
21 // SoundsManagerImpl --------------------------------------------------- 21 // SoundsManagerImpl ---------------------------------------------------
22 22
23 class SoundsManagerImpl : public SoundsManager { 23 class SoundsManagerImpl : public SoundsManager {
24 public: 24 public:
25 SoundsManagerImpl() {} 25 SoundsManagerImpl() {}
26 ~SoundsManagerImpl() override { DCHECK(CalledOnValidThread()); } 26 ~SoundsManagerImpl() override {
27 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
28 }
27 29
28 // SoundsManager implementation: 30 // SoundsManager implementation:
29 bool Initialize(SoundKey key, const base::StringPiece& data) override; 31 bool Initialize(SoundKey key, const base::StringPiece& data) override;
30 bool Play(SoundKey key) override; 32 bool Play(SoundKey key) override;
31 bool Stop(SoundKey key) override; 33 bool Stop(SoundKey key) override;
32 base::TimeDelta GetDuration(SoundKey key) override; 34 base::TimeDelta GetDuration(SoundKey key) override;
33 35
34 private: 36 private:
35 AudioStreamHandler* GetHandler(SoundKey key); 37 AudioStreamHandler* GetHandler(SoundKey key);
36 38
(...skipping 18 matching lines...) Expand all
55 if (!handler->IsInitialized()) { 57 if (!handler->IsInitialized()) {
56 LOG(WARNING) << "Can't initialize AudioStreamHandler for key=" << key; 58 LOG(WARNING) << "Can't initialize AudioStreamHandler for key=" << key;
57 return false; 59 return false;
58 } 60 }
59 61
60 handlers_.push_back({key, std::move(handler)}); 62 handlers_.push_back({key, std::move(handler)});
61 return true; 63 return true;
62 } 64 }
63 65
64 bool SoundsManagerImpl::Play(SoundKey key) { 66 bool SoundsManagerImpl::Play(SoundKey key) {
65 DCHECK(CalledOnValidThread()); 67 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
66 AudioStreamHandler* handler = GetHandler(key); 68 AudioStreamHandler* handler = GetHandler(key);
67 return handler && handler->Play(); 69 return handler && handler->Play();
68 } 70 }
69 71
70 bool SoundsManagerImpl::Stop(SoundKey key) { 72 bool SoundsManagerImpl::Stop(SoundKey key) {
71 DCHECK(CalledOnValidThread()); 73 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
72 AudioStreamHandler* handler = GetHandler(key); 74 AudioStreamHandler* handler = GetHandler(key);
73 if (!handler) 75 if (!handler)
74 return false; 76 return false;
75 handler->Stop(); 77 handler->Stop();
76 return true; 78 return true;
77 } 79 }
78 80
79 base::TimeDelta SoundsManagerImpl::GetDuration(SoundKey key) { 81 base::TimeDelta SoundsManagerImpl::GetDuration(SoundKey key) {
80 DCHECK(CalledOnValidThread()); 82 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
81 AudioStreamHandler* handler = GetHandler(key); 83 AudioStreamHandler* handler = GetHandler(key);
82 return !handler ? base::TimeDelta() : handler->duration(); 84 return !handler ? base::TimeDelta() : handler->duration();
83 } 85 }
84 86
85 AudioStreamHandler* SoundsManagerImpl::GetHandler(SoundKey key) { 87 AudioStreamHandler* SoundsManagerImpl::GetHandler(SoundKey key) {
86 for (auto& entry : handlers_) { 88 for (auto& entry : handlers_) {
87 if (entry.key == key) 89 if (entry.key == key)
88 return entry.handler.get(); 90 return entry.handler.get();
89 } 91 }
90 return nullptr; 92 return nullptr;
91 } 93 }
92 94
93 } // namespace 95 } // namespace
94 96
95 SoundsManager::SoundsManager() {} 97 SoundsManager::SoundsManager() {}
96 98
97 SoundsManager::~SoundsManager() { DCHECK(CalledOnValidThread()); } 99 SoundsManager::~SoundsManager() {
100 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
101 }
98 102
99 // static 103 // static
100 void SoundsManager::Create() { 104 void SoundsManager::Create() {
101 CHECK(!g_instance || g_initialized_for_testing) 105 CHECK(!g_instance || g_initialized_for_testing)
102 << "SoundsManager::Create() is called twice"; 106 << "SoundsManager::Create() is called twice";
103 if (g_initialized_for_testing) 107 if (g_initialized_for_testing)
104 return; 108 return;
105 g_instance = new SoundsManagerImpl(); 109 g_instance = new SoundsManagerImpl();
106 } 110 }
107 111
(...skipping 13 matching lines...) Expand all
121 125
122 // static 126 // static
123 void SoundsManager::InitializeForTesting(SoundsManager* manager) { 127 void SoundsManager::InitializeForTesting(SoundsManager* manager) {
124 CHECK(!g_instance) << "SoundsManager is already initialized."; 128 CHECK(!g_instance) << "SoundsManager is already initialized.";
125 CHECK(manager); 129 CHECK(manager);
126 g_instance = manager; 130 g_instance = manager;
127 g_initialized_for_testing = true; 131 g_initialized_for_testing = true;
128 } 132 }
129 133
130 } // namespace media 134 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/sounds/sounds_manager.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698