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