OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ | 5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ |
6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ | 6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace sql { | 10 namespace sql { |
11 class Connection; | 11 class Connection; |
12 class MetaTable; | 12 class MetaTable; |
13 } | 13 } |
14 | 14 |
15 // An abstract base class representing a table within a WebDatabase. | 15 // An abstract base class representing a table within a WebDatabase. |
16 // Each table should subclass this, adding type-specific methods as needed. | 16 // Each table should subclass this, adding type-specific methods as needed. |
17 class WebDatabaseTable { | 17 class WebDatabaseTable { |
18 public: | 18 public: |
19 WebDatabaseTable(sql::Connection* db, sql::MetaTable* meta_table); | 19 // To look up a WebDatabaseTable of a certain type from WebDatabase, |
20 // we use a void* key, so that we can simply use the address of one | |
21 // of the type's statics. | |
22 typedef void* TypeKey; | |
23 | |
24 // The object is not ready for use until Init() has been called. | |
25 WebDatabaseTable(); | |
20 virtual ~WebDatabaseTable(); | 26 virtual ~WebDatabaseTable(); |
21 | 27 |
28 // Retrieves the TypeKey for the concrete subtype. | |
29 virtual TypeKey GetTypeKey() const = 0; | |
30 | |
22 // Attempts to initialize the table and returns true if successful. | 31 // Attempts to initialize the table and returns true if successful. |
23 virtual bool Init() = 0; | 32 // |
33 // The base class stores the members passed and always return true; | |
34 // subclasses may perform other initialization as needed. | |
35 virtual bool Init(sql::Connection* db, sql::MetaTable* meta_table); | |
24 | 36 |
25 // In order to encourage developers to think about sync when adding or | 37 // In order to encourage developers to think about sync when adding or |
26 // or altering new tables, this method must be implemented. Please get in | 38 // or altering new tables, this method must be implemented. Please get in |
27 // contact with the sync team if you believe you're making a change that they | 39 // contact with the sync team if you believe you're making a change that they |
28 // should be aware of (or if you could break something). | 40 // should be aware of (or if you could break something). |
29 // TODO(andybons): Implement something more robust. | 41 // TODO(andybons): Implement something more robust. |
30 virtual bool IsSyncable() = 0; | 42 virtual bool IsSyncable() = 0; |
31 | 43 |
32 // Migrates this table to |version|. Returns false if there was | 44 // Migrates this table to |version|. Returns false if there was |
33 // migration work to do and it failed, true otherwise. | 45 // migration work to do and it failed, true otherwise. |
34 // | 46 // |
35 // |app_locale| is the locale of the app. Passed as a parameter as | 47 // |app_locale| is the locale of the app. Passed as a parameter as |
36 // |it can only be safely queried on the UI thread. | 48 // |it can only be safely queried on the UI thread. |
37 // | 49 // |
38 // Implementations may set |*update_compatible_version| to true if | 50 // Implementations may set |*update_compatible_version| to true if |
39 // the compatible version should be changed to |version|. | 51 // the compatible version should be changed to |version|. |
40 // Implementations should otherwise not modify this parameter. | 52 // Implementations should otherwise not modify this parameter. |
41 virtual bool MigrateToVersion(int version, | 53 virtual bool MigrateToVersion(int version, |
42 const std::string& app_locale, | 54 const std::string& app_locale, |
43 bool* update_compatible_version) = 0; | 55 bool* update_compatible_version) = 0; |
44 | 56 |
45 protected: | 57 protected: |
46 sql::Connection* db_; | 58 sql::Connection* db_; |
dhollowa
2013/03/12 21:29:38
A comment on these two members regarding ownership
Jói
2013/03/12 21:59:53
Done.
| |
47 sql::MetaTable* meta_table_; | 59 sql::MetaTable* meta_table_; |
48 | 60 |
49 private: | 61 private: |
50 DISALLOW_COPY_AND_ASSIGN(WebDatabaseTable); | 62 DISALLOW_COPY_AND_ASSIGN(WebDatabaseTable); |
51 }; | 63 }; |
52 | 64 |
53 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ | 65 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_TABLE_H_ |
OLD | NEW |