Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: chrome/browser/webdata/keyword_table.h

Issue 11493003: Remove the protector service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix implicit ExtensionSystem -> TemplateURLService dependency Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // added in version 26. 47 // added in version 26.
48 // instant_url See TemplateURLData::instant_url. This was added in 48 // instant_url See TemplateURLData::instant_url. This was added in
49 // version 29. 49 // version 29.
50 // last_modified See TemplateURLData::last_modified. This was added 50 // last_modified See TemplateURLData::last_modified. This was added
51 // in version 38. 51 // in version 38.
52 // sync_guid See TemplateURLData::sync_guid. This was added in 52 // sync_guid See TemplateURLData::sync_guid. This was added in
53 // version 39. 53 // version 39.
54 // alternate_urls See TemplateURLData::alternate_urls. This was added 54 // alternate_urls See TemplateURLData::alternate_urls. This was added
55 // in version 47. 55 // in version 47.
56 // 56 //
57 // keywords_backup The full copy of the |keywords| table. Added in
58 // version 43. Must be in sync with |keywords|
59 // table otherwise verification of default search
60 // provider settings will fail.
61 //
62 // This class also manages some fields in the |meta| table: 57 // This class also manages some fields in the |meta| table:
63 // 58 //
64 // Default Search Provider ID The id of the default search provider. 59 // Default Search Provider ID The id of the default search provider.
65 // Default Search Provider ID Backup
66 // Backup copy of the above for restoring it
67 // in case the setting was hijacked or
68 // corrupted. This was added in version 40.
69 // Default Search Provider Backup Backup copy of the raw in |keywords|
70 // with the default search provider ID to
71 // restore all provider info. This was added
72 // in version 42. Not used in 43.
73 // Default Search Provider ID Backup Signature
74 // The signature of backup data and
75 // |keywords| table contents to be able to
76 // verify the backup and understand when the
77 // settings were changed. This was added
78 // in version 40.
79 // Builtin Keyword Version The version of builtin keywords data. 60 // Builtin Keyword Version The version of builtin keywords data.
80 // 61 //
81 class KeywordTable : public WebDatabaseTable { 62 class KeywordTable : public WebDatabaseTable {
82 public: 63 public:
83 typedef std::vector<TemplateURLData> Keywords; 64 typedef std::vector<TemplateURLData> Keywords;
84 65
85 // Constants exposed for the benefit of test code: 66 // Constants exposed for the benefit of test code:
86 67
87 static const char kDefaultSearchProviderKey[]; 68 static const char kDefaultSearchProviderKey[];
88 // Meta table key to store backup value for the default search provider id.
89 static const char kDefaultSearchIDBackupKey[];
90 // Meta table key to store backup value signature for the default search
91 // provider. The default search provider ID and the |keywords_backup| table
92 // are signed.
93 static const char kBackupSignatureKey[];
94 69
95 KeywordTable(sql::Connection* db, sql::MetaTable* meta_table); 70 KeywordTable(sql::Connection* db, sql::MetaTable* meta_table);
96 virtual ~KeywordTable(); 71 virtual ~KeywordTable();
97 virtual bool Init() OVERRIDE; 72 virtual bool Init() OVERRIDE;
98 virtual bool IsSyncable() OVERRIDE; 73 virtual bool IsSyncable() OVERRIDE;
99 74
100 // Adds a new keyword, updating the id field on success. 75 // Adds a new keyword, updating the id field on success.
101 // Returns true if successful. 76 // Returns true if successful.
102 bool AddKeyword(const TemplateURLData& data); 77 bool AddKeyword(const TemplateURLData& data);
103 78
104 // Removes the specified keyword. 79 // Removes the specified keyword.
105 // Returns true if successful. 80 // Returns true if successful.
106 bool RemoveKeyword(TemplateURLID id); 81 bool RemoveKeyword(TemplateURLID id);
107 82
108 // Loads the keywords into the specified vector. It's up to the caller to 83 // Loads the keywords into the specified vector. It's up to the caller to
109 // delete the returned objects. 84 // delete the returned objects.
110 // Returns true on success. 85 // Returns true on success.
111 bool GetKeywords(Keywords* keywords); 86 bool GetKeywords(Keywords* keywords);
112 87
113 // Updates the database values for the specified url. 88 // Updates the database values for the specified url.
114 // Returns true on success. 89 // Returns true on success.
115 bool UpdateKeyword(const TemplateURLData& data); 90 bool UpdateKeyword(const TemplateURLData& data);
116 91
117 // ID (TemplateURLData->id) of the default search provider. 92 // ID (TemplateURLData->id) of the default search provider.
118 bool SetDefaultSearchProviderID(int64 id); 93 bool SetDefaultSearchProviderID(int64 id);
119 int64 GetDefaultSearchProviderID(); 94 int64 GetDefaultSearchProviderID();
120 95
121 // If the default search provider backup is valid, returns true and copies the
122 // backup into |backup|. Otherwise returns false.
123 bool GetDefaultSearchProviderBackup(TemplateURLData* backup);
124
125 // Returns true if the default search provider has been changed out from under
126 // us. This can happen if another process modifies our database or the file
127 // was corrupted.
128 bool DidDefaultSearchProviderChange();
129
130 // Version of the built-in keywords. 96 // Version of the built-in keywords.
131 bool SetBuiltinKeywordVersion(int version); 97 bool SetBuiltinKeywordVersion(int version);
132 int GetBuiltinKeywordVersion(); 98 int GetBuiltinKeywordVersion();
133 99
134 // Returns a comma-separated list of the keyword columns for the current 100 // Returns a comma-separated list of the keyword columns for the current
135 // version of the table. 101 // version of the table.
136 static std::string GetKeywordColumns(); 102 static std::string GetKeywordColumns();
137 103
138 // Table migration functions. 104 // Table migration functions.
139 bool MigrateToVersion21AutoGenerateKeywordColumn(); 105 bool MigrateToVersion21AutoGenerateKeywordColumn();
140 bool MigrateToVersion25AddLogoIDColumn(); 106 bool MigrateToVersion25AddLogoIDColumn();
141 bool MigrateToVersion26AddCreatedByPolicyColumn(); 107 bool MigrateToVersion26AddCreatedByPolicyColumn();
142 bool MigrateToVersion28SupportsInstantColumn(); 108 bool MigrateToVersion28SupportsInstantColumn();
143 bool MigrateToVersion29InstantURLToSupportsInstant(); 109 bool MigrateToVersion29InstantURLToSupportsInstant();
144 bool MigrateToVersion38AddLastModifiedColumn(); 110 bool MigrateToVersion38AddLastModifiedColumn();
145 bool MigrateToVersion39AddSyncGUIDColumn(); 111 bool MigrateToVersion39AddSyncGUIDColumn();
146 bool MigrateToVersion44AddDefaultSearchProviderBackup(); 112 bool MigrateToVersion44AddDefaultSearchProviderBackup();
147 bool MigrateToVersion45RemoveLogoIDAndAutogenerateColumns(); 113 bool MigrateToVersion45RemoveLogoIDAndAutogenerateColumns();
148 bool MigrateToVersion47AddAlternateURLsColumn(); 114 bool MigrateToVersion47AddAlternateURLsColumn();
115 bool MigrateToVersion48RemoveKeywordsBackup();
149 116
150 private: 117 private:
151 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, DefaultSearchProviderBackup);
152 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); 118 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents);
153 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering); 119 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContentsOrdering);
154 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, SanitizeURLs); 120 FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, SanitizeURLs);
155 FRIEND_TEST_ALL_PREFIXES(WebDatabaseMigrationTest, MigrateVersion44ToCurrent); 121 FRIEND_TEST_ALL_PREFIXES(WebDatabaseMigrationTest, MigrateVersion44ToCurrent);
156 122
157 // NOTE: Since the table columns have changed in different versions, many 123 // NOTE: Since the table columns have changed in different versions, many
158 // functions below take a |table_version| argument which dictates which 124 // functions below take a |table_version| argument which dictates which
159 // version number's column set to use. 125 // version number's column set to use.
160 126
161 // Fills |data| with the data in |s|. Returns false if we couldn't fill 127 // Fills |data| with the data in |s|. Returns false if we couldn't fill
162 // |data| for some reason, e.g. |s| tried to set one of the fields to an 128 // |data| for some reason, e.g. |s| tried to set one of the fields to an
163 // illegal value. 129 // illegal value.
164 static bool GetKeywordDataFromStatement(const sql::Statement& s, 130 static bool GetKeywordDataFromStatement(const sql::Statement& s,
165 TemplateURLData* data); 131 TemplateURLData* data);
166 132
167 // Returns contents of |keywords_backup| table and default search provider
168 // id backup as a string through |data|. Return value is true on success,
169 // false otherwise.
170 bool GetSignatureData(int table_version, std::string* data);
171
172 // Returns contents of selected table as a string in |contents| parameter. 133 // Returns contents of selected table as a string in |contents| parameter.
173 // Returns true on success, false otherwise. 134 // Returns true on success, false otherwise.
174 bool GetTableContents(const char* table_name, 135 bool GetTableContents(const char* table_name,
175 int table_version, 136 int table_version,
176 std::string* contents); 137 std::string* contents);
177 138
178 // Updates settings backup, signs it and stores the signature in the
179 // database. Returns true on success.
180 bool UpdateBackupSignature(int table_version);
181
182 // Signs the backup table. This is a subset of what UpdateBackupSignature()
183 // does.
184 bool SignBackup(int table_version);
185
186 // Checks the signature for the current settings backup. Returns true
187 // if signature is valid, false otherwise.
188 bool IsBackupSignatureValid(int table_version);
189
190 // Gets a string representation for keyword with id specified. 139 // Gets a string representation for keyword with id specified.
191 // Used to store its result in |meta| table or to compare with another 140 // Used to store its result in |meta| table or to compare with another
192 // keyword. Returns true on success, false otherwise. 141 // keyword. Returns true on success, false otherwise.
193 bool GetKeywordAsString(TemplateURLID id, 142 bool GetKeywordAsString(TemplateURLID id,
194 const std::string& table_name, 143 const std::string& table_name,
195 std::string* result); 144 std::string* result);
196 145
197 // Updates default search provider id backup in |meta| table. Returns
198 // true on success. The id is returned back via |id| parameter.
199 bool UpdateDefaultSearchProviderIDBackup(TemplateURLID* id);
200
201 // Migrates table |name| (which should be either "keywords" or 146 // Migrates table |name| (which should be either "keywords" or
202 // "keywords_backup") from version 44 to version 45. 147 // "keywords_backup") from version 44 to version 45.
203 bool MigrateKeywordsTableForVersion45(const std::string& name); 148 bool MigrateKeywordsTableForVersion45(const std::string& name);
204 149
205 // Whether the backup was overwritten during migration.
206 bool backup_overwritten_;
207
208 DISALLOW_COPY_AND_ASSIGN(KeywordTable); 150 DISALLOW_COPY_AND_ASSIGN(KeywordTable);
209 }; 151 };
210 152
211 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ 153 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.cc ('k') | chrome/browser/webdata/keyword_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698