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; | 18 class TemplateURL; |
| 19 struct TemplateURLData; |
19 | 20 |
20 namespace sql { | 21 namespace sql { |
21 class Statement; | 22 class Statement; |
22 } // namespace sql | 23 } // namespace sql |
23 | 24 |
24 // This class manages the |keywords| MetaTable within the SQLite database | 25 // This class manages the |keywords| MetaTable within the SQLite database |
25 // passed to the constructor. It expects the following schema: | 26 // passed to the constructor. It expects the following schema: |
26 // | 27 // |
27 // Note: The database stores time in seconds, UTC. | 28 // Note: The database stores time in seconds, UTC. |
28 // | 29 // |
29 // keywords Most of the columns mirror that of a field in | 30 // keywords Most of the columns mirror that of a field in |
30 // TemplateURL. See TemplateURL for more details. | 31 // TemplateURLData. See that struct for more details. |
31 // id | 32 // id |
32 // short_name | 33 // short_name |
33 // keyword | 34 // keyword |
34 // favicon_url | 35 // favicon_url |
35 // url | 36 // url |
36 // show_in_default_list | 37 // show_in_default_list |
37 // safe_for_autoreplace | 38 // safe_for_autoreplace |
38 // originating_url | 39 // originating_url |
39 // date_created This column was added after we allowed keywords. | 40 // date_created This column was added after we allowed keywords. |
40 // Keywords created before we started tracking | 41 // Keywords created before we started tracking |
41 // creation date have a value of 0 for this. | 42 // creation date have a value of 0 for this. |
42 // usage_count | 43 // usage_count |
43 // input_encodings Semicolon separated list of supported input | 44 // input_encodings Semicolon separated list of supported input |
44 // encodings, may be empty. | 45 // encodings, may be empty. |
45 // suggest_url | 46 // suggest_url |
46 // prepopulate_id See TemplateURL::prepopulate_id. | 47 // prepopulate_id See TemplateURLData::prepopulate_id. |
47 // autogenerate_keyword | 48 // autogenerate_keyword |
48 // logo_id Deprecated, to be removed; see crbug.com/113248. | 49 // logo_id Deprecated, to be removed; see crbug.com/113248. |
49 // created_by_policy See TemplateURL::created_by_policy. This was added | 50 // created_by_policy See TemplateURLData::created_by_policy. This was |
50 // in version 26. | 51 // added in version 26. |
51 // instant_url See TemplateURL::instant_url. This was added | 52 // instant_url See TemplateURLData::instant_url. This was added in |
52 // in version 29. | 53 // version 29. |
53 // last_modified See TemplateURL::last_modified. This was added in | 54 // last_modified See TemplateURLData::last_modified. This was added |
54 // version 38. | 55 // in version 38. |
55 // sync_guid See TemplateURL::sync_guid. This was added in | 56 // sync_guid See TemplateURLData::sync_guid. This was added in |
56 // version 39. | 57 // version 39. |
57 // | 58 // |
58 // keywords_backup The full copy of the |keywords| table. Added in | 59 // keywords_backup The full copy of the |keywords| table. Added in |
59 // version 43. Must be in sync with |keywords| | 60 // version 43. Must be in sync with |keywords| |
60 // table otherwise verification of default search | 61 // table otherwise verification of default search |
61 // provider settings will fail. | 62 // provider settings will fail. |
62 // | 63 // |
63 // This class also manages some fields in the |meta| table: | 64 // This class also manages some fields in the |meta| table: |
64 // | 65 // |
65 // Default Search Provider ID The id of the default search provider. | 66 // Default Search Provider ID The id of the default search provider. |
66 // Default Search Provider ID Backup | 67 // Default Search Provider ID Backup |
67 // Backup copy of the above for restoring it | 68 // Backup copy of the above for restoring it |
68 // in case the setting was hijacked or | 69 // in case the setting was hijacked or |
69 // corrupted. This was added in version 40. | 70 // corrupted. This was added in version 40. |
70 // Default Search Provider Backup Backup copy of the raw in |keywords| | 71 // Default Search Provider Backup Backup copy of the raw in |keywords| |
71 // with the default search provider ID to | 72 // with the default search provider ID to |
72 // restore all provider info. This was added | 73 // restore all provider info. This was added |
73 // in version 42. Not used in 43. | 74 // in version 42. Not used in 43. |
74 // Default Search Provider ID Backup Signature | 75 // Default Search Provider ID Backup Signature |
75 // The signature of backup data and | 76 // The signature of backup data and |
76 // |keywords| table contents to be able to | 77 // |keywords| table contents to be able to |
77 // verify the backup and understand when the | 78 // verify the backup and understand when the |
78 // settings were changed. This was added | 79 // settings were changed. This was added |
79 // in version 40. | 80 // in version 40. |
80 // Builtin Keyword Version The version of builtin keywords data. | 81 // Builtin Keyword Version The version of builtin keywords data. |
81 // | 82 // |
82 class KeywordTable : public WebDatabaseTable { | 83 class KeywordTable : public WebDatabaseTable { |
83 public: | 84 public: |
84 typedef std::vector<TemplateURL*> Keywords; | 85 typedef std::vector<TemplateURLData> Keywords; |
85 | 86 |
86 // Constants exposed for the benefit of test code: | 87 // Constants exposed for the benefit of test code: |
87 | 88 |
88 static const char kDefaultSearchProviderKey[]; | 89 static const char kDefaultSearchProviderKey[]; |
89 // Meta table key to store backup value for the default search provider id. | 90 // Meta table key to store backup value for the default search provider id. |
90 static const char kDefaultSearchIDBackupKey[]; | 91 static const char kDefaultSearchIDBackupKey[]; |
91 // Meta table key to store backup value signature for the default search | 92 // Meta table key to store backup value signature for the default search |
92 // provider. The default search provider ID and the |keywords_backup| table | 93 // provider. The default search provider ID and the |keywords_backup| table |
93 // are signed. | 94 // are signed. |
94 static const char kBackupSignatureKey[]; | 95 static const char kBackupSignatureKey[]; |
(...skipping 16 matching lines...) Expand all Loading... |
111 | 112 |
112 // Loads the keywords into the specified vector. It's up to the caller to | 113 // Loads the keywords into the specified vector. It's up to the caller to |
113 // delete the returned objects. | 114 // delete the returned objects. |
114 // Returns true on success. | 115 // Returns true on success. |
115 bool GetKeywords(Keywords* keywords); | 116 bool GetKeywords(Keywords* keywords); |
116 | 117 |
117 // Updates the database values for the specified url. | 118 // Updates the database values for the specified url. |
118 // Returns true on success. | 119 // Returns true on success. |
119 bool UpdateKeyword(const TemplateURL& url); | 120 bool UpdateKeyword(const TemplateURL& url); |
120 | 121 |
121 // ID (TemplateURL->id) of the default search provider. | 122 // ID (TemplateURLData->id) of the default search provider. |
122 bool SetDefaultSearchProviderID(int64 id); | 123 bool SetDefaultSearchProviderID(int64 id); |
123 int64 GetDefaultSearchProviderID(); | 124 int64 GetDefaultSearchProviderID(); |
124 | 125 |
125 // Backup of the default search provider. NULL if the backup is invalid. The | 126 // If the default search provider backup is valid, returns true and copies the |
126 // returned TemplateURL is owned by the caller. | 127 // backup into |backup|. Otherwise returns false. |
127 TemplateURL* GetDefaultSearchProviderBackup(); | 128 bool GetDefaultSearchProviderBackup(TemplateURLData* backup); |
128 | 129 |
129 // Returns true if the default search provider has been changed out from under | 130 // Returns true if the default search provider has been changed out from under |
130 // us. This can happen if another process modifies our database or the file | 131 // us. This can happen if another process modifies our database or the file |
131 // was corrupted. | 132 // was corrupted. |
132 bool DidDefaultSearchProviderChange(); | 133 bool DidDefaultSearchProviderChange(); |
133 | 134 |
134 // Version of the built-in keywords. | 135 // Version of the built-in keywords. |
135 bool SetBuiltinKeywordVersion(int version); | 136 bool SetBuiltinKeywordVersion(int version); |
136 int GetBuiltinKeywordVersion(); | 137 int GetBuiltinKeywordVersion(); |
137 | 138 |
138 // Table migration functions. | 139 // Table migration functions. |
139 bool MigrateToVersion21AutoGenerateKeywordColumn(); | 140 bool MigrateToVersion21AutoGenerateKeywordColumn(); |
140 bool MigrateToVersion25AddLogoIDColumn(); | 141 bool MigrateToVersion25AddLogoIDColumn(); |
141 bool MigrateToVersion26AddCreatedByPolicyColumn(); | 142 bool MigrateToVersion26AddCreatedByPolicyColumn(); |
142 bool MigrateToVersion28SupportsInstantColumn(); | 143 bool MigrateToVersion28SupportsInstantColumn(); |
143 bool MigrateToVersion29InstantUrlToSupportsInstant(); | 144 bool MigrateToVersion29InstantUrlToSupportsInstant(); |
144 bool MigrateToVersion38AddLastModifiedColumn(); | 145 bool MigrateToVersion38AddLastModifiedColumn(); |
145 bool MigrateToVersion39AddSyncGUIDColumn(); | 146 bool MigrateToVersion39AddSyncGUIDColumn(); |
146 bool MigrateToVersion44AddDefaultSearchProviderBackup(); | 147 bool MigrateToVersion44AddDefaultSearchProviderBackup(); |
147 | 148 |
148 private: | 149 private: |
149 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, DefaultSearchProviderBackup); | 150 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, DefaultSearchProviderBackup); |
150 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); | 151 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); |
151 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering); | 152 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering); |
152 | 153 |
153 // Returns a new TemplateURL from the data in |s|. The caller owns the | 154 // NOTE: Since the table columns have changed in different versions, many |
154 // returned pointer. | 155 // functions below take a |table_version| argument which dictates which |
155 static TemplateURL* GetKeywordDataFromStatement(const sql::Statement& s); | 156 // version number's column set to use. |
| 157 |
| 158 // Fills |data| with the data in |s|. |
| 159 static void GetKeywordDataFromStatement(const sql::Statement& s, |
| 160 TemplateURLData* data); |
156 | 161 |
157 // Returns contents of |keywords_backup| table and default search provider | 162 // Returns contents of |keywords_backup| table and default search provider |
158 // id backup as a string through |data|. Return value is true on success, | 163 // id backup as a string through |data|. Return value is true on success, |
159 // false otherwise. | 164 // false otherwise. |
160 bool GetSignatureData(std::string* data); | 165 bool GetSignatureData(std::string* data); |
161 | 166 |
162 // Returns contents of selected table as a string in |contents| parameter. | 167 // Returns contents of selected table as a string in |contents| parameter. |
163 // Returns true on success, false otherwise. | 168 // Returns true on success, false otherwise. |
164 bool GetTableContents(const char* table_name, std::string* contents); | 169 bool GetTableContents(const char* table_name, std::string* contents); |
165 | 170 |
(...skipping 13 matching lines...) Expand all Loading... |
179 std::string* result); | 184 std::string* result); |
180 | 185 |
181 // Updates default search provider id backup in |meta| table. Returns | 186 // Updates default search provider id backup in |meta| table. Returns |
182 // true on success. The id is returned back via |id| parameter. | 187 // true on success. The id is returned back via |id| parameter. |
183 bool UpdateDefaultSearchProviderIDBackup(TemplateURLID* id); | 188 bool UpdateDefaultSearchProviderIDBackup(TemplateURLID* id); |
184 | 189 |
185 DISALLOW_COPY_AND_ASSIGN(KeywordTable); | 190 DISALLOW_COPY_AND_ASSIGN(KeywordTable); |
186 }; | 191 }; |
187 | 192 |
188 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ | 193 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ |
OLD | NEW |