Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_KEYWORD_TABLE_H_ | 5 #ifndef CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ |
| 6 #define CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ | 6 #define CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/webdata/web_database_table.h" | 15 #include "chrome/browser/webdata/web_database_table.h" |
| 16 #include "chrome/browser/search_engines/template_url_id.h" | 16 #include "chrome/browser/search_engines/template_url_id.h" |
| 17 | 17 |
| 18 class TemplateURL; | |
| 19 struct TemplateURLData; | 18 struct TemplateURLData; |
| 20 | 19 |
| 21 namespace sql { | 20 namespace sql { |
| 22 class Statement; | 21 class Statement; |
| 23 } // namespace sql | 22 } // namespace sql |
| 24 | 23 |
| 25 // This class manages the |keywords| MetaTable within the SQLite database | 24 // This class manages the |keywords| MetaTable within the SQLite database |
| 26 // passed to the constructor. It expects the following schema: | 25 // passed to the constructor. It expects the following schema: |
| 27 // | 26 // |
| 28 // Note: The database stores time in seconds, UTC. | 27 // Note: The database stores time in seconds, UTC. |
| 29 // | 28 // |
| 30 // keywords Most of the columns mirror that of a field in | 29 // keywords Most of the columns mirror that of a field in |
| 31 // TemplateURLData. See that struct for more details. | 30 // TemplateURLData. See that struct for more details. |
| 32 // id | 31 // id |
| 33 // short_name | 32 // short_name |
| 34 // keyword | 33 // keyword |
| 35 // favicon_url | 34 // favicon_url |
| 36 // url | 35 // url |
| 37 // show_in_default_list | 36 // show_in_default_list |
| 38 // safe_for_autoreplace | 37 // safe_for_autoreplace |
| 39 // originating_url | 38 // originating_url |
| 40 // date_created This column was added after we allowed keywords. | 39 // date_created This column was added after we allowed keywords. |
| 41 // Keywords created before we started tracking | 40 // Keywords created before we started tracking |
| 42 // creation date have a value of 0 for this. | 41 // creation date have a value of 0 for this. |
| 43 // usage_count | 42 // usage_count |
| 44 // input_encodings Semicolon separated list of supported input | 43 // input_encodings Semicolon separated list of supported input |
| 45 // encodings, may be empty. | 44 // encodings, may be empty. |
| 46 // suggest_url | 45 // suggest_url |
| 47 // prepopulate_id See TemplateURLData::prepopulate_id. | 46 // prepopulate_id See TemplateURLData::prepopulate_id. |
| 48 // autogenerate_keyword | 47 // autogenerate_keyword |
|
SteveT
2012/05/08 01:17:15
Nit: Is it worth adding a comment here about this
Peter Kasting
2012/05/08 01:31:42
Oops, this should have been removed entirely!
| |
| 49 // logo_id Deprecated, to be removed; see crbug.com/113248. | |
| 50 // created_by_policy See TemplateURLData::created_by_policy. This was | 48 // created_by_policy See TemplateURLData::created_by_policy. This was |
| 51 // added in version 26. | 49 // added in version 26. |
| 52 // instant_url See TemplateURLData::instant_url. This was added in | 50 // instant_url See TemplateURLData::instant_url. This was added in |
| 53 // version 29. | 51 // version 29. |
| 54 // last_modified See TemplateURLData::last_modified. This was added | 52 // last_modified See TemplateURLData::last_modified. This was added |
| 55 // in version 38. | 53 // in version 38. |
| 56 // sync_guid See TemplateURLData::sync_guid. This was added in | 54 // sync_guid See TemplateURLData::sync_guid. This was added in |
| 57 // version 39. | 55 // version 39. |
| 58 // | 56 // |
| 59 // keywords_backup The full copy of the |keywords| table. Added in | 57 // keywords_backup The full copy of the |keywords| table. Added in |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 static const char kKeywordColumns[]; | 95 static const char kKeywordColumns[]; |
| 98 | 96 |
| 99 KeywordTable(sql::Connection* db, sql::MetaTable* meta_table) | 97 KeywordTable(sql::Connection* db, sql::MetaTable* meta_table) |
| 100 : WebDatabaseTable(db, meta_table) {} | 98 : WebDatabaseTable(db, meta_table) {} |
| 101 virtual ~KeywordTable(); | 99 virtual ~KeywordTable(); |
| 102 virtual bool Init() OVERRIDE; | 100 virtual bool Init() OVERRIDE; |
| 103 virtual bool IsSyncable() OVERRIDE; | 101 virtual bool IsSyncable() OVERRIDE; |
| 104 | 102 |
| 105 // Adds a new keyword, updating the id field on success. | 103 // Adds a new keyword, updating the id field on success. |
| 106 // Returns true if successful. | 104 // Returns true if successful. |
| 107 bool AddKeyword(const TemplateURL& url); | 105 bool AddKeyword(const TemplateURLData& data); |
| 108 | 106 |
| 109 // Removes the specified keyword. | 107 // Removes the specified keyword. |
| 110 // Returns true if successful. | 108 // Returns true if successful. |
| 111 bool RemoveKeyword(TemplateURLID id); | 109 bool RemoveKeyword(TemplateURLID id); |
| 112 | 110 |
| 113 // Loads the keywords into the specified vector. It's up to the caller to | 111 // Loads the keywords into the specified vector. It's up to the caller to |
| 114 // delete the returned objects. | 112 // delete the returned objects. |
| 115 // Returns true on success. | 113 // Returns true on success. |
| 116 bool GetKeywords(Keywords* keywords); | 114 bool GetKeywords(Keywords* keywords); |
| 117 | 115 |
| 118 // Updates the database values for the specified url. | 116 // Updates the database values for the specified url. |
| 119 // Returns true on success. | 117 // Returns true on success. |
| 120 bool UpdateKeyword(const TemplateURL& url); | 118 bool UpdateKeyword(const TemplateURLData& data); |
| 121 | 119 |
| 122 // ID (TemplateURLData->id) of the default search provider. | 120 // ID (TemplateURLData->id) of the default search provider. |
| 123 bool SetDefaultSearchProviderID(int64 id); | 121 bool SetDefaultSearchProviderID(int64 id); |
| 124 int64 GetDefaultSearchProviderID(); | 122 int64 GetDefaultSearchProviderID(); |
| 125 | 123 |
| 126 // If the default search provider backup is valid, returns true and copies the | 124 // If the default search provider backup is valid, returns true and copies the |
| 127 // backup into |backup|. Otherwise returns false. | 125 // backup into |backup|. Otherwise returns false. |
| 128 bool GetDefaultSearchProviderBackup(TemplateURLData* backup); | 126 bool GetDefaultSearchProviderBackup(TemplateURLData* backup); |
| 129 | 127 |
| 130 // Returns true if the default search provider has been changed out from under | 128 // Returns true if the default search provider has been changed out from under |
| 131 // us. This can happen if another process modifies our database or the file | 129 // us. This can happen if another process modifies our database or the file |
| 132 // was corrupted. | 130 // was corrupted. |
| 133 bool DidDefaultSearchProviderChange(); | 131 bool DidDefaultSearchProviderChange(); |
| 134 | 132 |
| 135 // Version of the built-in keywords. | 133 // Version of the built-in keywords. |
| 136 bool SetBuiltinKeywordVersion(int version); | 134 bool SetBuiltinKeywordVersion(int version); |
| 137 int GetBuiltinKeywordVersion(); | 135 int GetBuiltinKeywordVersion(); |
| 138 | 136 |
| 139 // Table migration functions. | 137 // Table migration functions. |
| 140 bool MigrateToVersion21AutoGenerateKeywordColumn(); | 138 bool MigrateToVersion21AutoGenerateKeywordColumn(); |
| 141 bool MigrateToVersion25AddLogoIDColumn(); | 139 bool MigrateToVersion25AddLogoIDColumn(); |
| 142 bool MigrateToVersion26AddCreatedByPolicyColumn(); | 140 bool MigrateToVersion26AddCreatedByPolicyColumn(); |
| 143 bool MigrateToVersion28SupportsInstantColumn(); | 141 bool MigrateToVersion28SupportsInstantColumn(); |
| 144 bool MigrateToVersion29InstantUrlToSupportsInstant(); | 142 bool MigrateToVersion29InstantUrlToSupportsInstant(); |
| 145 bool MigrateToVersion38AddLastModifiedColumn(); | 143 bool MigrateToVersion38AddLastModifiedColumn(); |
| 146 bool MigrateToVersion39AddSyncGUIDColumn(); | 144 bool MigrateToVersion39AddSyncGUIDColumn(); |
| 147 bool MigrateToVersion44AddDefaultSearchProviderBackup(); | 145 bool MigrateToVersion44AddDefaultSearchProviderBackup(); |
| 146 bool MigrateToVersion45RemoveLogoIDAndAutogenerateColumns(); | |
| 148 | 147 |
| 149 private: | 148 private: |
| 150 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, DefaultSearchProviderBackup); | 149 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, DefaultSearchProviderBackup); |
| 151 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); | 150 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); |
| 152 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering); | 151 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering); |
| 153 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, SanitizeURLs); | 152 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, SanitizeURLs); |
| 153 FRIEND_TEST_ALL_PREFIXES(WebDatabaseMigrationTest, MigrateVersion44ToCurrent); | |
| 154 | 154 |
| 155 // NOTE: Since the table columns have changed in different versions, many | 155 // NOTE: Since the table columns have changed in different versions, many |
| 156 // functions below take a |table_version| argument which dictates which | 156 // functions below take a |table_version| argument which dictates which |
| 157 // version number's column set to use. | 157 // version number's column set to use. |
| 158 | 158 |
| 159 // Fills |data| with the data in |s|. Returns false if we couldn't fill | 159 // Fills |data| with the data in |s|. Returns false if we couldn't fill |
| 160 // |data| for some reason, e.g. |s| tried to set one of the fields to an | 160 // |data| for some reason, e.g. |s| tried to set one of the fields to an |
| 161 // illegal value. | 161 // illegal value. |
| 162 static bool GetKeywordDataFromStatement(const sql::Statement& s, | 162 static bool GetKeywordDataFromStatement(const sql::Statement& s, |
| 163 TemplateURLData* data); | 163 TemplateURLData* data); |
| 164 | 164 |
| 165 // Returns contents of |keywords_backup| table and default search provider | 165 // Returns contents of |keywords_backup| table and default search provider |
| 166 // id backup as a string through |data|. Return value is true on success, | 166 // id backup as a string through |data|. Return value is true on success, |
| 167 // false otherwise. | 167 // false otherwise. |
| 168 bool GetSignatureData(std::string* data); | 168 bool GetSignatureData(int table_version, std::string* data); |
| 169 | 169 |
| 170 // Returns contents of selected table as a string in |contents| parameter. | 170 // Returns contents of selected table as a string in |contents| parameter. |
| 171 // Returns true on success, false otherwise. | 171 // Returns true on success, false otherwise. |
| 172 bool GetTableContents(const char* table_name, std::string* contents); | 172 bool GetTableContents(const char* table_name, |
| 173 int table_version, | |
| 174 std::string* contents); | |
| 173 | 175 |
| 174 // Updates settings backup, signs it and stores the signature in the | 176 // Updates settings backup, signs it and stores the signature in the |
| 175 // database. Returns true on success. | 177 // database. Returns true on success. |
| 176 bool UpdateBackupSignature(); | 178 bool UpdateBackupSignature(int table_version); |
| 179 | |
| 180 // Signs the backup table. This is a subset of what UpdateBackupSignature() | |
| 181 // does. | |
| 182 bool SignBackup(int table_version); | |
| 177 | 183 |
| 178 // Checks the signature for the current settings backup. Returns true | 184 // Checks the signature for the current settings backup. Returns true |
| 179 // if signature is valid, false otherwise. | 185 // if signature is valid, false otherwise. |
| 180 bool IsBackupSignatureValid(); | 186 bool IsBackupSignatureValid(int table_version); |
| 181 | 187 |
| 182 // Gets a string representation for keyword with id specified. | 188 // Gets a string representation for keyword with id specified. |
| 183 // Used to store its result in |meta| table or to compare with another | 189 // Used to store its result in |meta| table or to compare with another |
| 184 // keyword. Returns true on success, false otherwise. | 190 // keyword. Returns true on success, false otherwise. |
| 185 bool GetKeywordAsString(TemplateURLID id, | 191 bool GetKeywordAsString(TemplateURLID id, |
| 186 const std::string& table_name, | 192 const std::string& table_name, |
| 187 std::string* result); | 193 std::string* result); |
| 188 | 194 |
| 189 // Updates default search provider id backup in |meta| table. Returns | 195 // Updates default search provider id backup in |meta| table. Returns |
| 190 // true on success. The id is returned back via |id| parameter. | 196 // true on success. The id is returned back via |id| parameter. |
| 191 bool UpdateDefaultSearchProviderIDBackup(TemplateURLID* id); | 197 bool UpdateDefaultSearchProviderIDBackup(TemplateURLID* id); |
| 192 | 198 |
| 199 // Migrates table |name| (which should be either "keywords" or | |
| 200 // "keywords_backup" from version 44 to version 45. | |
| 201 bool MigrateKeywordsTableForVersion45(const std::string& name); | |
| 202 | |
| 193 DISALLOW_COPY_AND_ASSIGN(KeywordTable); | 203 DISALLOW_COPY_AND_ASSIGN(KeywordTable); |
| 194 }; | 204 }; |
| 195 | 205 |
| 196 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ | 206 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ |
| OLD | NEW |