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.
5 #ifndef CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_TYPES_H_
6 #define CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_TYPES_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/history/history_types.h"
12 #include "components/history/core/browser/keyword_id.h"
13 #include "sql/statement.h"
21 typedef int64 AndroidURLID;
22 typedef int64 SearchTermID;
24 // Wraps all columns needed to support android.provider.Browser.BookmarkColumns.
25 // It is used in insert() and update() to specify the columns need to insert or
27 // The column is not valid until it set. Using is_valid() to find out whether
28 // the specific column could be used.
30 // The defult copy constructor is used.
31 class HistoryAndBookmarkRow {
45 COLUMN_END // This must be the last.
48 HistoryAndBookmarkRow();
49 virtual ~HistoryAndBookmarkRow();
51 // Returns the column name defined in Android.
52 static std::string GetAndroidName(ColumnID id);
54 static ColumnID GetColumnID(const std::string& name);
57 void set_url(const GURL& url) {
58 set_value_explicitly(URL);
61 const GURL& url() const {
66 void set_raw_url(const std::string& raw_url) {
67 set_value_explicitly(RAW_URL);
70 const std::string& raw_url() const {
75 void set_title(const base::string16& title) {
76 set_value_explicitly(TITLE);
79 const base::string16& title() const {
83 // The page's first visit time.
84 void set_created(const base::Time created) {
85 set_value_explicitly(CREATED);
88 const base::Time& created() const {
92 // The page's last visit time.
93 void set_last_visit_time(const base::Time last_visit_time) {
94 set_value_explicitly(LAST_VISIT_TIME);
95 last_visit_time_ = last_visit_time;
97 const base::Time& last_visit_time() const {
98 return last_visit_time_;
102 void set_visit_count(int visit_count) {
103 set_value_explicitly(VISIT_COUNT);
104 visit_count_ = visit_count;
106 int visit_count() const {
110 // Whether the page is bookmarked.
111 void set_is_bookmark(bool is_bookmark) {
112 set_value_explicitly(BOOKMARK);
113 is_bookmark_ = is_bookmark;
115 bool is_bookmark() const {
119 // The favicon related to page if any.
120 void set_favicon(const scoped_refptr<base::RefCountedMemory>& data) {
121 set_value_explicitly(FAVICON);
124 const scoped_refptr<base::RefCountedMemory>& favicon() const {
128 bool favicon_valid() const {
129 return favicon_.get() && favicon_->size();
132 // The id of android url.
133 void set_id(AndroidURLID id) {
134 set_value_explicitly(ID);
137 AndroidURLID id() const {
141 // The id of the parent folder containing the bookmark, if any.
142 void set_parent_id(int64 parent_id) {
143 set_value_explicitly(PARENT_ID);
144 parent_id_ = parent_id;
146 const int64 parent_id() const {
150 // The internal URLID
151 void set_url_id(URLID url_id) {
152 set_value_explicitly(URL_ID);
155 URLID url_id() const {
159 // Returns true if the given |id| has been set explicitly.
160 bool is_value_set_explicitly(ColumnID id) const {
161 return values_set_.find(id) != values_set_.end();
165 void set_value_explicitly(ColumnID id) {
166 values_set_.insert(id);
171 std::string raw_url_;
172 base::string16 title_;
174 base::Time last_visit_time_;
175 scoped_refptr<base::RefCountedMemory> favicon_;
181 // Used to find whether a column has been set a value explicitly.
182 std::set<ColumnID> values_set_;
184 // We support the implicit copy constuctor and operator=.
187 // Wraps all columns needed to support android.provider.Browser.SearchColumns.
188 // It is used in insert() and update() to specify the columns need to insert or
191 // The column is not valid until it set. Using is_valid() to find out whether
192 // the specific column could be used.
194 // The defult copy constructor is used.
207 virtual ~SearchRow();
209 // Returns the column name defined in Android.
210 static std::string GetAndroidName(ColumnID id);
212 static ColumnID GetColumnID(const std::string& name);
214 SearchTermID id() const {
217 void set_id(SearchTermID id) {
218 set_value_explicitly(SearchRow::ID);
222 const base::string16& search_term() const {
225 void set_search_term(const base::string16& search_term) {
226 set_value_explicitly(SearchRow::SEARCH_TERM);
227 search_term_ = search_term;
230 const base::Time search_time() const {
233 void set_search_time(const base::Time& time) {
234 set_value_explicitly(SearchRow::SEARCH_TIME);
238 const GURL& url() const {
241 void set_url(const GURL& url) {
242 set_value_explicitly(SearchRow::URL);
246 KeywordID keyword_id() const {
249 void set_keyword_id(KeywordID keyword_id) {
250 set_value_explicitly(SearchRow::KEYWORD_ID);
251 keyword_id_ = keyword_id;
254 // Returns true if the given |id| has been set explicitly.
255 bool is_value_set_explicitly(ColumnID id) const {
256 return values_set_.find(id) != values_set_.end();
260 void set_value_explicitly(ColumnID id) {
261 values_set_.insert(id);
265 base::string16 search_term_;
266 base::Time search_time_;
268 KeywordID keyword_id_;
270 // Used to find whether a column has been set a value.
271 std::set<ColumnID> values_set_;
273 // We support the implicit copy constuctor and operator=.
276 // Defines the row stored in android_urls table.
277 struct AndroidURLRow {
281 // The unique id of the row
283 // The corresponding URLID in the url table.
285 // The orignal URL string passed in by client.
289 // Defines the row of keyword_cache table.
290 struct SearchTermRow {
294 // The unique id of the row.
298 // The last visit time.
299 base::Time last_visit_time;
302 // This class wraps the sql statement and favicon column index in statement if
303 // any. It is returned by AndroidProviderBackend::Query().
305 // Using favicon_index() to get the index of favicon; The value of that column
306 // is the Favicon ID, Client should call HistoryService::GetFavicon() to get the
308 class AndroidStatement {
310 AndroidStatement(sql::Statement* statement, int favicon_index);
313 sql::Statement* statement() {
314 return statement_.get();
317 // The favicon index in statement; -1 is returned if favicon is not in
319 int favicon_index() const {
320 return favicon_index_;
324 scoped_ptr<sql::Statement> statement_;
327 DISALLOW_COPY_AND_ASSIGN(AndroidStatement);
330 } // namespace history
332 #endif // CHROME_BROWSER_HISTORY_ANDROID_ANDROID_HISTORY_TYPES_H_