| Index: content/browser/media/media_internals.h
|
| diff --git a/content/browser/media/media_internals.h b/content/browser/media/media_internals.h
|
| index 24b314ef321c7a577117111ccd83ab4ee3684523..8a179e0197b90b14abfc0d9a688d0c4e9b524df0 100644
|
| --- a/content/browser/media/media_internals.h
|
| +++ b/content/browser/media/media_internals.h
|
| @@ -8,12 +8,14 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| -#include "base/memory/ref_counted.h"
|
| -#include "base/memory/singleton.h"
|
| +#include "base/callback_forward.h"
|
| +#include "base/compiler_specific.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/strings/string16.h"
|
| +#include "base/synchronization/lock.h"
|
| #include "base/values.h"
|
| #include "content/common/content_export.h"
|
| -#include "content/public/common/media_stream_request.h"
|
| +#include "media/audio/audio_logging.h"
|
|
|
| namespace media {
|
| class AudioParameters;
|
| @@ -23,90 +25,60 @@ struct MediaLogEvent;
|
| namespace content {
|
|
|
| // This class stores information about currently active media.
|
| -// It's constructed on the UI thread but all of its methods are called on the IO
|
| -// thread.
|
| -class CONTENT_EXPORT MediaInternals {
|
| +class CONTENT_EXPORT MediaInternals
|
| + : NON_EXPORTED_BASE(public media::AudioLogFactory) {
|
| public:
|
| - virtual ~MediaInternals();
|
| -
|
| static MediaInternals* GetInstance();
|
|
|
| - // The following methods are virtual for gmock.
|
| -
|
| - // Called when an audio stream is deleted.
|
| - virtual void OnDeleteAudioStream(void* host, int stream_id);
|
| -
|
| - // Called when an audio stream is set to playing or paused.
|
| - virtual void OnSetAudioStreamPlaying(void* host, int stream_id, bool playing);
|
| -
|
| - // Called when an audio stream is created with the parameters that
|
| - // it attempts to use to make the stream.
|
| - virtual void OnAudioStreamCreated(void* host,
|
| - int stream_id,
|
| - const media::AudioParameters& params,
|
| - const std::string& input_device_id);
|
| -
|
| - // Called when the status of an audio stream is set to "created", "closed", or
|
| - // "error".
|
| - virtual void OnSetAudioStreamStatus(void* host, int stream_id,
|
| - const std::string& status);
|
| -
|
| - // Called when the volume of an audio stream is set.
|
| - virtual void OnSetAudioStreamVolume(void* host, int stream_id,
|
| - double volume);
|
| + virtual ~MediaInternals();
|
|
|
| // Called when a MediaEvent occurs.
|
| - virtual void OnMediaEvents(int render_process_id,
|
| - const std::vector<media::MediaLogEvent>& events);
|
| + void OnMediaEvents(int render_process_id,
|
| + const std::vector<media::MediaLogEvent>& events);
|
|
|
| // Called with the update string.
|
| typedef base::Callback<void(const string16&)> UpdateCallback;
|
|
|
| - // Add/remove update callbacks (see above).
|
| + // Add/remove update callbacks (see above). Must be called on the IO thread.
|
| void AddUpdateCallback(const UpdateCallback& callback);
|
| void RemoveUpdateCallback(const UpdateCallback& callback);
|
| +
|
| + // Sends all cached data to each registered UpdateCallback.
|
| void SendEverything();
|
|
|
| + // AudioLogFactory implementation. Safe to call from any thread.
|
| + virtual scoped_ptr<media::AudioLog> CreateAudioLog(
|
| + AudioComponent component) OVERRIDE;
|
| +
|
| private:
|
| - friend class MockMediaInternals;
|
| + friend class AudioLogImpl;
|
| friend class MediaInternalsTest;
|
| - friend struct DefaultSingletonTraits<MediaInternals>;
|
| + friend struct base::DefaultLazyInstanceTraits<MediaInternals>;
|
|
|
| MediaInternals();
|
|
|
| - // Sets |property| of an audio stream to |value| and notifies observers.
|
| - // (host, stream_id) is a unique id for the audio stream.
|
| - // |host| will never be dereferenced.
|
| - void UpdateAudioStream(void* host, int stream_id,
|
| - const std::string& property, base::Value* value);
|
| -
|
| - // See UpdateAudioStream. The difference is that StoreAudioStream does not
|
| - // immediately send the data to the client, instead it waits until
|
| - // SendEverything is called.
|
| - void StoreAudioStream(void* host,
|
| - int stream_id,
|
| - const std::string& property,
|
| - base::Value* value);
|
| -
|
| - // Removes |item| from |data_|.
|
| - void DeleteItem(const std::string& item);
|
| -
|
| - base::DictionaryValue* StoreItem(const std::string& id,
|
| - const std::string& property,
|
| - base::Value* value);
|
| -
|
| - // Sets data_.id.property = value and notifies attached UIs using update_fn.
|
| - // id may be any depth, e.g. "video.decoders.1.2.3"
|
| - void UpdateItem(const std::string& update_fn, const std::string& id,
|
| - const std::string& property, base::Value* value);
|
| -
|
| - // Calls javascript |function|(|value|) on each attached UI.
|
| - void SendUpdate(const std::string& function, base::Value* value);
|
| -
|
| - base::DictionaryValue data_;
|
| -
|
| + // Sends |update| to each registered UpdateCallback. Safe to call from any
|
| + // thread, but will forward to the IO thread.
|
| + void SendUpdate(const string16& update);
|
| +
|
| + // Caches |value| under |cache_key| so that future SendEverything() calls will
|
| + // include the current data. Calls JavaScript |function|(|value|) for each
|
| + // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges
|
| + // the cache entry after completion instead.
|
| + void SendUpdateAndCache(const std::string& cache_key,
|
| + const std::string& function,
|
| + const base::DictionaryValue* value);
|
| + void SendUpdateAndPurgeCache(const std::string& cache_key,
|
| + const std::string& function,
|
| + const base::DictionaryValue* value);
|
| + // Must only be accessed on the IO thread.
|
| std::vector<UpdateCallback> update_callbacks_;
|
|
|
| + // All variables below must be accessed under |lock_|.
|
| + base::Lock lock_;
|
| + base::DictionaryValue cached_data_;
|
| + int owner_ids_[AUDIO_COMPONENT_MAX];
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(MediaInternals);
|
| };
|
|
|
|
|