OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ | 5 #ifndef CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ |
6 #define CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ | 6 #define CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sequenced_task_runner_helpers.h" | 10 #include "base/sequenced_task_runner_helpers.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // CastMediaShlib::Initialize/Finalize through this interface. | 25 // CastMediaShlib::Initialize/Finalize through this interface. |
26 // Threading model and lifetime: | 26 // Threading model and lifetime: |
27 // * This class interacts on both UI and media threads (task runners required | 27 // * This class interacts on both UI and media threads (task runners required |
28 // by ctor to perform thread hopping and checks). See function-level comments | 28 // by ctor to perform thread hopping and checks). See function-level comments |
29 // on which thread to use for which operations. | 29 // on which thread to use for which operations. |
30 // * The application should instantiate a single MediaResourceTracker instance. | 30 // * The application should instantiate a single MediaResourceTracker instance. |
31 // Destruction should be performed by calling FinalizeAndDestroy from the UI | 31 // Destruction should be performed by calling FinalizeAndDestroy from the UI |
32 // thread. | 32 // thread. |
33 class MediaResourceTracker { | 33 class MediaResourceTracker { |
34 public: | 34 public: |
35 // Helper class to manage media resource usage count. | |
36 // Create an instance of this class when a media resource is created. | |
37 // Delete the instance *after* the media resource is deleted. | |
38 // This class is not thread-safe. It must be created and deleted on | |
39 // |MediaResourceTracker::media_task_runner_|. | |
40 class ScopedUsage { | |
41 public: | |
42 ScopedUsage(MediaResourceTracker* tracker); | |
43 ~ScopedUsage(); | |
44 | |
45 private: | |
46 MediaResourceTracker* tracker_; | |
halliwell
2016/09/15 20:54:07
nit: should DISALLOW_COPY_AND_ASSIGN
alokp
2016/09/15 21:01:48
Done.
| |
47 }; | |
48 | |
35 MediaResourceTracker( | 49 MediaResourceTracker( |
36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 50 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
37 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner); | 51 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner); |
38 | 52 |
39 // Media resource acquire implementation. Must call on ui thread; runs | 53 // Media resource acquire implementation. Must call on ui thread; runs |
40 // CastMediaShlib::Initialize on media thread. Safe to call even if media lib | 54 // CastMediaShlib::Initialize on media thread. Safe to call even if media lib |
41 // already initialized. | 55 // already initialized. |
42 void InitializeMediaLib(); | 56 void InitializeMediaLib(); |
43 | 57 |
44 // Media resource release implementation: | 58 // Media resource release implementation: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 100 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
87 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 101 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
88 | 102 |
89 DISALLOW_COPY_AND_ASSIGN(MediaResourceTracker); | 103 DISALLOW_COPY_AND_ASSIGN(MediaResourceTracker); |
90 }; | 104 }; |
91 | 105 |
92 } // namespace media | 106 } // namespace media |
93 } // namespace chromecast | 107 } // namespace chromecast |
94 | 108 |
95 #endif // CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ | 109 #endif // CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ |
OLD | NEW |