a3f16af33c6a90bf173dee0cf628fd520c9c87ff
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / android / android_history_provider_service.h
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_PROVIDER_SERVICE_H_
6 #define CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_PROVIDER_SERVICE_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/task/cancelable_task_tracker.h"
11 #include "components/history/core/android/android_history_types.h"
12 #include "sql/statement.h"
13
14 class Profile;
15
16 // This class provides the methods to communicate with history backend service
17 // for the Android content provider.
18 // The methods of this class must run on the UI thread to cooperate with the
19 // BookmarkModel task posted in the DB thread.
20 class AndroidHistoryProviderService {
21  public:
22   explicit AndroidHistoryProviderService(Profile* profile);
23   virtual ~AndroidHistoryProviderService();
24
25   // The callback definitions ------------------------------------------------
26
27   // Callback invoked when a method creating an |AndroidStatement| object is
28   // complete. The pointer is NULL if the creation failed.
29   typedef base::Callback<void(history::AndroidStatement*)> QueryCallback;
30
31   // Callback invoked when a method updating rows in the database complete.
32   // The parameter is the number of rows updated or 0 if the update failed.
33   typedef base::Callback<void(int)> UpdateCallback;
34
35   // Callback invoked when a method inserting rows in the database complete.
36   // The value is the new row id or 0 if the insertion failed.
37   typedef base::Callback<void(int64)> InsertCallback;
38
39   // Callback invoked when a method deleting rows in the database complete.
40   // The value is the number of rows deleted or 0 if the deletion failed.
41   typedef base::Callback<void(int)> DeleteCallback;
42
43   // Callback invoked when a method moving an |AndroidStatement| is complete.
44   // The value passed to the callback is the new position, or in case of
45   // failure, the old position.
46   typedef base::Callback<void(int)> MoveStatementCallback;
47
48   // History and Bookmarks ----------------------------------------------------
49   //
50   // Runs the given query on history backend, and invokes the |callback| to
51   // return the result.
52   //
53   // |projections| is the vector of the result columns.
54   // |selection| is the SQL WHERE clause without 'WHERE'.
55   // |selection_args| is the arguments for WHERE clause.
56   // |sort_order| is the SQL ORDER clause.
57   base::CancelableTaskTracker::TaskId QueryHistoryAndBookmarks(
58       const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections,
59       const std::string& selection,
60       const std::vector<base::string16>& selection_args,
61       const std::string& sort_order,
62       const QueryCallback& callback,
63       base::CancelableTaskTracker* tracker);
64
65   // Runs the given update and the number of the row updated is returned to the
66   // |callback| on success.
67   //
68   // |row| is the value to update.
69   // |selection| is the SQL WHERE clause without 'WHERE'.
70   // |selection_args| is the arguments for the WHERE clause.
71   base::CancelableTaskTracker::TaskId UpdateHistoryAndBookmarks(
72       const history::HistoryAndBookmarkRow& row,
73       const std::string& selection,
74       const std::vector<base::string16>& selection_args,
75       const UpdateCallback& callback,
76       base::CancelableTaskTracker* tracker);
77
78   // Deletes the specified rows and invokes the |callback| to return the number
79   // of row deleted on success.
80   //
81   // |selection| is the SQL WHERE clause without 'WHERE'.
82   // |selection_args| is the arguments for the WHERE clause.
83   //
84   // If |selection| is empty all history and bookmarks are deleted.
85   base::CancelableTaskTracker::TaskId DeleteHistoryAndBookmarks(
86       const std::string& selection,
87       const std::vector<base::string16>& selection_args,
88       const DeleteCallback& callback,
89       base::CancelableTaskTracker* tracker);
90
91   // Inserts the given values into history backend, and invokes the |callback|
92   // to return the result.
93   base::CancelableTaskTracker::TaskId InsertHistoryAndBookmark(
94       const history::HistoryAndBookmarkRow& values,
95       const InsertCallback& callback,
96       base::CancelableTaskTracker* tracker);
97
98   // Deletes the matched history and invokes |callback| to return the number of
99   // rows deleted.
100   base::CancelableTaskTracker::TaskId DeleteHistory(
101       const std::string& selection,
102       const std::vector<base::string16>& selection_args,
103       const DeleteCallback& callback,
104       base::CancelableTaskTracker* tracker);
105
106   // Statement ----------------------------------------------------------------
107   // Moves the statement's current row from |current_pos| to |destination| in DB
108   // thread. The new position is returned to the callback. The result supplied
109   // the callback is constrained by the number of rows might.
110   base::CancelableTaskTracker::TaskId MoveStatement(
111       history::AndroidStatement* statement,
112       int current_pos,
113       int destination,
114       const MoveStatementCallback& callback,
115       base::CancelableTaskTracker* tracker);
116
117   // Closes the statement in db thread. The AndroidHistoryProviderService takes
118   // the ownership of |statement|.
119   void CloseStatement(history::AndroidStatement* statement);
120
121   // Search term --------------------------------------------------------------
122   // Inserts the given values and returns the SearchTermID of the inserted row
123   // to the |callback| on success.
124   base::CancelableTaskTracker::TaskId InsertSearchTerm(
125       const history::SearchRow& row,
126       const InsertCallback& callback,
127       base::CancelableTaskTracker* tracker);
128
129   // Runs the given update and returns the number of the update rows to the
130   // |callback| on success.
131   //
132   // |row| is the value need to update.
133   // |selection| is the SQL WHERE clause without 'WHERE'.
134   // |selection_args| is the arguments for WHERE clause.
135   base::CancelableTaskTracker::TaskId UpdateSearchTerms(
136       const history::SearchRow& row,
137       const std::string& selection,
138       const std::vector<base::string16>& selection_args,
139       const UpdateCallback& callback,
140       base::CancelableTaskTracker* tracker);
141
142   // Deletes the matched rows and the number of deleted rows is returned to
143   // the |callback| on success.
144   //
145   // |selection| is the SQL WHERE clause without 'WHERE'.
146   // |selection_args| is the arguments for WHERE clause.
147   //
148   // If |selection| is empty all search terms will be deleted.
149   base::CancelableTaskTracker::TaskId DeleteSearchTerms(
150       const std::string& selection,
151       const std::vector<base::string16>& selection_args,
152       const DeleteCallback& callback,
153       base::CancelableTaskTracker* tracker);
154
155   // Runs the query and invokes the |callback| to return the result.
156   //
157   // |projections| specifies the result columns, can not be empty, otherwise
158   // NULL is returned.
159   // |selection| is the SQL WHERE clause without 'WHERE'.
160   // |selection_args| is the arguments for WHERE clause.
161   // |sort_order| the SQL ORDER clause.
162   base::CancelableTaskTracker::TaskId QuerySearchTerms(
163       const std::vector<history::SearchRow::ColumnID>& projections,
164       const std::string& selection,
165       const std::vector<base::string16>& selection_args,
166       const std::string& sort_order,
167       const QueryCallback& callback,
168       base::CancelableTaskTracker* tracker);
169
170  private:
171   Profile* profile_;
172
173   DISALLOW_COPY_AND_ASSIGN(AndroidHistoryProviderService);
174 };
175
176 #endif  // CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_PROVIDER_SERVICE_H_