Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / android / android_history_provider_service.h
index 0b57b0c..d25a0cd 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "base/callback.h"
 #include "base/memory/ref_counted.h"
-#include "chrome/browser/common/cancelable_request.h"
+#include "base/task/cancelable_task_tracker.h"
 #include "chrome/browser/history/android/android_history_types.h"
 #include "sql/statement.h"
 
@@ -17,45 +17,33 @@ class Profile;
 // for the Android content provider.
 // The methods of this class must run on the UI thread to cooperate with the
 // BookmarkModel task posted in the DB thread.
-class AndroidHistoryProviderService : public CancelableRequestProvider {
+class AndroidHistoryProviderService {
  public:
   explicit AndroidHistoryProviderService(Profile* profile);
   virtual ~AndroidHistoryProviderService();
 
   // The callback definitions ------------------------------------------------
-  typedef base::Callback<void(
-                    Handle,                // handle
-                    bool,                  // true if the query succeeded.
-                    history::AndroidStatement*)>  // the result of query
-                    QueryCallback;
-  typedef CancelableRequest<QueryCallback> QueryRequest;
-
-  typedef base::Callback<void(
-                    Handle,                // handle
-                    bool,                  // true if the update succeeded.
-                    int)>                  // the number of row updated.
-                    UpdateCallback;
-  typedef CancelableRequest<UpdateCallback> UpdateRequest;
-
-  typedef base::Callback<void(
-                    Handle,                // handle
-                    bool,                  // true if the insert succeeded.
-                    int64)>                // the id of inserted row.
-                    InsertCallback;
-  typedef CancelableRequest<InsertCallback> InsertRequest;
-
-  typedef base::Callback<void(
-                    Handle,                // handle
-                    bool,                  // true if the deletion succeeded.
-                    int)>                  // the number of row deleted.
-                    DeleteCallback;
-  typedef CancelableRequest<DeleteCallback> DeleteRequest;
-
-  typedef base::Callback<void(
-                    Handle,                // handle
-                    int)>                  // the new position.
-                    MoveStatementCallback;
-  typedef CancelableRequest<MoveStatementCallback> MoveStatementRequest;
+
+  // Callback invoked when a method creating an |AndroidStatement| object is
+  // complete. The pointer is NULL if the creation failed.
+  typedef base::Callback<void(history::AndroidStatement*)> QueryCallback;
+
+  // Callback invoked when a method updating rows in the database complete.
+  // The parameter is the number of rows updated or 0 if the update failed.
+  typedef base::Callback<void(int)> UpdateCallback;
+
+  // Callback invoked when a method inserting rows in the database complete.
+  // The value is the new row id or 0 if the insertion failed.
+  typedef base::Callback<void(int64)> InsertCallback;
+
+  // Callback invoked when a method deleting rows in the database complete.
+  // The value is the number of rows deleted or 0 if the deletion failed.
+  typedef base::Callback<void(int)> DeleteCallback;
+
+  // Callback invoked when a method moving an |AndroidStatement| is complete.
+  // The value passed to the callback is the new position, or in case of
+  // failure, the old position.
+  typedef base::Callback<void(int)> MoveStatementCallback;
 
   // History and Bookmarks ----------------------------------------------------
   //
@@ -66,13 +54,13 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for WHERE clause.
   // |sort_order| is the SQL ORDER clause.
-  Handle QueryHistoryAndBookmarks(
+  base::CancelableTaskTracker::TaskId QueryHistoryAndBookmarks(
       const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections,
       const std::string& selection,
       const std::vector<base::string16>& selection_args,
       const std::string& sort_order,
-      CancelableRequestConsumerBase* consumer,
-      const QueryCallback& callback);
+      const QueryCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Runs the given update and the number of the row updated is returned to the
   // |callback| on success.
@@ -80,12 +68,12 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
   // |row| is the value to update.
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for the WHERE clause.
-  Handle UpdateHistoryAndBookmarks(
+  base::CancelableTaskTracker::TaskId UpdateHistoryAndBookmarks(
       const history::HistoryAndBookmarkRow& row,
       const std::string& selection,
       const std::vector<base::string16>& selection_args,
-      CancelableRequestConsumerBase* consumer,
-      const UpdateCallback& callback);
+      const UpdateCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Deletes the specified rows and invokes the |callback| to return the number
   // of row deleted on success.
@@ -93,35 +81,38 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for the WHERE clause.
   //
-  // if |selection| is empty all history and bookmarks are deleted.
-  Handle DeleteHistoryAndBookmarks(
+  // If |selection| is empty all history and bookmarks are deleted.
+  base::CancelableTaskTracker::TaskId DeleteHistoryAndBookmarks(
       const std::string& selection,
       const std::vector<base::string16>& selection_args,
-      CancelableRequestConsumerBase* consumer,
-      const DeleteCallback& callback);
+      const DeleteCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Inserts the given values into history backend, and invokes the |callback|
   // to return the result.
-  Handle InsertHistoryAndBookmark(const history::HistoryAndBookmarkRow& values,
-                                  CancelableRequestConsumerBase* consumer,
-                                  const InsertCallback& callback);
+  base::CancelableTaskTracker::TaskId InsertHistoryAndBookmark(
+      const history::HistoryAndBookmarkRow& values,
+      const InsertCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Deletes the matched history and invokes |callback| to return the number of
-  // the row deleted from the |callback|.
-  Handle DeleteHistory(const std::string& selection,
-                       const std::vector<base::string16>& selection_args,
-                       CancelableRequestConsumerBase* consumer,
-                       const DeleteCallback& callback);
+  // rows deleted.
+  base::CancelableTaskTracker::TaskId DeleteHistory(
+      const std::string& selection,
+      const std::vector<base::string16>& selection_args,
+      const DeleteCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Statement ----------------------------------------------------------------
   // Moves the statement's current row from |current_pos| to |destination| in DB
   // thread. The new position is returned to the callback. The result supplied
   // the callback is constrained by the number of rows might.
-  Handle MoveStatement(history::AndroidStatement* statement,
-                       int current_pos,
-                       int destination,
-                       CancelableRequestConsumerBase* consumer,
-                       const MoveStatementCallback& callback);
+  base::CancelableTaskTracker::TaskId MoveStatement(
+      history::AndroidStatement* statement,
+      int current_pos,
+      int destination,
+      const MoveStatementCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
   // Closes the statement in db thread. The AndroidHistoryProviderService takes
   // the ownership of |statement|.
@@ -129,47 +120,52 @@ class AndroidHistoryProviderService : public CancelableRequestProvider {
 
   // Search term --------------------------------------------------------------
   // Inserts the given values and returns the SearchTermID of the inserted row
-  // from the |callback| on success.
-  Handle InsertSearchTerm(const history::SearchRow& row,
-                          CancelableRequestConsumerBase* consumer,
-                          const InsertCallback& callback);
+  // to the |callback| on success.
+  base::CancelableTaskTracker::TaskId InsertSearchTerm(
+      const history::SearchRow& row,
+      const InsertCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
-  // Runs the given update and returns the number of the update rows from the
+  // Runs the given update and returns the number of the update rows to the
   // |callback| on success.
   //
   // |row| is the value need to update.
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for WHERE clause.
-  Handle UpdateSearchTerms(const history::SearchRow& row,
-                           const std::string& selection,
-                           const std::vector<base::string16>& selection_args,
-                           CancelableRequestConsumerBase* consumer,
-                           const UpdateCallback& callback);
+  base::CancelableTaskTracker::TaskId UpdateSearchTerms(
+      const history::SearchRow& row,
+      const std::string& selection,
+      const std::vector<base::string16>& selection_args,
+      const UpdateCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
-  // Deletes the matched rows and the number of deleted rows is returned from
+  // Deletes the matched rows and the number of deleted rows is returned to
   // the |callback| on success.
+  //
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for WHERE clause.
   //
-  // if |selection| is empty all search be deleted.
-  Handle DeleteSearchTerms(const std::string& selection,
-                           const std::vector<base::string16>& selection_args,
-                           CancelableRequestConsumerBase* consumer,
-                           const DeleteCallback& callback);
+  // If |selection| is empty all search terms will be deleted.
+  base::CancelableTaskTracker::TaskId DeleteSearchTerms(
+      const std::string& selection,
+      const std::vector<base::string16>& selection_args,
+      const DeleteCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
-  // Returns the result of the given query from the |callback|.
+  // Runs the query and invokes the |callback| to return the result.
+  //
   // |projections| specifies the result columns, can not be empty, otherwise
   // NULL is returned.
   // |selection| is the SQL WHERE clause without 'WHERE'.
   // |selection_args| is the arguments for WHERE clause.
   // |sort_order| the SQL ORDER clause.
-  Handle QuerySearchTerms(
+  base::CancelableTaskTracker::TaskId QuerySearchTerms(
       const std::vector<history::SearchRow::ColumnID>& projections,
       const std::string& selection,
       const std::vector<base::string16>& selection_args,
       const std::string& sort_order,
-      CancelableRequestConsumerBase* consumer,
-      const QueryCallback& callback);
+      const QueryCallback& callback,
+      base::CancelableTaskTracker* tracker);
 
  private:
   Profile* profile_;