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