12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace history {
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistoryBackend;
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistoryDatabase;
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// HistoryDBTask can be used to process arbitrary work on the history backend
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// thread. HistoryDBTask is scheduled using HistoryService::ScheduleDBTask.
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// When HistoryBackend processes the task it invokes RunOnDBThread. Once the
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// task completes and has not been canceled, DoneRunOnMainThread is invoked back
175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// on the main thread, after which this object is destroyed, also on the
185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// main thread.
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class HistoryDBTask {
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual ~HistoryDBTask() {}
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked on the database thread. The return value indicates whether the
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // task is done. A return value of true signals the task is done and
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // RunOnDBThread should NOT be invoked again. A return value of false
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // indicates the task is not done, and should be run again after other
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // tasks are given a chance to be processed.
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) = 0;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked on the main thread once RunOnDBThread has returned true. This is
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // only invoked if the request was not canceled and returned true from
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // RunOnDBThread.
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DoneRunOnMainThread() = 0;
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace history
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_HISTORY_HISTORY_DB_TASK_H_
39