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 // ChromeThreadRelay provides a convenient way to bounce work to a specific | |
6 // ChromeThread and then return results back to the originating thread. | |
7 // | |
8 // EXAMPLE: | |
9 // | |
10 // class MyRelay : public ChromeThreadRelay { | |
11 // public: | |
12 // MyRelay(const Params& params) : params_(params) { | |
13 // } | |
14 // protected: | |
15 // virtual void RunWork() { | |
16 // results_ = DoWork(params_); | |
17 // } | |
18 // virtual void RunCallback() { | |
19 // ... use results_ on the originating thread ... | |
20 // } | |
21 // private: | |
22 // Params params_; | |
23 // Results_ results_; | |
24 // }; | |
25 | |
26 #ifndef CHROME_BROWSER_CHROME_THREAD_RELAY_H_ | |
27 #define CHROME_BROWSER_CHROME_THREAD_RELAY_H_ | |
28 | |
29 #include "base/ref_counted.h" | |
30 #include "chrome/browser/chrome_thread.h" | |
31 | |
32 class ChromeThreadRelay | |
33 : public base::RefCountedThreadSafe<ChromeThreadRelay> { | |
34 public: | |
35 ChromeThreadRelay(); | |
36 | |
37 void Start(ChromeThread::ID target_thread_id, | |
38 const tracked_objects::Location& from_here); | |
39 | |
40 protected: | |
41 friend class base::RefCountedThreadSafe<ChromeThreadRelay>; | |
42 virtual ~ChromeThreadRelay() {} | |
43 | |
44 // Called to perform work on the FILE thread. | |
45 virtual void RunWork() = 0; | |
46 | |
47 // Called to notify the callback on the origin thread. | |
48 virtual void RunCallback() = 0; | |
49 | |
50 private: | |
51 void ProcessOnTargetThread(); | |
52 ChromeThread::ID origin_thread_id_; | |
53 }; | |
54 | |
55 #endif // CHROME_BROWSER_CHROME_THREAD_RELAY_H_ | |
OLD | NEW |