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

Side by Side Diff: webrtc/base/messagehandler.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 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
« no previous file with comments | « webrtc/base/messagedigest_unittest.cc ('k') | webrtc/base/messagehandler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_MESSAGEHANDLER_H_ 11 #ifndef WEBRTC_BASE_MESSAGEHANDLER_H_
12 #define WEBRTC_BASE_MESSAGEHANDLER_H_ 12 #define WEBRTC_BASE_MESSAGEHANDLER_H_
13 13
14 #include <memory>
15 #include <utility>
16 14
17 #include "webrtc/base/constructormagic.h" 15 // This header is deprecated and is just left here temporarily during
18 16 // refactoring. See https://bugs.webrtc.org/7634 for more details.
19 namespace rtc { 17 #include "webrtc/rtc_base/messagehandler.h"
20
21 struct Message;
22
23 // Messages get dispatched to a MessageHandler
24
25 class MessageHandler {
26 public:
27 virtual ~MessageHandler();
28 virtual void OnMessage(Message* msg) = 0;
29
30 protected:
31 MessageHandler() {}
32
33 private:
34 RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandler);
35 };
36
37 // Helper class to facilitate executing a functor on a thread.
38 template <class ReturnT, class FunctorT>
39 class FunctorMessageHandler : public MessageHandler {
40 public:
41 explicit FunctorMessageHandler(const FunctorT& functor)
42 : functor_(functor) {}
43 virtual void OnMessage(Message* msg) {
44 result_ = functor_();
45 }
46 const ReturnT& result() const { return result_; }
47
48 // Returns moved result. Should not call result() or MoveResult() again
49 // after this.
50 ReturnT MoveResult() { return std::move(result_); }
51
52 private:
53 FunctorT functor_;
54 ReturnT result_;
55 };
56
57 // Specialization for ReturnT of void.
58 template <class FunctorT>
59 class FunctorMessageHandler<void, FunctorT> : public MessageHandler {
60 public:
61 explicit FunctorMessageHandler(const FunctorT& functor)
62 : functor_(functor) {}
63 virtual void OnMessage(Message* msg) {
64 functor_();
65 }
66 void result() const {}
67 void MoveResult() {}
68
69 private:
70 FunctorT functor_;
71 };
72
73 } // namespace rtc
74 18
75 #endif // WEBRTC_BASE_MESSAGEHANDLER_H_ 19 #endif // WEBRTC_BASE_MESSAGEHANDLER_H_
OLDNEW
« no previous file with comments | « webrtc/base/messagedigest_unittest.cc ('k') | webrtc/base/messagehandler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698