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

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

Issue 7396024: Adding a sync_guid field to TemplateURL. Adding appropriate database migration changes and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Lint fix. Created 9 years, 5 months 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
« no previous file with comments | « chrome/browser/webdata/keyword_table.h ('k') | chrome/browser/webdata/web_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/webdata/keyword_table.h" 5 #include "chrome/browser/webdata/keyword_table.h"
6 6
7 #include "app/sql/statement.h" 7 #include "app/sql/statement.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/history/history_database.h" 12 #include "chrome/browser/history/history_database.h"
13 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 15
16 using base::Time; 16 using base::Time;
17 17
18 namespace { 18 namespace {
19 19
20 // ID of the url column in keywords. 20 // ID of the url column in keywords.
21 const int kUrlIdPosition = 17; 21 const int kUrlIdPosition = 18;
22 22
23 // Keys used in the meta table. 23 // Keys used in the meta table.
24 const char* kDefaultSearchProviderKey = "Default Search Provider ID"; 24 const char* kDefaultSearchProviderKey = "Default Search Provider ID";
25 const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; 25 const char* kBuiltinKeywordVersion = "Builtin Keyword Version";
26 26
27 void BindURLToStatement(const TemplateURL& url, sql::Statement* s) { 27 void BindURLToStatement(const TemplateURL& url, sql::Statement* s) {
28 s->BindString(0, UTF16ToUTF8(url.short_name())); 28 s->BindString(0, UTF16ToUTF8(url.short_name()));
29 s->BindString(1, UTF16ToUTF8(url.keyword())); 29 s->BindString(1, UTF16ToUTF8(url.keyword()));
30 GURL favicon_url = url.GetFaviconURL(); 30 GURL favicon_url = url.GetFaviconURL();
31 if (!favicon_url.is_valid()) { 31 if (!favicon_url.is_valid()) {
(...skipping 16 matching lines...) Expand all
48 s->BindInt(9, url.show_in_default_list() ? 1 : 0); 48 s->BindInt(9, url.show_in_default_list() ? 1 : 0);
49 s->BindString(10, url.suggestions_url() ? url.suggestions_url()->url() : 49 s->BindString(10, url.suggestions_url() ? url.suggestions_url()->url() :
50 std::string()); 50 std::string());
51 s->BindInt(11, url.prepopulate_id()); 51 s->BindInt(11, url.prepopulate_id());
52 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0); 52 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0);
53 s->BindInt(13, url.logo_id()); 53 s->BindInt(13, url.logo_id());
54 s->BindBool(14, url.created_by_policy()); 54 s->BindBool(14, url.created_by_policy());
55 s->BindString(15, url.instant_url() ? url.instant_url()->url() : 55 s->BindString(15, url.instant_url() ? url.instant_url()->url() :
56 std::string()); 56 std::string());
57 s->BindInt64(16, url.last_modified().ToTimeT()); 57 s->BindInt64(16, url.last_modified().ToTimeT());
58 s->BindString(17, url.sync_guid());
58 } 59 }
59 } // anonymous namespace 60 } // anonymous namespace
60 61
61 KeywordTable::~KeywordTable() {} 62 KeywordTable::~KeywordTable() {}
62 63
63 bool KeywordTable::Init() { 64 bool KeywordTable::Init() {
64 if (!db_->DoesTableExist("keywords")) { 65 if (!db_->DoesTableExist("keywords")) {
65 if (!db_->Execute("CREATE TABLE keywords (" 66 if (!db_->Execute("CREATE TABLE keywords ("
66 "id INTEGER PRIMARY KEY," 67 "id INTEGER PRIMARY KEY,"
67 "short_name VARCHAR NOT NULL," 68 "short_name VARCHAR NOT NULL,"
68 "keyword VARCHAR NOT NULL," 69 "keyword VARCHAR NOT NULL,"
69 "favicon_url VARCHAR NOT NULL," 70 "favicon_url VARCHAR NOT NULL,"
70 "url VARCHAR NOT NULL," 71 "url VARCHAR NOT NULL,"
71 "show_in_default_list INTEGER," 72 "show_in_default_list INTEGER,"
72 "safe_for_autoreplace INTEGER," 73 "safe_for_autoreplace INTEGER,"
73 "originating_url VARCHAR," 74 "originating_url VARCHAR,"
74 "date_created INTEGER DEFAULT 0," 75 "date_created INTEGER DEFAULT 0,"
75 "usage_count INTEGER DEFAULT 0," 76 "usage_count INTEGER DEFAULT 0,"
76 "input_encodings VARCHAR," 77 "input_encodings VARCHAR,"
77 "suggest_url VARCHAR," 78 "suggest_url VARCHAR,"
78 "prepopulate_id INTEGER DEFAULT 0," 79 "prepopulate_id INTEGER DEFAULT 0,"
79 "autogenerate_keyword INTEGER DEFAULT 0," 80 "autogenerate_keyword INTEGER DEFAULT 0,"
80 "logo_id INTEGER DEFAULT 0," 81 "logo_id INTEGER DEFAULT 0,"
81 "created_by_policy INTEGER DEFAULT 0," 82 "created_by_policy INTEGER DEFAULT 0,"
82 "instant_url VARCHAR," 83 "instant_url VARCHAR,"
83 "last_modified INTEGER DEFAULT 0)")) { 84 "last_modified INTEGER DEFAULT 0,"
85 "sync_guid VARCHAR)")) {
84 NOTREACHED(); 86 NOTREACHED();
85 return false; 87 return false;
86 } 88 }
87 } 89 }
88 return true; 90 return true;
89 } 91 }
90 92
91 bool KeywordTable::IsSyncable() { 93 bool KeywordTable::IsSyncable() {
92 return true; 94 return true;
93 } 95 }
94 96
95 bool KeywordTable::AddKeyword(const TemplateURL& url) { 97 bool KeywordTable::AddKeyword(const TemplateURL& url) {
96 DCHECK(url.id()); 98 DCHECK(url.id());
97 // Be sure to change kUrlIdPosition if you add columns 99 // Be sure to change kUrlIdPosition if you add columns
98 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, 100 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE,
99 "INSERT INTO keywords " 101 "INSERT INTO keywords "
100 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " 102 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, "
101 "originating_url, date_created, usage_count, input_encodings, " 103 "originating_url, date_created, usage_count, input_encodings, "
102 "show_in_default_list, suggest_url, prepopulate_id, " 104 "show_in_default_list, suggest_url, prepopulate_id, "
103 "autogenerate_keyword, logo_id, created_by_policy, instant_url, " 105 "autogenerate_keyword, logo_id, created_by_policy, instant_url, "
104 "last_modified, id) VALUES " 106 "last_modified, sync_guid, id) VALUES "
105 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); 107 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
106 if (!s) { 108 if (!s) {
107 NOTREACHED() << "Statement prepare failed"; 109 NOTREACHED() << "Statement prepare failed";
108 return false; 110 return false;
109 } 111 }
110 BindURLToStatement(url, &s); 112 BindURLToStatement(url, &s);
111 s.BindInt64(kUrlIdPosition, url.id()); 113 s.BindInt64(kUrlIdPosition, url.id());
112 if (!s.Run()) { 114 if (!s.Run()) {
113 NOTREACHED(); 115 NOTREACHED();
114 return false; 116 return false;
115 } 117 }
(...skipping 11 matching lines...) Expand all
127 s.BindInt64(0, id); 129 s.BindInt64(0, id);
128 return s.Run(); 130 return s.Run();
129 } 131 }
130 132
131 bool KeywordTable::GetKeywords(std::vector<TemplateURL*>* urls) { 133 bool KeywordTable::GetKeywords(std::vector<TemplateURL*>* urls) {
132 sql::Statement s(db_->GetUniqueStatement( 134 sql::Statement s(db_->GetUniqueStatement(
133 "SELECT id, short_name, keyword, favicon_url, url, " 135 "SELECT id, short_name, keyword, favicon_url, url, "
134 "safe_for_autoreplace, originating_url, date_created, " 136 "safe_for_autoreplace, originating_url, date_created, "
135 "usage_count, input_encodings, show_in_default_list, " 137 "usage_count, input_encodings, show_in_default_list, "
136 "suggest_url, prepopulate_id, autogenerate_keyword, logo_id, " 138 "suggest_url, prepopulate_id, autogenerate_keyword, logo_id, "
137 "created_by_policy, instant_url, last_modified " 139 "created_by_policy, instant_url, last_modified, sync_guid "
138 "FROM keywords ORDER BY id ASC")); 140 "FROM keywords ORDER BY id ASC"));
139 if (!s) { 141 if (!s) {
140 NOTREACHED() << "Statement prepare failed"; 142 NOTREACHED() << "Statement prepare failed";
141 return false; 143 return false;
142 } 144 }
143 while (s.Step()) { 145 while (s.Step()) {
144 TemplateURL* template_url = new TemplateURL(); 146 TemplateURL* template_url = new TemplateURL();
145 template_url->set_id(s.ColumnInt64(0)); 147 template_url->set_id(s.ColumnInt64(0));
146 148
147 std::string tmp; 149 std::string tmp;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 template_url->set_autogenerate_keyword(s.ColumnInt(13) == 1); 182 template_url->set_autogenerate_keyword(s.ColumnInt(13) == 1);
181 183
182 template_url->set_logo_id(s.ColumnInt(14)); 184 template_url->set_logo_id(s.ColumnInt(14));
183 185
184 template_url->set_created_by_policy(s.ColumnBool(15)); 186 template_url->set_created_by_policy(s.ColumnBool(15));
185 187
186 template_url->SetInstantURL(s.ColumnString(16), 0, 0); 188 template_url->SetInstantURL(s.ColumnString(16), 0, 0);
187 189
188 template_url->set_last_modified(Time::FromTimeT(s.ColumnInt64(17))); 190 template_url->set_last_modified(Time::FromTimeT(s.ColumnInt64(17)));
189 191
192 template_url->set_sync_guid(s.ColumnString(18));
193
190 urls->push_back(template_url); 194 urls->push_back(template_url);
191 } 195 }
192 return s.Succeeded(); 196 return s.Succeeded();
193 } 197 }
194 198
195 bool KeywordTable::UpdateKeyword(const TemplateURL& url) { 199 bool KeywordTable::UpdateKeyword(const TemplateURL& url) {
196 DCHECK(url.id()); 200 DCHECK(url.id());
197 // Be sure to change kUrlIdPosition if you add columns 201 // Be sure to change kUrlIdPosition if you add columns
198 sql::Statement s(db_->GetUniqueStatement( 202 sql::Statement s(db_->GetUniqueStatement(
199 "UPDATE keywords " 203 "UPDATE keywords "
200 "SET short_name=?, keyword=?, favicon_url=?, url=?, " 204 "SET short_name=?, keyword=?, favicon_url=?, url=?, "
201 "safe_for_autoreplace=?, originating_url=?, date_created=?, " 205 "safe_for_autoreplace=?, originating_url=?, date_created=?, "
202 "usage_count=?, input_encodings=?, show_in_default_list=?, " 206 "usage_count=?, input_encodings=?, show_in_default_list=?, "
203 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, " 207 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, "
204 "logo_id=?, created_by_policy=?, instant_url=?, last_modified=? " 208 "logo_id=?, created_by_policy=?, instant_url=?, last_modified=?, "
205 "WHERE id=?")); 209 "sync_guid=? WHERE id=?"));
206 if (!s) { 210 if (!s) {
207 NOTREACHED() << "Statement prepare failed"; 211 NOTREACHED() << "Statement prepare failed";
208 return false; 212 return false;
209 } 213 }
210 BindURLToStatement(url, &s); 214 BindURLToStatement(url, &s);
211 s.BindInt64(kUrlIdPosition, url.id()); 215 s.BindInt64(kUrlIdPosition, url.id());
212 return s.Run(); 216 return s.Run();
213 } 217 }
214 218
215 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { 219 bool KeywordTable::SetDefaultSearchProviderID(int64 id) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (!db_->Execute("ALTER TABLE keywords_temp RENAME TO keywords")) 298 if (!db_->Execute("ALTER TABLE keywords_temp RENAME TO keywords"))
295 return false; 299 return false;
296 300
297 return true; 301 return true;
298 } 302 }
299 303
300 bool KeywordTable::MigrateToVersion38AddLastModifiedColumn() { 304 bool KeywordTable::MigrateToVersion38AddLastModifiedColumn() {
301 return db_->Execute( 305 return db_->Execute(
302 "ALTER TABLE keywords ADD COLUMN last_modified INTEGER DEFAULT 0"); 306 "ALTER TABLE keywords ADD COLUMN last_modified INTEGER DEFAULT 0");
303 } 307 }
308
309 bool KeywordTable::MigrateToVersion39AddSyncGUIDColumn() {
310 return db_->Execute(
311 "ALTER TABLE keywords ADD COLUMN sync_guid VARCHAR");
312 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/keyword_table.h ('k') | chrome/browser/webdata/web_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698