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 MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ | 5 #ifndef MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ |
6 #define MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ | 6 #define MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
16 | 16 |
17 class MessageLoop; | 17 class MessageLoop; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Thread; | 20 class Thread; |
21 } | 21 } |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 | 24 |
25 // Factory object that manages named MessageLoops. | 25 // Factory object that manages named MessageLoops. |
26 // | 26 // |
27 // TODO(scherkus): replace this with something simpler http://crbug.com/116873 | 27 // TODO(scherkus): replace this with something simpler http://crbug.com/116873 |
28 class MEDIA_EXPORT MessageLoopFactory { | 28 class MEDIA_EXPORT MessageLoopFactory { |
29 public: | 29 public: |
| 30 enum Type { |
| 31 kAudioDecoder, |
| 32 kVideoDecoder, |
| 33 kPipeline |
| 34 }; |
| 35 |
30 MessageLoopFactory(); | 36 MessageLoopFactory(); |
31 | 37 |
32 // Get the message loop associated with |name|. A new MessageLoop | 38 // Get the message loop proxy associated with |type|. A new MessageLoopProxy |
33 // is created if the factory doesn't have one associated with |name|. | 39 // is created if the factory doesn't have one associated with |type|. |
34 // | 40 scoped_refptr<base::MessageLoopProxy> GetMessageLoop(Type type); |
35 // |name| must not be an empty string. | |
36 MessageLoop* GetMessageLoop(const std::string& name); | |
37 | |
38 // Get the message loop proxy associated with |name|. A new MessageLoopProxy | |
39 // is created if the factory doesn't have one associated with |name|. | |
40 // | |
41 // |name| must not be an empty string. | |
42 scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy( | |
43 const std::string& name); | |
44 | 41 |
45 private: | 42 private: |
46 // Only allow scoped_ptr<> to delete factory. | 43 // Only allow scoped_ptr<> to delete factory. |
47 friend class scoped_ptr<MessageLoopFactory>; | 44 friend class scoped_ptr<MessageLoopFactory>; |
48 ~MessageLoopFactory(); | 45 ~MessageLoopFactory(); |
49 | 46 |
50 // Returns the thread associated with |name| creating a new thread if needed. | 47 // Returns the thread associated with |type| creating a new thread if needed. |
51 base::Thread* GetThread(const std::string& name); | 48 base::Thread* GetThread(Type type); |
52 | 49 |
53 // Lock used to serialize access for the following data members. | 50 // Lock used to serialize access for the following data members. |
54 base::Lock lock_; | 51 base::Lock lock_; |
55 | 52 |
56 // List of pairs of created threads and their names. We use a list to ensure | 53 // List of pairs of created threads and their types. We use a list to ensure |
57 // threads are stopped & deleted in reverse order of creation. | 54 // threads are stopped & deleted in reverse order of creation. |
58 typedef std::list<std::pair<std::string, base::Thread*> > ThreadList; | 55 typedef std::list<std::pair<Type, base::Thread*> > ThreadList; |
59 ThreadList threads_; | 56 ThreadList threads_; |
60 | 57 |
61 DISALLOW_COPY_AND_ASSIGN(MessageLoopFactory); | 58 DISALLOW_COPY_AND_ASSIGN(MessageLoopFactory); |
62 }; | 59 }; |
63 | 60 |
64 } // namespace media | 61 } // namespace media |
65 | 62 |
66 #endif // MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ | 63 #endif // MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ |
OLD | NEW |