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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ 6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/singleton.h" 13 #include "base/strings/string16.h" 14 #include "base/values.h" 15 #include "content/common/content_export.h" 16 #include "content/public/common/media_stream_request.h" 17 18 namespace media { 19 struct MediaLogEvent; 20 } 21 22 namespace content { 23 24 // This class stores information about currently active media. 25 // It's constructed on the UI thread but all of its methods are called on the IO 26 // thread. 27 class CONTENT_EXPORT MediaInternals { 28 public: 29 virtual ~MediaInternals(); 30 31 static MediaInternals* GetInstance(); 32 33 // The following methods are virtual for gmock. 34 35 // Called when an audio stream is deleted. 36 virtual void OnDeleteAudioStream(void* host, int stream_id); 37 38 // Called when an audio stream is set to playing or paused. 39 virtual void OnSetAudioStreamPlaying(void* host, int stream_id, 40 bool playing); 41 42 // Called when the status of an audio stream is set to "created", "closed", or 43 // "error". 44 virtual void OnSetAudioStreamStatus(void* host, int stream_id, 45 const std::string& status); 46 47 // Called when the volume of an audio stream is set. 48 virtual void OnSetAudioStreamVolume(void* host, int stream_id, 49 double volume); 50 51 // Called when a MediaEvent occurs. 52 virtual void OnMediaEvents(int render_process_id, 53 const std::vector<media::MediaLogEvent>& events); 54 55 // Called with the update string. 56 typedef base::Callback<void(const string16&)> UpdateCallback; 57 58 // Add/remove update callbacks (see above). 59 void AddUpdateCallback(const UpdateCallback& callback); 60 void RemoveUpdateCallback(const UpdateCallback& callback); 61 void SendEverything(); 62 63 private: 64 friend class MockMediaInternals; 65 friend class MediaInternalsTest; 66 friend struct DefaultSingletonTraits<MediaInternals>; 67 68 MediaInternals(); 69 70 // Sets |property| of an audio stream to |value| and notifies observers. 71 // (host, stream_id) is a unique id for the audio stream. 72 // |host| will never be dereferenced. 73 void UpdateAudioStream(void* host, int stream_id, 74 const std::string& property, base::Value* value); 75 76 // Removes |item| from |data_|. 77 void DeleteItem(const std::string& item); 78 79 // Sets data_.id.property = value and notifies attached UIs using update_fn. 80 // id may be any depth, e.g. "video.decoders.1.2.3" 81 void UpdateItem(const std::string& update_fn, const std::string& id, 82 const std::string& property, base::Value* value); 83 84 // Calls javascript |function|(|value|) on each attached UI. 85 void SendUpdate(const std::string& function, base::Value* value); 86 87 base::DictionaryValue data_; 88 89 std::vector<UpdateCallback> update_callbacks_; 90 91 DISALLOW_COPY_AND_ASSIGN(MediaInternals); 92 }; 93 94 } // namespace content 95 96 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ 97