Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: media/base/message_loop_factory.h

Issue 10855051: Use enum instead of string in MessageLoopFactory::GetMessageLoop* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update player_wtl Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 MessageLoopType {
scherkus (not reviewing) 2012/08/09 17:13:24 s/MessageLoop/Type/
xhwang 2012/08/10 01:04:28 Done.
31 AUDIO_DECODER,
scherkus (not reviewing) 2012/08/09 17:13:24 we've been using kCamelCase format for constants
xhwang 2012/08/10 01:04:28 Done.
32 VIDEO_DECODER,
33 PIPELINE
34 };
35
30 MessageLoopFactory(); 36 MessageLoopFactory();
31 37
32 // Get the message loop associated with |name|. A new MessageLoop 38 // Get the message loop associated with |type|. A new MessageLoop
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 MessageLoop* GetMessageLoop(MessageLoopType type);
scherkus (not reviewing) 2012/08/09 17:13:24 can we remove this method entirely and rename the
xhwang 2012/08/10 01:04:28 Done.
35 // |name| must not be an empty string.
36 MessageLoop* GetMessageLoop(const std::string& name);
37 41
38 // Get the message loop proxy associated with |name|. A new MessageLoopProxy 42 // Get the message loop proxy associated with |type|. A new MessageLoopProxy
39 // is created if the factory doesn't have one associated with |name|. 43 // is created if the factory doesn't have one associated with |type|.
40 //
41 // |name| must not be an empty string.
42 scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy( 44 scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy(
43 const std::string& name); 45 MessageLoopType type);
44 46
45 private: 47 private:
46 // Only allow scoped_ptr<> to delete factory. 48 // Only allow scoped_ptr<> to delete factory.
47 friend class scoped_ptr<MessageLoopFactory>; 49 friend class scoped_ptr<MessageLoopFactory>;
48 ~MessageLoopFactory(); 50 ~MessageLoopFactory();
49 51
50 // Returns the thread associated with |name| creating a new thread if needed. 52 // Returns the thread associated with |type| creating a new thread if needed.
51 base::Thread* GetThread(const std::string& name); 53 base::Thread* GetThread(MessageLoopType type);
52 54
53 // Lock used to serialize access for the following data members. 55 // Lock used to serialize access for the following data members.
54 base::Lock lock_; 56 base::Lock lock_;
55 57
56 // List of pairs of created threads and their names. We use a list to ensure 58 // 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. 59 // threads are stopped & deleted in reverse order of creation.
58 typedef std::list<std::pair<std::string, base::Thread*> > ThreadList; 60 typedef std::list<std::pair<MessageLoopType, base::Thread*> > ThreadList;
59 ThreadList threads_; 61 ThreadList threads_;
60 62
61 DISALLOW_COPY_AND_ASSIGN(MessageLoopFactory); 63 DISALLOW_COPY_AND_ASSIGN(MessageLoopFactory);
62 }; 64 };
63 65
64 } // namespace media 66 } // namespace media
65 67
66 #endif // MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_ 68 #endif // MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698