Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / media / media_internals.h
blobc0f144a5b8b4a080df5aea55ca7b320ac7362caf
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.
5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_
6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/lazy_instance.h"
14 #include "base/strings/string16.h"
15 #include "base/synchronization/lock.h"
16 #include "base/values.h"
17 #include "content/common/content_export.h"
18 #include "media/audio/audio_logging.h"
20 namespace media {
21 class AudioParameters;
22 struct MediaLogEvent;
25 namespace content {
27 // This class stores information about currently active media.
28 class CONTENT_EXPORT MediaInternals
29 : NON_EXPORTED_BASE(public media::AudioLogFactory) {
30 public:
31 static MediaInternals* GetInstance();
33 virtual ~MediaInternals();
35 // Called when a MediaEvent occurs.
36 void OnMediaEvents(int render_process_id,
37 const std::vector<media::MediaLogEvent>& events);
39 // Called with the update string.
40 typedef base::Callback<void(const base::string16&)> UpdateCallback;
42 // Add/remove update callbacks (see above). Must be called on the IO thread.
43 void AddUpdateCallback(const UpdateCallback& callback);
44 void RemoveUpdateCallback(const UpdateCallback& callback);
46 // Sends all cached data to each registered UpdateCallback.
47 void SendEverything();
49 // AudioLogFactory implementation. Safe to call from any thread.
50 virtual scoped_ptr<media::AudioLog> CreateAudioLog(
51 AudioComponent component) OVERRIDE;
53 private:
54 friend class AudioLogImpl;
55 friend class MediaInternalsTest;
56 friend struct base::DefaultLazyInstanceTraits<MediaInternals>;
58 MediaInternals();
60 // Sends |update| to each registered UpdateCallback. Safe to call from any
61 // thread, but will forward to the IO thread.
62 void SendUpdate(const base::string16& update);
64 // Caches |value| under |cache_key| so that future SendEverything() calls will
65 // include the current data. Calls JavaScript |function|(|value|) for each
66 // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges
67 // the cache entry after completion instead.
68 void SendUpdateAndCache(const std::string& cache_key,
69 const std::string& function,
70 const base::DictionaryValue* value);
71 void SendUpdateAndPurgeCache(const std::string& cache_key,
72 const std::string& function,
73 const base::DictionaryValue* value);
74 // Must only be accessed on the IO thread.
75 std::vector<UpdateCallback> update_callbacks_;
77 // All variables below must be accessed under |lock_|.
78 base::Lock lock_;
79 base::DictionaryValue cached_data_;
80 int owner_ids_[AUDIO_COMPONENT_MAX];
82 DISALLOW_COPY_AND_ASSIGN(MediaInternals);
85 } // namespace content
87 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_