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

Unified Diff: media/audio/android/audio_manager_android.cc

Issue 2077983003: Intiialize AudioManager and related class lazily (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: defer StartHangMonitor() on all platforms Created 4 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/android/audio_manager_android.cc
diff --git a/media/audio/android/audio_manager_android.cc b/media/audio/android/audio_manager_android.cc
index a7ec08d69c4d30e60b56716a450f43ae8c1e6b86..02881688bc672e5a5807208d1f23ea6811203e0e 100644
--- a/media/audio/android/audio_manager_android.cc
+++ b/media/audio/android/audio_manager_android.cc
@@ -63,30 +63,39 @@ AudioManagerAndroid::AudioManagerAndroid(
audio_log_factory),
communication_mode_is_on_(false),
output_volume_override_set_(false),
- output_volume_override_(0) {
+ output_volume_override_(0),
+ initialized_(false) {
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
-
- // WARNING: This is executed on the UI loop, do not add any code here which
- // loads libraries or attempts to call out into the OS. Instead add such code
- // to the InitializeOnAudioThread() method below.
-
- // Task must be posted last to avoid races from handing out "this" to the
- // audio thread.
- GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
- &AudioManagerAndroid::InitializeOnAudioThread,
- base::Unretained(this)));
}
AudioManagerAndroid::~AudioManagerAndroid() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
Shutdown();
+ if (j_audio_manager_.is_null())
+ return;
DVLOG(2) << "Destroying Java part of the audio manager";
Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(),
j_audio_manager_.obj());
j_audio_manager_.Reset();
}
+void AudioManagerAndroid::InitializeIfNeeded() {
+ if (initialized_)
+ return;
+
+ // WARNING: This is executed on the UI loop, do not add any code here which
+ // loads libraries or attempts to call out into the OS. Instead add such code
+ // to the InitializeOnAudioThread() method below.
+
+ // Task must be posted last to avoid races from handing out "this" to the
+ // audio thread.
+ GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
+ &AudioManagerAndroid::InitializeOnAudioThread,
+ base::Unretained(this)));
+ initialized_ = true;
+}
+
bool AudioManagerAndroid::HasAudioOutputDevices() {
return true;
}

Powered by Google App Engine
This is Rietveld 408576698