| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/singleton.h" |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "base/threading/non_thread_safe.h" | |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "content/public/browser/media_observer.h" | 13 #include "content/public/browser/media_observer.h" |
| 14 | 14 |
| 15 class MediaInternalsObserver; | 15 class MediaInternalsObserver; |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 struct MediaLogEvent; | 18 struct MediaLogEvent; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // This class stores information about currently active media. | 21 // This class stores information about currently active media. |
| 22 // All of its methods are called on the IO thread. | 22 // It's constructed on the UI thread but all of its methods are called on the IO |
| 23 class MediaInternals : public content::MediaObserver, | 23 // thread. |
| 24 public base::NonThreadSafe { | 24 class MediaInternals : public content::MediaObserver { |
| 25 public: | 25 public: |
| 26 virtual ~MediaInternals(); | 26 virtual ~MediaInternals(); |
| 27 | 27 |
| 28 static MediaInternals* GetInstance(); |
| 29 |
| 28 // Overridden from content::MediaObserver: | 30 // Overridden from content::MediaObserver: |
| 29 virtual void OnDeleteAudioStream(void* host, int stream_id) OVERRIDE; | 31 virtual void OnDeleteAudioStream(void* host, int stream_id) OVERRIDE; |
| 30 virtual void OnSetAudioStreamPlaying(void* host, | 32 virtual void OnSetAudioStreamPlaying(void* host, |
| 31 int stream_id, | 33 int stream_id, |
| 32 bool playing) OVERRIDE; | 34 bool playing) OVERRIDE; |
| 33 virtual void OnSetAudioStreamStatus(void* host, | 35 virtual void OnSetAudioStreamStatus(void* host, |
| 34 int stream_id, | 36 int stream_id, |
| 35 const std::string& status) OVERRIDE; | 37 const std::string& status) OVERRIDE; |
| 36 virtual void OnSetAudioStreamVolume(void* host, | 38 virtual void OnSetAudioStreamVolume(void* host, |
| 37 int stream_id, | 39 int stream_id, |
| 38 double volume) OVERRIDE; | 40 double volume) OVERRIDE; |
| 39 virtual void OnMediaEvent(int render_process_id, | 41 virtual void OnMediaEvent(int render_process_id, |
| 40 const media::MediaLogEvent& event) OVERRIDE; | 42 const media::MediaLogEvent& event) OVERRIDE; |
| 41 | 43 |
| 42 // Methods for observers. | 44 // Methods for observers. |
| 43 // Observers should add themselves on construction and remove themselves | 45 // Observers should add themselves on construction and remove themselves |
| 44 // on destruction. | 46 // on destruction. |
| 45 void AddObserver(MediaInternalsObserver* observer); | 47 void AddObserver(MediaInternalsObserver* observer); |
| 46 void RemoveObserver(MediaInternalsObserver* observer); | 48 void RemoveObserver(MediaInternalsObserver* observer); |
| 47 void SendEverything(); | 49 void SendEverything(); |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 friend class IOThread; | |
| 51 friend class MediaInternalsTest; | 52 friend class MediaInternalsTest; |
| 53 friend struct DefaultSingletonTraits<MediaInternals>; |
| 52 | 54 |
| 53 MediaInternals(); | 55 MediaInternals(); |
| 54 | 56 |
| 55 // Sets |property| of an audio stream to |value| and notifies observers. | 57 // Sets |property| of an audio stream to |value| and notifies observers. |
| 56 // (host, stream_id) is a unique id for the audio stream. | 58 // (host, stream_id) is a unique id for the audio stream. |
| 57 // |host| will never be dereferenced. | 59 // |host| will never be dereferenced. |
| 58 void UpdateAudioStream(void* host, int stream_id, | 60 void UpdateAudioStream(void* host, int stream_id, |
| 59 const std::string& property, Value* value); | 61 const std::string& property, Value* value); |
| 60 | 62 |
| 61 // Removes |item| from |data_|. | 63 // Removes |item| from |data_|. |
| 62 void DeleteItem(const std::string& item); | 64 void DeleteItem(const std::string& item); |
| 63 | 65 |
| 64 // Sets data_.id.property = value and notifies attached UIs using update_fn. | 66 // Sets data_.id.property = value and notifies attached UIs using update_fn. |
| 65 // id may be any depth, e.g. "video.decoders.1.2.3" | 67 // id may be any depth, e.g. "video.decoders.1.2.3" |
| 66 void UpdateItem(const std::string& update_fn, const std::string& id, | 68 void UpdateItem(const std::string& update_fn, const std::string& id, |
| 67 const std::string& property, Value* value); | 69 const std::string& property, Value* value); |
| 68 | 70 |
| 69 // Calls javascript |function|(|value|) on each attached UI. | 71 // Calls javascript |function|(|value|) on each attached UI. |
| 70 void SendUpdate(const std::string& function, Value* value); | 72 void SendUpdate(const std::string& function, Value* value); |
| 71 | 73 |
| 72 static MediaInternals* instance_; | 74 static MediaInternals* instance_; |
| 73 DictionaryValue data_; | 75 DictionaryValue data_; |
| 74 ObserverList<MediaInternalsObserver> observers_; | 76 ObserverList<MediaInternalsObserver> observers_; |
| 75 | 77 |
| 76 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 78 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 #endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 81 #endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| OLD | NEW |