Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2011 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 COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_TABLE_H_
      6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_TABLE_H_
      7 
      8 #include "base/logging.h"
      9 #include "components/webdata/common/webdata_export.h"
     10 
     11 namespace sql {
     12 class Connection;
     13 class MetaTable;
     14 }
     15 
     16 // An abstract base class representing a table within a WebDatabase.
     17 // Each table should subclass this, adding type-specific methods as needed.
     18 class WEBDATA_EXPORT WebDatabaseTable {
     19  public:
     20   // To look up a WebDatabaseTable of a certain type from WebDatabase,
     21   // we use a void* key, so that we can simply use the address of one
     22   // of the type's statics.
     23   typedef void* TypeKey;
     24 
     25   // The object is not ready for use until Init() has been called.
     26   WebDatabaseTable();
     27   virtual ~WebDatabaseTable();
     28 
     29   // Retrieves the TypeKey for the concrete subtype.
     30   virtual TypeKey GetTypeKey() const = 0;
     31 
     32   // Stores the passed members as instance variables.
     33   void Init(sql::Connection* db, sql::MetaTable* meta_table);
     34 
     35   // Create all of the expected SQL tables if they do not already exist.
     36   // Returns true on success, false on failure.
     37   virtual bool CreateTablesIfNecessary() = 0;
     38 
     39   // In order to encourage developers to think about sync when adding or
     40   // or altering new tables, this method must be implemented. Please get in
     41   // contact with the sync team if you believe you're making a change that they
     42   // should be aware of (or if you could break something).
     43   // TODO(andybons): Implement something more robust.
     44   virtual bool IsSyncable() = 0;
     45 
     46   // Migrates this table to |version|. Returns false if there was
     47   // migration work to do and it failed, true otherwise.
     48   //
     49   // Implementations may set |*update_compatible_version| to true if
     50   // the compatible version should be changed to |version|.
     51   // Implementations should otherwise not modify this parameter.
     52   virtual bool MigrateToVersion(int version,
     53                                 bool* update_compatible_version) = 0;
     54 
     55  protected:
     56   // Non-owning. These are owned by WebDatabase, valid as long as that
     57   // class exists. Since lifetime of WebDatabaseTable objects slightly
     58   // exceeds that of WebDatabase, they should not be used in
     59   // ~WebDatabaseTable.
     60   sql::Connection* db_;
     61   sql::MetaTable* meta_table_;
     62 
     63  private:
     64   DISALLOW_COPY_AND_ASSIGN(WebDatabaseTable);
     65 };
     66 
     67 #endif  // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_TABLE_H_
     68