| 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_; |
| 47 DISALLOW_COPY_AND_ASSIGN(ScopedUsage); |
| 48 }; |
| 49 |
| 35 MediaResourceTracker( | 50 MediaResourceTracker( |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner); | 52 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner); |
| 38 | 53 |
| 39 // Media resource acquire implementation. Must call on ui thread; runs | 54 // Media resource acquire implementation. Must call on ui thread; runs |
| 40 // CastMediaShlib::Initialize on media thread. Safe to call even if media lib | 55 // CastMediaShlib::Initialize on media thread. Safe to call even if media lib |
| 41 // already initialized. | 56 // already initialized. |
| 42 void InitializeMediaLib(); | 57 void InitializeMediaLib(); |
| 43 | 58 |
| 44 // Media resource release implementation: | 59 // 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_; | 101 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 87 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 102 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
| 88 | 103 |
| 89 DISALLOW_COPY_AND_ASSIGN(MediaResourceTracker); | 104 DISALLOW_COPY_AND_ASSIGN(MediaResourceTracker); |
| 90 }; | 105 }; |
| 91 | 106 |
| 92 } // namespace media | 107 } // namespace media |
| 93 } // namespace chromecast | 108 } // namespace chromecast |
| 94 | 109 |
| 95 #endif // CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ | 110 #endif // CHROMECAST_MEDIA_BASE_MEDIA_RESOURCE_TRACKER_H_ |
| OLD | NEW |