| 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 CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 public: | 30 public: |
| 31 static MediaInternals* GetInstance(); | 31 static MediaInternals* GetInstance(); |
| 32 | 32 |
| 33 virtual ~MediaInternals(); | 33 virtual ~MediaInternals(); |
| 34 | 34 |
| 35 // Called when a MediaEvent occurs. | 35 // Called when a MediaEvent occurs. |
| 36 void OnMediaEvents(int render_process_id, | 36 void OnMediaEvents(int render_process_id, |
| 37 const std::vector<media::MediaLogEvent>& events); | 37 const std::vector<media::MediaLogEvent>& events); |
| 38 | 38 |
| 39 // Called with the update string. | 39 // Called with the update string. |
| 40 typedef base::Callback<void(const string16&)> UpdateCallback; | 40 typedef base::Callback<void(const base::string16&)> UpdateCallback; |
| 41 | 41 |
| 42 // Add/remove update callbacks (see above). Must be called on the IO thread. | 42 // Add/remove update callbacks (see above). Must be called on the IO thread. |
| 43 void AddUpdateCallback(const UpdateCallback& callback); | 43 void AddUpdateCallback(const UpdateCallback& callback); |
| 44 void RemoveUpdateCallback(const UpdateCallback& callback); | 44 void RemoveUpdateCallback(const UpdateCallback& callback); |
| 45 | 45 |
| 46 // Sends all cached data to each registered UpdateCallback. | 46 // Sends all cached data to each registered UpdateCallback. |
| 47 void SendEverything(); | 47 void SendEverything(); |
| 48 | 48 |
| 49 // AudioLogFactory implementation. Safe to call from any thread. | 49 // AudioLogFactory implementation. Safe to call from any thread. |
| 50 virtual scoped_ptr<media::AudioLog> CreateAudioLog( | 50 virtual scoped_ptr<media::AudioLog> CreateAudioLog( |
| 51 AudioComponent component) OVERRIDE; | 51 AudioComponent component) OVERRIDE; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 friend class AudioLogImpl; | 54 friend class AudioLogImpl; |
| 55 friend class MediaInternalsTest; | 55 friend class MediaInternalsTest; |
| 56 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; | 56 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; |
| 57 | 57 |
| 58 MediaInternals(); | 58 MediaInternals(); |
| 59 | 59 |
| 60 // Sends |update| to each registered UpdateCallback. Safe to call from any | 60 // Sends |update| to each registered UpdateCallback. Safe to call from any |
| 61 // thread, but will forward to the IO thread. | 61 // thread, but will forward to the IO thread. |
| 62 void SendUpdate(const string16& update); | 62 void SendUpdate(const base::string16& update); |
| 63 | 63 |
| 64 // Caches |value| under |cache_key| so that future SendEverything() calls will | 64 // Caches |value| under |cache_key| so that future SendEverything() calls will |
| 65 // include the current data. Calls JavaScript |function|(|value|) for each | 65 // include the current data. Calls JavaScript |function|(|value|) for each |
| 66 // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges | 66 // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges |
| 67 // the cache entry after completion instead. | 67 // the cache entry after completion instead. |
| 68 void SendUpdateAndCache(const std::string& cache_key, | 68 void SendUpdateAndCache(const std::string& cache_key, |
| 69 const std::string& function, | 69 const std::string& function, |
| 70 const base::DictionaryValue* value); | 70 const base::DictionaryValue* value); |
| 71 void SendUpdateAndPurgeCache(const std::string& cache_key, | 71 void SendUpdateAndPurgeCache(const std::string& cache_key, |
| 72 const std::string& function, | 72 const std::string& function, |
| 73 const base::DictionaryValue* value); | 73 const base::DictionaryValue* value); |
| 74 // Must only be accessed on the IO thread. | 74 // Must only be accessed on the IO thread. |
| 75 std::vector<UpdateCallback> update_callbacks_; | 75 std::vector<UpdateCallback> update_callbacks_; |
| 76 | 76 |
| 77 // All variables below must be accessed under |lock_|. | 77 // All variables below must be accessed under |lock_|. |
| 78 base::Lock lock_; | 78 base::Lock lock_; |
| 79 base::DictionaryValue cached_data_; | 79 base::DictionaryValue cached_data_; |
| 80 int owner_ids_[AUDIO_COMPONENT_MAX]; | 80 int owner_ids_[AUDIO_COMPONENT_MAX]; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 82 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 } // namespace content | 85 } // namespace content |
| 86 | 86 |
| 87 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 87 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| OLD | NEW |