Home | History | Annotate | Download | only in android
      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_SQL_HANDLER_H_
      6 #define CHROME_BROWSER_HISTORY_ANDROID_SQL_HANDLER_H_
      7 
      8 #include "chrome/browser/history/android/android_history_types.h"
      9 
     10 namespace history {
     11 
     12 // This is a wrapper of information needed for Insert/Update/Delete
     13 // method in SQLHandler. Refer to SQLHandler's comment below for how
     14 // it is used.
     15 struct TableIDRow {
     16   TableIDRow();
     17   ~TableIDRow();
     18 
     19   URLID url_id;
     20   GURL url;
     21   // Whether the URL was bookmarked.
     22   bool bookmarked;
     23 };
     24 
     25 typedef std::vector<TableIDRow> TableIDRows;
     26 
     27 // This base class is used by AndroidProviderBackend to manipulate the indvidual
     28 // table or BookmarkModel in its Insert/Update/Delete method.
     29 //
     30 // The implementation needs to provides an array of columns. Once the columns
     31 // are inserted or updated, the corresponding Insert() or Update() method will
     32 // be invoked. The Delete() method is called to delete rows.
     33 //
     34 // The HistoryAndBookmarkRow given in Insert() or Update() provide the data for
     35 // insert or update. No all the data in HistoryAndBookmarkRow maybe valid, using
     36 // HistoryAndBookmarkRow::is_value_set_explicitly() method to see if the data
     37 // need be inserted or updated.
     38 class SQLHandler {
     39  public:
     40   // |columns| is the implementation's columns.
     41   // |column_count| is the number of column in |columns|.
     42   SQLHandler(const HistoryAndBookmarkRow::ColumnID columns[], int column_count);
     43   virtual ~SQLHandler();
     44 
     45   // Updates the rows whose URLID or URL is in the given |ids_set| with new
     46   // value stored in |row|. Return true if the update succeeds.
     47   virtual bool Update(const HistoryAndBookmarkRow& row,
     48                       const TableIDRows& ids_set) = 0;
     49 
     50   // Inserts the given |row|, return true on success; The id of insertted row
     51   // should be set in |row|, so other implemnetations could use it to complete
     52   // the insert.
     53   virtual bool Insert(HistoryAndBookmarkRow* row) = 0;
     54 
     55   // Deletes the rows whose id is in |ids_set|, returns false if any deletion
     56   // failed, otherwise return true even all/some of rows are not found.
     57   virtual bool Delete(const TableIDRows& ids_set) = 0;
     58 
     59   // Return true if |row| has a value explicitly set for at least one of the
     60   // columns in |row| that are known to this class.
     61   bool HasColumnIn(const HistoryAndBookmarkRow& row);
     62 
     63   // Returns true if |id| is one of the columns known to this class.
     64   bool HasColumn(HistoryAndBookmarkRow::ColumnID id);
     65 
     66  private:
     67   // The columns of this handler.
     68   const std::set<HistoryAndBookmarkRow::ColumnID> columns_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(SQLHandler);
     71 };
     72 
     73 }  // namespace history.
     74 
     75 #endif  // CHROME_BROWSER_HISTORY_ANDROID_SQL_HANDLER_H_
     76