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 NET_DNS_SERIAL_WORKER_H_ | 5 #ifndef NET_DNS_SERIAL_WORKER_H_ |
6 #define NET_DNS_SERIAL_WORKER_H_ | 6 #define NET_DNS_SERIAL_WORKER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
13 | 13 |
14 // Forward declaration | 14 // Forward declaration |
15 namespace base { | 15 namespace base { |
16 class MessageLoopProxy; | 16 class SingleThreadTaskRunner; |
17 } | 17 } |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 // SerialWorker executes a job on WorkerPool serially -- **once at a time**. | 21 // SerialWorker executes a job on WorkerPool serially -- **once at a time**. |
22 // On |WorkNow|, a call to |DoWork| is scheduled on the WorkerPool. Once it | 22 // On |WorkNow|, a call to |DoWork| is scheduled on the WorkerPool. Once it |
23 // completes, |OnWorkFinished| is called on the origin thread. | 23 // completes, |OnWorkFinished| is called on the origin thread. |
24 // If |WorkNow| is called (1 or more times) while |DoWork| is already under way, | 24 // If |WorkNow| is called (1 or more times) while |DoWork| is already under way, |
25 // |DoWork| will be called once: after current |DoWork| completes, before a | 25 // |DoWork| will be called once: after current |DoWork| completes, before a |
26 // call to |OnWorkFinished|. | 26 // call to |OnWorkFinished|. |
(...skipping 27 matching lines...) Expand all Loading... | |
54 friend class base::RefCountedThreadSafe<SerialWorker>; | 54 friend class base::RefCountedThreadSafe<SerialWorker>; |
55 // protected to allow sub-classing, but prevent deleting | 55 // protected to allow sub-classing, but prevent deleting |
56 virtual ~SerialWorker(); | 56 virtual ~SerialWorker(); |
57 | 57 |
58 // Executed on WorkerPool, at most once at a time. | 58 // Executed on WorkerPool, at most once at a time. |
59 virtual void DoWork() = 0; | 59 virtual void DoWork() = 0; |
60 | 60 |
61 // Executed on origin thread after |DoRead| completes. | 61 // Executed on origin thread after |DoRead| completes. |
62 virtual void OnWorkFinished() = 0; | 62 virtual void OnWorkFinished() = 0; |
63 | 63 |
64 base::MessageLoopProxy* loop() { return message_loop_.get(); } | 64 base::SingleThreadTaskRunner* loop() { return task_runner_.get(); } |
asanka
2015/05/14 18:38:40
Is this used? We should get rid of this if it isn'
anujsharma
2015/05/20 13:13:16
Done..No reference found
| |
65 | 65 |
66 private: | 66 private: |
67 enum State { | 67 enum State { |
68 CANCELLED = -1, | 68 CANCELLED = -1, |
69 IDLE = 0, | 69 IDLE = 0, |
70 WORKING, // |DoWorkJob| posted on WorkerPool, until |OnWorkJobFinished| | 70 WORKING, // |DoWorkJob| posted on WorkerPool, until |OnWorkJobFinished| |
71 PENDING, // |WorkNow| while WORKING, must re-do work | 71 PENDING, // |WorkNow| while WORKING, must re-do work |
72 WAITING, // WorkerPool is busy, |RetryWork| is posted | 72 WAITING, // WorkerPool is busy, |RetryWork| is posted |
73 }; | 73 }; |
74 | 74 |
75 // Called on the worker thread, executes |DoWork| and notifies the origin | 75 // Called on the worker thread, executes |DoWork| and notifies the origin |
76 // thread. | 76 // thread. |
77 void DoWorkJob(); | 77 void DoWorkJob(); |
78 | 78 |
79 // Called on the the origin thread after |DoWork| completes. | 79 // Called on the the origin thread after |DoWork| completes. |
80 void OnWorkJobFinished(); | 80 void OnWorkJobFinished(); |
81 | 81 |
82 // Posted to message loop in case WorkerPool is busy. (state == WAITING) | 82 // Posted to message loop in case WorkerPool is busy. (state == WAITING) |
83 void RetryWork(); | 83 void RetryWork(); |
84 | 84 |
85 // Message loop for the thread of origin. | 85 // Task runner for the thread of origin. |
86 scoped_refptr<base::MessageLoopProxy> message_loop_; | 86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
87 | 87 |
88 State state_; | 88 State state_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(SerialWorker); | 90 DISALLOW_COPY_AND_ASSIGN(SerialWorker); |
91 }; | 91 }; |
92 | 92 |
93 } // namespace net | 93 } // namespace net |
94 | 94 |
95 #endif // NET_DNS_SERIAL_WORKER_H_ | 95 #endif // NET_DNS_SERIAL_WORKER_H_ |
96 | 96 |
OLD | NEW |