OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | |
9 | |
10 namespace history { | 8 namespace history { |
11 | 9 |
12 class HistoryBackend; | 10 class HistoryBackend; |
13 class HistoryDatabase; | 11 class HistoryDatabase; |
14 | 12 |
15 // HistoryDBTask can be used to process arbitrary work on the history backend | 13 // HistoryDBTask can be used to process arbitrary work on the history backend |
16 // thread. HistoryDBTask is scheduled using HistoryService::ScheduleDBTask. | 14 // thread. HistoryDBTask is scheduled using HistoryService::ScheduleDBTask. |
17 // When HistoryBackend processes the task it invokes RunOnDBThread. Once the | 15 // When HistoryBackend processes the task it invokes RunOnDBThread. Once the |
18 // task completes and has not been canceled, DoneRunOnMainThread is invoked back | 16 // task completes and has not been canceled, DoneRunOnMainThread is invoked back |
19 // on the main thread. | 17 // on the main thread, after which this object is destroyed, also on the |
20 class HistoryDBTask : public base::RefCountedThreadSafe<HistoryDBTask> { | 18 // main thread. |
| 19 class HistoryDBTask { |
21 public: | 20 public: |
| 21 virtual ~HistoryDBTask() {} |
| 22 |
22 // Invoked on the database thread. The return value indicates whether the | 23 // Invoked on the database thread. The return value indicates whether the |
23 // task is done. A return value of true signals the task is done and | 24 // task is done. A return value of true signals the task is done and |
24 // RunOnDBThread should NOT be invoked again. A return value of false | 25 // RunOnDBThread should NOT be invoked again. A return value of false |
25 // indicates the task is not done, and should be run again after other | 26 // indicates the task is not done, and should be run again after other |
26 // tasks are given a chance to be processed. | 27 // tasks are given a chance to be processed. |
27 virtual bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) = 0; | 28 virtual bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) = 0; |
28 | 29 |
29 // Invoked on the main thread once RunOnDBThread has returned true. This is | 30 // Invoked on the main thread once RunOnDBThread has returned true. This is |
30 // only invoked if the request was not canceled and returned true from | 31 // only invoked if the request was not canceled and returned true from |
31 // RunOnDBThread. | 32 // RunOnDBThread. |
32 virtual void DoneRunOnMainThread() = 0; | 33 virtual void DoneRunOnMainThread() = 0; |
33 | |
34 protected: | |
35 friend class base::RefCountedThreadSafe<HistoryDBTask>; | |
36 | |
37 virtual ~HistoryDBTask() {} | |
38 }; | 34 }; |
39 | 35 |
40 } // namespace history | 36 } // namespace history |
41 | 37 |
42 #endif // CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ | 38 #endif // CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_ |
OLD | NEW |