| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| 6 #define CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 6 #define CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/observer_list_threadsafe.h" | 10 #include "base/observer_list_threadsafe.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "content/browser/renderer_host/media/media_observer.h" | 12 #include "content/browser/renderer_host/media/media_observer.h" |
| 13 | 13 |
| 14 class MediaInternalsObserver; | 14 class MediaInternalsObserver; |
| 15 | 15 |
| 16 // This class stores information about currently active media. | 16 // This class stores information about currently active media. |
| 17 class MediaInternals : public MediaObserver { | 17 class MediaInternals : public MediaObserver { |
| 18 public: | 18 public: |
| 19 virtual ~MediaInternals(); | 19 virtual ~MediaInternals(); |
| 20 | 20 |
| 21 // MediaObserver implementation. These are called from the IO thread: | 21 // MediaObserver implementation. These are called from the IO thread: |
| 22 virtual void OnDeleteAudioStream(void* host, int32 render_view, | 22 virtual void OnDeleteAudioStream(void* host, int stream_id); |
| 23 int stream_id); | 23 virtual void OnSetAudioStreamPlaying(void* host, int stream_id, bool playing); |
| 24 virtual void OnSetAudioStreamPlaying(void* host, int32 render_view, | 24 virtual void OnSetAudioStreamStatus(void* host, int stream_id, |
| 25 int stream_id, bool playing); | 25 const std::string& status); |
| 26 virtual void OnSetAudioStreamStatus(void* host, int32 render_view, | 26 virtual void OnSetAudioStreamVolume(void* host, int stream_id, double volume); |
| 27 int stream_id, const std::string& status); | |
| 28 virtual void OnSetAudioStreamVolume(void* host, int32 render_view, | |
| 29 int stream_id, double volume); | |
| 30 | 27 |
| 31 // Methods for observers. Called from the observer's own thread: | 28 // Methods for observers. Called from the observer's own thread: |
| 32 // UIs should add themselves on construction and remove themselves | 29 // UIs should add themselves on construction and remove themselves |
| 33 // on destruction. | 30 // on destruction. |
| 34 void AddUI(MediaInternalsObserver* ui); | 31 void AddUI(MediaInternalsObserver* ui); |
| 35 void RemoveUI(MediaInternalsObserver* ui); | 32 void RemoveUI(MediaInternalsObserver* ui); |
| 36 void SendEverything(); | 33 void SendEverything(); |
| 37 | 34 |
| 38 private: | 35 private: |
| 39 friend class IOThread; | 36 friend class IOThread; |
| 40 friend class MediaInternalsTest; | 37 friend class MediaInternalsTest; |
| 41 | 38 |
| 42 MediaInternals(); | 39 MediaInternals(); |
| 43 | 40 |
| 44 // Sets |property| of an audio stream to |value| and notifies observers. | 41 // Sets |property| of an audio stream to |value| and notifies observers. |
| 45 // (host, render_view, stream_id) is a unique id for the audio stream. | 42 // (host, stream_id) is a unique id for the audio stream. |
| 46 // |host| will never be dereferenced. | 43 // |host| will never be dereferenced. |
| 47 void UpdateAudioStream(void* host, int32 render_view, int stream_id, | 44 void UpdateAudioStream(void* host, int stream_id, |
| 48 const std::string& property, Value* value); | 45 const std::string& property, Value* value); |
| 49 | 46 |
| 50 // Removes |item| from |data_|. | 47 // Removes |item| from |data_|. |
| 51 void DeleteItem(const std::string& item); | 48 void DeleteItem(const std::string& item); |
| 52 | 49 |
| 53 // Sets data_.id.property = value and notifies attached UIs using update_fn. | 50 // Sets data_.id.property = value and notifies attached UIs using update_fn. |
| 54 // id may be any depth, e.g. "video.decoders.1.2.3" | 51 // id may be any depth, e.g. "video.decoders.1.2.3" |
| 55 void UpdateItem(const std::string& update_fn, const std::string& id, | 52 void UpdateItem(const std::string& update_fn, const std::string& id, |
| 56 const std::string& property, Value* value); | 53 const std::string& property, Value* value); |
| 57 | 54 |
| 58 // Calls javascript |function|(|value|) on each attached UI. | 55 // Calls javascript |function|(|value|) on each attached UI. |
| 59 void SendUpdate(const std::string& function, Value* value); | 56 void SendUpdate(const std::string& function, Value* value); |
| 60 | 57 |
| 61 static MediaInternals* instance_; | 58 static MediaInternals* instance_; |
| 62 DictionaryValue data_; | 59 DictionaryValue data_; |
| 63 scoped_refptr<ObserverListThreadSafe<MediaInternalsObserver> > observers_; | 60 scoped_refptr<ObserverListThreadSafe<MediaInternalsObserver> > observers_; |
| 64 | 61 |
| 65 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 62 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
| 66 }; | 63 }; |
| 67 | 64 |
| 68 #endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 65 #endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| OLD | NEW |