Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webkit/quota/quota_database.h" | 5 #include "webkit/quota/quota_database.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
| 10 #include "app/sql/diagnostic_error_delegate.h" | 10 #include "app/sql/diagnostic_error_delegate.h" |
| 11 #include "app/sql/meta_table.h" | 11 #include "app/sql/meta_table.h" |
| 12 #include "app/sql/statement.h" | 12 #include "app/sql/statement.h" |
| 13 #include "app/sql/transaction.h" | 13 #include "app/sql/transaction.h" |
| 14 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "webkit/quota/special_storage_policy.h" | 18 #include "webkit/quota/special_storage_policy.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Definitions for database schema. | 22 // Definitions for database schema. |
| 23 | 23 |
| 24 const int kCurrentVersion = 2; | 24 const int kCurrentVersion = 3; |
| 25 const int kCompatibleVersion = 2; | 25 const int kCompatibleVersion = 3; |
| 26 | 26 |
| 27 const char kOriginsTable[] = "Origins"; | 27 const char kOriginsTable[] = "Origins"; |
| 28 const char kHostQuotaTable[] = "HostQuotaTable"; | 28 const char kHostQuotaTable[] = "HostQuotaTable"; |
| 29 const char kOriginLastAccessTable[] = "OriginLastAccessTable"; | 29 const char kOriginInfoTable[] = "OriginInfoTable"; |
| 30 const char kGlobalQuotaKeyPrefix[] = "GlobalQuota-"; | 30 const char kGlobalQuotaKeyPrefix[] = "GlobalQuota-"; |
| 31 const char kIsOriginTableBootstrapped[] = "IsOriginTableBootstrapped"; | 31 const char kIsOriginTableBootstrapped[] = "IsOriginTableBootstrapped"; |
| 32 | 32 |
| 33 const struct { | 33 const struct { |
| 34 const char* table_name; | 34 const char* table_name; |
| 35 const char* columns; | 35 const char* columns; |
| 36 } kTables[] = { | 36 } kTables[] = { |
| 37 { kHostQuotaTable, | 37 { kHostQuotaTable, |
| 38 "(host TEXT NOT NULL," | 38 "(host TEXT NOT NULL," |
| 39 " type INTEGER NOT NULL," | 39 " type INTEGER NOT NULL," |
| 40 " quota INTEGER," | 40 " quota INTEGER DEFAULT 0," |
| 41 " UNIQUE(host, type))" }, | 41 " UNIQUE(host, type))" }, |
| 42 { kOriginLastAccessTable, | 42 { kOriginInfoTable, |
| 43 "(origin TEXT NOT NULL," | 43 "(origin TEXT NOT NULL," |
| 44 " type INTEGER NOT NULL," | 44 " type INTEGER NOT NULL," |
| 45 " used_count INTEGER," | 45 " used_count INTEGER DEFAULT 0," |
| 46 " last_access_time INTEGER," | 46 " last_access_time INTEGER DEFAULT 0," |
| 47 " last_modified_time INTEGER DEFAULT 0," | |
| 47 " UNIQUE(origin, type))" }, | 48 " UNIQUE(origin, type))" }, |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 const struct { | 51 const struct { |
| 51 const char* index_name; | 52 const char* index_name; |
| 52 const char* table_name; | 53 const char* table_name; |
| 53 const char* columns; | 54 const char* columns; |
| 54 bool unique; | 55 bool unique; |
| 55 } kIndexes[] = { | 56 } kIndexes[] = { |
| 56 { "HostIndex", | 57 { "HostIndex", |
| 57 kHostQuotaTable, | 58 kHostQuotaTable, |
| 58 "(host)", | 59 "(host)", |
| 59 false }, | 60 false }, |
| 60 { "OriginLastAccessIndex", | 61 { "OriginInfoIndex", |
| 61 kOriginLastAccessTable, | 62 kOriginInfoTable, |
| 62 "(origin, last_access_time)", | 63 "(origin)", |
| 64 false }, | |
| 65 { "OriginLastAccessTimeIndex", | |
| 66 kOriginInfoTable, | |
| 67 "(last_access_time)", | |
| 68 false }, | |
| 69 { "OriginLastModifiedTimeIndex", | |
| 70 kOriginInfoTable, | |
| 71 "(last_modified_time)", | |
| 63 false }, | 72 false }, |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 const int kTableCount = ARRAYSIZE_UNSAFE(kTables); | 75 const int kTableCount = ARRAYSIZE_UNSAFE(kTables); |
| 67 const int kIndexCount = ARRAYSIZE_UNSAFE(kIndexes); | 76 const int kIndexCount = ARRAYSIZE_UNSAFE(kIndexes); |
| 68 | 77 |
| 69 class HistogramUniquifier { | 78 class HistogramUniquifier { |
| 70 public: | 79 public: |
| 71 static const char* name() { return "Sqlite.Quota.Error"; } | 80 static const char* name() { return "Sqlite.Quota.Error"; } |
| 72 }; | 81 }; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 return true; | 148 return true; |
| 140 } | 149 } |
| 141 | 150 |
| 142 bool QuotaDatabase::SetHostQuota( | 151 bool QuotaDatabase::SetHostQuota( |
| 143 const std::string& host, StorageType type, int64 quota) { | 152 const std::string& host, StorageType type, int64 quota) { |
| 144 DCHECK_GE(quota, 0); | 153 DCHECK_GE(quota, 0); |
| 145 if (!LazyOpen(true)) | 154 if (!LazyOpen(true)) |
| 146 return false; | 155 return false; |
| 147 | 156 |
| 148 sql::Statement statement; | 157 sql::Statement statement; |
| 149 | 158 const char* kSql = |
| 150 int64 dummy; | 159 "INSERT OR REPLACE INTO HostQuotaTable" |
| 151 if (GetHostQuota(host, type, &dummy)) { | 160 " (quota, host, type)" |
| 152 const char* kSql = | 161 " VALUES (?, ?, ?)"; |
| 153 "UPDATE HostQuotaTable" | 162 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 154 " SET quota = ?" | 163 return false; |
| 155 " WHERE host = ? AND type = ?"; | |
| 156 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
| 157 return false; | |
| 158 } else { | |
| 159 const char* kSql = | |
| 160 "INSERT INTO HostQuotaTable" | |
| 161 " (quota, host, type)" | |
| 162 " VALUES (?, ?, ?)"; | |
| 163 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
| 164 return false; | |
| 165 } | |
| 166 | 164 |
| 167 statement.BindInt64(0, quota); | 165 statement.BindInt64(0, quota); |
| 168 statement.BindString(1, host); | 166 statement.BindString(1, host); |
| 169 statement.BindInt(2, static_cast<int>(type)); | 167 statement.BindInt(2, static_cast<int>(type)); |
| 170 if (!statement.Run()) | 168 if (!statement.Run()) |
| 171 return false; | 169 return false; |
| 172 | 170 |
| 173 ScheduleCommit(); | 171 ScheduleCommit(); |
| 174 return true; | 172 return true; |
| 175 } | 173 } |
| 176 | 174 |
| 177 bool QuotaDatabase::SetOriginLastAccessTime( | 175 bool QuotaDatabase::SetOriginLastAccessTime( |
| 178 const GURL& origin, StorageType type, base::Time last_access_time) { | 176 const GURL& origin, StorageType type, base::Time last_access_time) { |
| 179 if (!LazyOpen(true)) | 177 if (!LazyOpen(true)) |
| 180 return false; | 178 return false; |
| 181 | 179 |
| 182 sql::Statement statement; | 180 sql::Statement statement; |
| 183 | 181 |
| 184 int used_count = 1; | 182 int used_count = 1; |
| 185 if (FindOriginUsedCount(origin, type, &used_count)) { | 183 if (FindOriginUsedCount(origin, type, &used_count)) { |
| 186 ++used_count; | 184 ++used_count; |
| 187 const char* kSql = | 185 const char* kSql = |
| 188 "UPDATE OriginLastAccessTable" | 186 "UPDATE OriginInfoTable" |
| 189 " SET used_count = ?, last_access_time = ?" | 187 " SET used_count = ?, last_access_time = ?" |
| 190 " WHERE origin = ? AND type = ?"; | 188 " WHERE origin = ? AND type = ?"; |
| 191 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 189 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 192 return false; | 190 return false; |
| 193 } else { | 191 } else { |
| 194 const char* kSql = | 192 const char* kSql = |
| 195 "INSERT INTO OriginLastAccessTable" | 193 "INSERT INTO OriginInfoTable" |
| 196 " (used_count, last_access_time, origin, type)" | 194 " (used_count, last_access_time, origin, type)" |
| 197 " VALUES (?, ?, ?, ?)"; | 195 " VALUES (?, ?, ?, ?)"; |
| 198 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 196 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 199 return false; | 197 return false; |
| 200 } | 198 } |
| 201 | 199 |
| 202 statement.BindInt(0, used_count); | 200 statement.BindInt(0, used_count); |
| 203 statement.BindInt64(1, last_access_time.ToInternalValue()); | 201 statement.BindInt64(1, last_access_time.ToInternalValue()); |
| 204 statement.BindString(2, origin.spec()); | 202 statement.BindString(2, origin.spec()); |
| 205 statement.BindInt(3, static_cast<int>(type)); | 203 statement.BindInt(3, static_cast<int>(type)); |
| 206 if (!statement.Run()) | 204 if (!statement.Run()) |
| 207 return false; | 205 return false; |
| 208 | 206 |
| 209 ScheduleCommit(); | 207 ScheduleCommit(); |
| 210 return true; | 208 return true; |
| 211 } | 209 } |
| 212 | 210 |
| 213 bool QuotaDatabase::RegisterOrigins(const std::set<GURL>& origins, | 211 bool QuotaDatabase::SetOriginLastModifiedTime( |
| 214 StorageType type, | 212 const GURL& origin, StorageType type, base::Time last_modified_time) { |
| 215 base::Time last_access_time) { | |
| 216 if (!LazyOpen(true)) | 213 if (!LazyOpen(true)) |
| 217 return false; | 214 return false; |
| 218 | 215 |
| 216 sql::Statement statement; | |
| 217 | |
| 218 int dummy; | |
| 219 if (FindOriginUsedCount(origin, type, &dummy)) { | |
| 220 const char* kSql = | |
| 221 "UPDATE OriginInfoTable" | |
| 222 " SET last_modified_time = ?" | |
| 223 " WHERE origin = ? AND type = ?"; | |
| 224 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
| 225 return false; | |
| 226 } else { | |
| 227 const char* kSql = | |
| 228 "INSERT INTO OriginInfoTable" | |
| 229 " (last_modified_time, origin, type) VALUES (?, ?, ?)"; | |
| 230 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
| 231 return false; | |
| 232 } | |
| 233 | |
| 234 statement.BindInt64(0, last_modified_time.ToInternalValue()); | |
| 235 statement.BindString(1, origin.spec()); | |
| 236 statement.BindInt(2, static_cast<int>(type)); | |
| 237 if (!statement.Run()) | |
| 238 return false; | |
| 239 | |
| 240 ScheduleCommit(); | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 244 bool QuotaDatabase::RegisterInitialOriginInfo( | |
| 245 const std::set<GURL>& origins, StorageType type) { | |
| 246 if (!LazyOpen(true)) | |
| 247 return false; | |
| 248 | |
| 219 typedef std::set<GURL>::const_iterator itr_type; | 249 typedef std::set<GURL>::const_iterator itr_type; |
| 220 for (itr_type itr = origins.begin(), end = origins.end(); | 250 for (itr_type itr = origins.begin(), end = origins.end(); |
| 221 itr != end; ++itr) { | 251 itr != end; ++itr) { |
| 222 const char* kSql = | 252 const char* kSql = |
| 223 "INSERT OR IGNORE INTO OriginLastAccessTable" | 253 "INSERT OR IGNORE INTO OriginInfoTable" |
| 224 " (used_count, last_access_time, origin, type)" | 254 " (origin, type) VALUES (?, ?)"; |
| 225 " VALUES (?, ?, ?, ?)"; | |
| 226 sql::Statement statement; | 255 sql::Statement statement; |
| 227 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 256 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 228 return false; | 257 return false; |
| 229 | 258 |
| 230 statement.BindInt(0, 0); // used_count | 259 statement.BindString(0, itr->spec()); |
| 231 statement.BindInt64(1, last_access_time.ToInternalValue()); | 260 statement.BindInt(1, static_cast<int>(type)); |
| 232 statement.BindString(2, itr->spec()); | |
| 233 statement.BindInt(3, static_cast<int>(type)); | |
| 234 if (!statement.Run()) | 261 if (!statement.Run()) |
| 235 return false; | 262 return false; |
| 236 } | 263 } |
| 237 | 264 |
| 238 ScheduleCommit(); | 265 ScheduleCommit(); |
| 239 return true; | 266 return true; |
| 240 } | 267 } |
| 241 | 268 |
| 242 bool QuotaDatabase::DeleteHostQuota( | 269 bool QuotaDatabase::DeleteHostQuota( |
| 243 const std::string& host, StorageType type) { | 270 const std::string& host, StorageType type) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 254 | 281 |
| 255 statement.BindString(0, host); | 282 statement.BindString(0, host); |
| 256 statement.BindInt(1, static_cast<int>(type)); | 283 statement.BindInt(1, static_cast<int>(type)); |
| 257 if (!statement.Run()) | 284 if (!statement.Run()) |
| 258 return false; | 285 return false; |
| 259 | 286 |
| 260 ScheduleCommit(); | 287 ScheduleCommit(); |
| 261 return true; | 288 return true; |
| 262 } | 289 } |
| 263 | 290 |
| 264 bool QuotaDatabase::DeleteOriginLastAccessTime( | 291 bool QuotaDatabase::DeleteOriginInfo( |
| 265 const GURL& origin, StorageType type) { | 292 const GURL& origin, StorageType type) { |
| 266 if (!LazyOpen(false)) | 293 if (!LazyOpen(false)) |
| 267 return false; | 294 return false; |
| 268 | 295 |
| 269 const char* kSql = | 296 const char* kSql = |
| 270 "DELETE FROM OriginLastAccessTable" | 297 "DELETE FROM OriginInfoTable" |
| 271 " WHERE origin = ? AND type = ?"; | 298 " WHERE origin = ? AND type = ?"; |
| 272 | 299 |
| 273 sql::Statement statement; | 300 sql::Statement statement; |
| 274 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 301 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 275 return false; | 302 return false; |
| 276 | 303 |
| 277 statement.BindString(0, origin.spec()); | 304 statement.BindString(0, origin.spec()); |
| 278 statement.BindInt(1, static_cast<int>(type)); | 305 statement.BindInt(1, static_cast<int>(type)); |
| 279 if (!statement.Run()) | 306 if (!statement.Run()) |
| 280 return false; | 307 return false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 297 | 324 |
| 298 bool QuotaDatabase::GetLRUOrigin( | 325 bool QuotaDatabase::GetLRUOrigin( |
| 299 StorageType type, | 326 StorageType type, |
| 300 const std::set<GURL>& exceptions, | 327 const std::set<GURL>& exceptions, |
| 301 SpecialStoragePolicy* special_storage_policy, | 328 SpecialStoragePolicy* special_storage_policy, |
| 302 GURL* origin) { | 329 GURL* origin) { |
| 303 DCHECK(origin); | 330 DCHECK(origin); |
| 304 if (!LazyOpen(false)) | 331 if (!LazyOpen(false)) |
| 305 return false; | 332 return false; |
| 306 | 333 |
| 307 const char* kSql = "SELECT origin FROM OriginLastAccessTable" | 334 const char* kSql = "SELECT origin FROM OriginInfoTable" |
| 308 " WHERE type = ?" | 335 " WHERE type = ?" |
| 309 " ORDER BY last_access_time ASC"; | 336 " ORDER BY last_access_time ASC"; |
| 310 | 337 |
| 311 sql::Statement statement; | 338 sql::Statement statement; |
| 312 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 339 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 313 return false; | 340 return false; |
| 314 statement.BindInt(0, static_cast<int>(type)); | 341 statement.BindInt(0, static_cast<int>(type)); |
| 315 | 342 |
| 316 while (statement.Step()) { | 343 while (statement.Step()) { |
| 317 GURL url(statement.ColumnString(0)); | 344 GURL url(statement.ColumnString(0)); |
| 318 if (exceptions.find(url) != exceptions.end()) | 345 if (exceptions.find(url) != exceptions.end()) |
| 319 continue; | 346 continue; |
| 320 if (special_storage_policy && | 347 if (special_storage_policy && |
| 321 special_storage_policy->IsStorageUnlimited(url)) | 348 special_storage_policy->IsStorageUnlimited(url)) |
| 322 continue; | 349 continue; |
| 323 *origin = url; | 350 *origin = url; |
| 324 return true; | 351 return true; |
| 325 } | 352 } |
| 326 | 353 |
| 327 *origin = GURL(); | 354 *origin = GURL(); |
| 328 return statement.Succeeded(); | 355 return statement.Succeeded(); |
| 329 } | 356 } |
| 330 | 357 |
| 358 bool QuotaDatabase::GetOriginsModifiedSince( | |
| 359 StorageType type, std::set<GURL>* origins, base::Time modified_since) { | |
| 360 DCHECK(origins); | |
| 361 if (!LazyOpen(false)) | |
| 362 return false; | |
| 363 | |
| 364 const char* kSql = "SELECT origin FROM OriginInfoTable" | |
| 365 " WHERE type = ? AND last_modified_time > ?"; | |
| 366 | |
| 367 sql::Statement statement; | |
| 368 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | |
| 369 return false; | |
| 370 statement.BindInt(0, static_cast<int>(type)); | |
| 371 statement.BindInt64(1, modified_since.ToInternalValue()); | |
| 372 | |
| 373 origins->clear(); | |
| 374 while (statement.Step()) | |
| 375 origins->insert(GURL(statement.ColumnString(0))); | |
| 376 | |
| 377 return statement.Succeeded(); | |
| 378 } | |
| 379 | |
| 331 bool QuotaDatabase::IsOriginDatabaseBootstrapped() { | 380 bool QuotaDatabase::IsOriginDatabaseBootstrapped() { |
| 332 if (!LazyOpen(true)) | 381 if (!LazyOpen(true)) |
| 333 return false; | 382 return false; |
| 334 | 383 |
| 335 int flag = 0; | 384 int flag = 0; |
| 336 return meta_table_->GetValue(kIsOriginTableBootstrapped, &flag) && flag; | 385 return meta_table_->GetValue(kIsOriginTableBootstrapped, &flag) && flag; |
| 337 } | 386 } |
| 338 | 387 |
| 339 bool QuotaDatabase::SetOriginDatabaseBootstrapped(bool bootstrap_flag) { | 388 bool QuotaDatabase::SetOriginDatabaseBootstrapped(bool bootstrap_flag) { |
| 340 if (!LazyOpen(true)) | 389 if (!LazyOpen(true)) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 362 &QuotaDatabase::Commit); | 411 &QuotaDatabase::Commit); |
| 363 } | 412 } |
| 364 | 413 |
| 365 bool QuotaDatabase::FindOriginUsedCount( | 414 bool QuotaDatabase::FindOriginUsedCount( |
| 366 const GURL& origin, StorageType type, int* used_count) { | 415 const GURL& origin, StorageType type, int* used_count) { |
| 367 DCHECK(used_count); | 416 DCHECK(used_count); |
| 368 if (!LazyOpen(false)) | 417 if (!LazyOpen(false)) |
| 369 return false; | 418 return false; |
| 370 | 419 |
| 371 const char* kSql = | 420 const char* kSql = |
| 372 "SELECT used_count FROM OriginLastAccessTable" | 421 "SELECT used_count FROM OriginInfoTable" |
| 373 " WHERE origin = ? AND type = ?"; | 422 " WHERE origin = ? AND type = ?"; |
| 374 | 423 |
| 375 sql::Statement statement; | 424 sql::Statement statement; |
| 376 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 425 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 377 return false; | 426 return false; |
| 378 | 427 |
| 379 statement.BindString(0, origin.spec()); | 428 statement.BindString(0, origin.spec()); |
| 380 statement.BindInt(1, static_cast<int>(type)); | 429 statement.BindInt(1, static_cast<int>(type)); |
| 381 if (!statement.Step() || !statement.Succeeded()) | 430 if (!statement.Step() || !statement.Succeeded()) |
| 382 return false; | 431 return false; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 | 483 |
| 435 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion)) | 484 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion)) |
| 436 return false; | 485 return false; |
| 437 | 486 |
| 438 if (meta_table_->GetCompatibleVersionNumber() > kCurrentVersion) { | 487 if (meta_table_->GetCompatibleVersionNumber() > kCurrentVersion) { |
| 439 LOG(WARNING) << "Quota database is too new."; | 488 LOG(WARNING) << "Quota database is too new."; |
| 440 return false; | 489 return false; |
| 441 } | 490 } |
| 442 | 491 |
| 443 if (meta_table_->GetVersionNumber() < kCurrentVersion) { | 492 if (meta_table_->GetVersionNumber() < kCurrentVersion) { |
| 444 // TODO(kinuko): Support schema upgrade. | 493 // TODO(kinuko): Support schema upgrade. |
|
michaeln
2011/06/16 19:28:53
Do we need an upgrade path for this schema change?
kinuko
2011/06/23 06:37:40
Done.
| |
| 445 return ResetSchema(); | 494 return ResetSchema(); |
| 446 } | 495 } |
| 447 | 496 |
| 448 #ifndef NDEBUG | 497 #ifndef NDEBUG |
| 449 DCHECK(sql::MetaTable::DoesTableExist(db_.get())); | 498 DCHECK(sql::MetaTable::DoesTableExist(db_.get())); |
| 450 for (int i = 0; i < kTableCount; ++i) { | 499 for (int i = 0; i < kTableCount; ++i) { |
| 451 DCHECK(db_->DoesTableExist(kTables[i].table_name)); | 500 DCHECK(db_->DoesTableExist(kTables[i].table_name)); |
| 452 } | 501 } |
| 453 #endif | 502 #endif |
| 454 | 503 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 statement.ColumnInt64(2) | 582 statement.ColumnInt64(2) |
| 534 }; | 583 }; |
| 535 | 584 |
| 536 if (!callback->Run(entry)) | 585 if (!callback->Run(entry)) |
| 537 return true; | 586 return true; |
| 538 } | 587 } |
| 539 | 588 |
| 540 return statement.Succeeded(); | 589 return statement.Succeeded(); |
| 541 } | 590 } |
| 542 | 591 |
| 543 bool QuotaDatabase::DumpLastAccessTimeTable( | 592 bool QuotaDatabase::DumpOriginInfoTable( |
| 544 LastAccessTimeTableCallback* callback) { | 593 OriginInfoTableCallback* callback) { |
| 545 scoped_ptr<LastAccessTimeTableCallback> callback_deleter(callback); | 594 scoped_ptr<OriginInfoTableCallback> callback_deleter(callback); |
| 546 | 595 |
| 547 if (!LazyOpen(true)) | 596 if (!LazyOpen(true)) |
| 548 return false; | 597 return false; |
| 549 | 598 |
| 550 const char* kSql = "SELECT * FROM OriginLastAccessTable"; | 599 const char* kSql = "SELECT * FROM OriginInfoTable"; |
| 551 sql::Statement statement; | 600 sql::Statement statement; |
| 552 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) | 601 if (!PrepareCachedStatement(db_.get(), SQL_FROM_HERE, kSql, &statement)) |
| 553 return false; | 602 return false; |
| 554 | 603 |
| 555 while (statement.Step()) { | 604 while (statement.Step()) { |
| 556 LastAccessTimeTableEntry entry = { | 605 OriginInfoTableEntry entry = { |
| 557 GURL(statement.ColumnString(0)), | 606 GURL(statement.ColumnString(0)), |
| 558 static_cast<StorageType>(statement.ColumnInt(1)), | 607 static_cast<StorageType>(statement.ColumnInt(1)), |
| 559 statement.ColumnInt(2), | 608 statement.ColumnInt(2), |
| 560 base::Time::FromInternalValue(statement.ColumnInt64(3)) | 609 base::Time::FromInternalValue(statement.ColumnInt64(3)), |
| 610 base::Time::FromInternalValue(statement.ColumnInt64(4)) | |
| 561 }; | 611 }; |
| 562 | 612 |
| 563 if (!callback->Run(entry)) | 613 if (!callback->Run(entry)) |
| 564 return true; | 614 return true; |
| 565 } | 615 } |
| 566 | 616 |
| 567 return statement.Succeeded(); | 617 return statement.Succeeded(); |
| 568 } | 618 } |
| 569 | 619 |
| 570 bool operator<(const QuotaDatabase::QuotaTableEntry& lhs, | 620 bool operator<(const QuotaDatabase::QuotaTableEntry& lhs, |
| 571 const QuotaDatabase::QuotaTableEntry& rhs) { | 621 const QuotaDatabase::QuotaTableEntry& rhs) { |
| 572 if (lhs.host < rhs.host) return true; | 622 if (lhs.host < rhs.host) return true; |
| 573 if (rhs.host < lhs.host) return false; | 623 if (rhs.host < lhs.host) return false; |
| 574 if (lhs.type < rhs.type) return true; | 624 if (lhs.type < rhs.type) return true; |
| 575 if (rhs.type < lhs.type) return false; | 625 if (rhs.type < lhs.type) return false; |
| 576 return lhs.quota < rhs.quota; | 626 return lhs.quota < rhs.quota; |
| 577 } | 627 } |
| 578 | 628 |
| 579 bool operator<(const QuotaDatabase::LastAccessTimeTableEntry& lhs, | 629 bool operator<(const QuotaDatabase::OriginInfoTableEntry& lhs, |
| 580 const QuotaDatabase::LastAccessTimeTableEntry& rhs) { | 630 const QuotaDatabase::OriginInfoTableEntry& rhs) { |
| 581 if (lhs.origin < rhs.origin) return true; | 631 if (lhs.origin < rhs.origin) return true; |
| 582 if (rhs.origin < lhs.origin) return false; | 632 if (rhs.origin < lhs.origin) return false; |
| 583 if (lhs.type < rhs.type) return true; | 633 if (lhs.type < rhs.type) return true; |
| 584 if (rhs.type < lhs.type) return false; | 634 if (rhs.type < lhs.type) return false; |
| 585 if (lhs.used_count < rhs.used_count) return true; | 635 if (lhs.used_count < rhs.used_count) return true; |
| 586 if (rhs.used_count < lhs.used_count) return false; | 636 if (rhs.used_count < lhs.used_count) return false; |
| 587 return lhs.last_access_time < rhs.last_access_time; | 637 return lhs.last_access_time < rhs.last_access_time; |
| 588 } | 638 } |
| 589 } // quota namespace | 639 } // quota namespace |
| OLD | NEW |