OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
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 | |
7 // client_message_dispatche.cc. | |
8 | |
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 | |
11 // protobuf is only deleted after all the handlers have finished executing. | |
12 | |
13 #ifndef REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | |
14 #define REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | |
15 | |
16 #include "base/ref_counted.h" | |
17 #include "base/task.h" | |
18 | |
19 namespace remoting { | |
20 namespace protocol { | |
21 | |
22 template <typename T> | |
23 class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > { | |
24 public: | |
25 RefCountedMessage(T* message) : message_(message) { } | |
26 | |
27 T* message() { return message_.get(); } | |
28 | |
29 private: | |
30 scoped_ptr<T> message_; | |
31 }; | |
32 | |
33 // Dummy methods to destroy messages. | |
34 template <class T> | |
35 static void DeleteMessage(scoped_refptr<T> message) { } | |
36 | |
37 template <class T> | |
38 static Task* NewDeleteTask(scoped_refptr<T> message) { | |
39 return NewRunnableFunction(&DeleteMessage<T>, message); | |
40 } | |
41 | |
42 } // namespace protocol | |
43 } // namespace remoting | |
44 | |
45 #endif // REMOTING_PROTOCOL_REF_COUNTED_MESSAGE_H_ | |
OLD | NEW |