web_database_table.h 2.7 KB

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