OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This is a wrapper class to help ref-counting a protobuf message. | 5 // This is a wrapper class to help ref-counting a protobuf message. |
6 // This file should only be inclued on host_message_dispatcher.cc and | 6 // This file should only be inclued on host_message_dispatcher.cc and |
7 // client_message_dispatche.cc. | 7 // client_message_dispatche.cc. |
8 | 8 |
9 // A single protobuf can contain multiple messages that will be handled by | 9 // A single protobuf can contain multiple messages that will be handled by |
10 // different message handlers. We use this wrapper to ensure that the | 10 // different message handlers. We use this wrapper to ensure that the |
11 // protobuf is only deleted after all the handlers have finished executing. | 11 // done_task is only called after all the handlers have finished executing. |
12 | 12 |
13 #ifndef REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | 13 #ifndef REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ |
14 #define REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | 14 #define REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ |
15 | 15 |
16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
17 #include "base/task.h" | 17 #include "base/task.h" |
18 #include "base/scoped_ptr.h" | |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 namespace protocol { | 21 namespace protocol { |
21 | 22 |
22 template <typename T> | 23 class RefCountedTask : public base::RefCounted<RefCountedTask> { |
awong
2011/01/19 02:12:48
I'm not sure I completely agree with having this c
Sergey Ulanov
2011/01/19 20:07:00
ScopedRunnableMethodFactory can't be used here bec
| |
23 class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > { | |
24 public: | 24 public: |
25 RefCountedMessage(T* message) : message_(message) { } | 25 RefCountedTask(Task* task); |
26 | |
27 T* message() { return message_.get(); } | |
28 | 26 |
29 private: | 27 private: |
30 scoped_ptr<T> message_; | 28 friend class base::RefCounted<RefCountedTask>; |
29 | |
30 virtual ~RefCountedTask(); | |
31 | |
32 scoped_ptr<Task> task_; | |
31 }; | 33 }; |
32 | 34 |
33 // Dummy methods to destroy messages. | 35 // Dummy methods to destroy messages. |
34 template <class T> | 36 template <class T> |
35 static void DeleteMessage(scoped_refptr<T> message) { } | 37 static void DeleteMessage(scoped_refptr<T> message) { } |
36 | 38 |
37 template <class T> | 39 template <class T> |
38 static Task* NewDeleteTask(scoped_refptr<T> message) { | 40 static Task* NewDeleteTask(scoped_refptr<T> message) { |
39 return NewRunnableFunction(&DeleteMessage<T>, message); | 41 return NewRunnableFunction(&DeleteMessage<T>, message); |
40 } | 42 } |
41 | 43 |
42 } // namespace protocol | 44 } // namespace protocol |
43 } // namespace remoting | 45 } // namespace remoting |
44 | 46 |
45 #endif // REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | 47 #endif // REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ |
OLD | NEW |