| LEFT | RIGHT |
| 1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
| 2 // | 2 // |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are met: | 4 // modification, are permitted provided that the following conditions are met: |
| 5 // | 5 // |
| 6 // 1. Redistributions of source code must retain the above copyright notice, | 6 // 1. Redistributions of source code must retain the above copyright notice, |
| 7 // this list of conditions and the following disclaimer. | 7 // this list of conditions and the following disclaimer. |
| 8 // 2. Redistributions in binary form must reproduce the above copyright notice, | 8 // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 9 // this list of conditions and the following disclaimer in the documentation | 9 // this list of conditions and the following disclaimer in the documentation |
| 10 // and/or other materials provided with the distribution. | 10 // and/or other materials provided with the distribution. |
| (...skipping 10 matching lines...) Show |
| 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | 25 |
| 26 #ifndef GEARS_BASE_COMMON_PERMISSIONS_DB_H__ | 26 #ifndef GEARS_BASE_COMMON_PERMISSIONS_DB_H__ |
| 27 #define GEARS_BASE_COMMON_PERMISSIONS_DB_H__ | 27 #define GEARS_BASE_COMMON_PERMISSIONS_DB_H__ |
| 28 | 28 |
| 29 #include <map> | 29 #include <map> |
| 30 #include "gears/base/common/database_name_table.h" | 30 #include "gears/base/common/database_name_table.h" |
| 31 #include "gears/base/common/database2_versions_table.h" | 31 #include "gears/base/common/database2_metadata.h" |
| 32 #include "gears/base/common/name_value_table.h" | 32 #include "gears/base/common/name_value_table.h" |
| 33 #include "gears/base/common/security_model.h" | 33 #include "gears/base/common/security_model.h" |
| 34 #include "gears/base/common/shortcut_table.h" | 34 #include "gears/base/common/shortcut_table.h" |
| 35 #include "gears/base/common/sqlite_wrapper.h" | 35 #include "gears/base/common/sqlite_wrapper.h" |
| 36 | 36 |
| 37 // TODO(cprince): Consider merging this with PermissionsDB::PermissionValue. | 37 // TODO(cprince): Consider merging this with PermissionsDB::PermissionValue. |
| 38 // But note the _TEMPORARY values hae no meaning to PermissionsDB. | 38 // But note the _TEMPORARY values hae no meaning to PermissionsDB. |
| 39 enum PermissionState { | 39 enum PermissionState { |
| 40 NOT_SET, | 40 NOT_SET, |
| 41 ALLOWED_PERMANENTLY, | 41 ALLOWED_PERMANENTLY, |
| (...skipping 94 matching lines...) Show 10 above Show 10 below |
| 136 std::string16 *basename); | 136 std::string16 *basename); |
| 137 | 137 |
| 138 // Mark the given database basename corrupt so that future calls to | 138 // Mark the given database basename corrupt so that future calls to |
| 139 // GetDatabaseBasename will no longer return it. The basename is | 139 // GetDatabaseBasename will no longer return it. The basename is |
| 140 // required because another thread of control could have already | 140 // required because another thread of control could have already |
| 141 // invalidated the database for the origin. | 141 // invalidated the database for the origin. |
| 142 bool MarkDatabaseCorrupt(const SecurityOrigin &origin, | 142 bool MarkDatabaseCorrupt(const SecurityOrigin &origin, |
| 143 const char16 *database_name, | 143 const char16 *database_name, |
| 144 const char16 *basename); | 144 const char16 *basename); |
| 145 | 145 |
| 146 // Database2 API: get current database version for a given database at the | 146 // Get the metadata table for Database2 API. The metadata table stores |
| 147 // specified origin | 147 // version information |
| 148 bool GetDatabase2Version(const SecurityOrigin &origin, | 148 Database2Metadata &GetDatabase2Metadata(); |
| 149 const std::string16 &name, | |
| 150 std::string16 *version, | |
| 151 bool *found); | |
| 152 | |
| 153 // Database2 API: set or create a version for a given database at the | |
| 154 // specified origin | |
| 155 bool SetDatabase2Version(const SecurityOrigin &origin, | |
| 156 const std::string16 &name, | |
| 157 const std::string16 &version); | |
| 158 | 149 |
| 159 private: | 150 private: |
| 160 // Private constructor, callers must use GetDB(). | 151 // Private constructor, callers must use GetDB(). |
| 161 PermissionsDB(); | 152 PermissionsDB(); |
| 162 | 153 |
| 163 // Initializes the database. Must be called before other methods. | 154 // Initializes the database. Must be called before other methods. |
| 164 bool Init(); | 155 bool Init(); |
| 165 | 156 |
| 166 // Creates or upgrades the database to kCurrentVersion. | 157 // Creates or upgrades the database to kCurrentVersion. |
| 167 bool CreateOrUpgradeDatabase(); | 158 bool CreateOrUpgradeDatabase(); |
| 168 | 159 |
| 169 // Creates the database's schema. | 160 // Creates the database's schema. |
| 170 bool CreateDatabase(); | 161 bool CreateDatabase(); |
| 171 | 162 |
| 172 // Schema upgrade functions. Higher-numbered functions call | 163 // Schema upgrade functions. Higher-numbered functions call |
| 173 // lower-numbered functions as appropriate. | 164 // lower-numbered functions as appropriate. |
| 165 bool UpgradeToVersion8(); |
| 174 bool UpgradeToVersion7(); | 166 bool UpgradeToVersion7(); |
| 175 bool UpgradeToVersion6(); | 167 bool UpgradeToVersion6(); |
| 176 bool UpgradeToVersion5(); | 168 bool UpgradeToVersion5(); |
| 177 bool UpgradeToVersion4(); | 169 bool UpgradeToVersion4(); |
| 178 bool UpgradeToVersion3(); | 170 bool UpgradeToVersion3(); |
| 179 bool UpgradeToVersion2(); | 171 bool UpgradeToVersion2(); |
| 180 | 172 |
| 181 // Destructor function called by ThreadLocals to dispose of a thread-specific | 173 // Destructor function called by ThreadLocals to dispose of a thread-specific |
| 182 // DB instance when a thread dies. | 174 // DB instance when a thread dies. |
| 183 static void DestroyDB(void *context); | 175 static void DestroyDB(void *context); |
| 184 | 176 |
| 185 // Database we use to store capabilities information. | 177 // Database we use to store capabilities information. |
| 186 SQLDatabase db_; | 178 SQLDatabase db_; |
| 187 | 179 |
| 188 // Version metadata for the capabilities database. | 180 // Version metadata for the capabilities database. |
| 189 NameValueTable version_table_; | 181 NameValueTable version_table_; |
| 190 | 182 |
| 191 // Maps origins to ability to access Gears. | 183 // Maps origins to ability to access Gears. |
| 192 NameValueTable access_table_; | 184 NameValueTable access_table_; |
| 193 | 185 |
| 194 // Shortcuts origins have defined. | 186 // Shortcuts origins have defined. |
| 195 ShortcutTable shortcut_table_; | 187 ShortcutTable shortcut_table_; |
| 196 | 188 |
| 197 DatabaseNameTable database_name_table_; | 189 DatabaseNameTable database_name_table_; |
| 198 | 190 |
| 199 // database2 metadata | 191 // database2 metadata |
| 200 Database2VersionsTable database2_versions_table_; | 192 Database2Metadata database2_metadata_table_; |
| 201 | 193 |
| 202 DISALLOW_EVIL_CONSTRUCTORS(PermissionsDB); | 194 DISALLOW_EVIL_CONSTRUCTORS(PermissionsDB); |
| 203 DECL_SINGLE_THREAD | 195 DECL_SINGLE_THREAD |
| 204 }; | 196 }; |
| 205 | 197 |
| 206 #endif // GEARS_BASE_COMMON_PERMISSIONS_DB_H__ | 198 #endif // GEARS_BASE_COMMON_PERMISSIONS_DB_H__ |
| LEFT | RIGHT |