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 #include "content/browser/appcache/appcache_database.h" | 5 #include "content/browser/appcache/appcache_database.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/browser/appcache/appcache_entry.h" | 13 #include "content/browser/appcache/appcache_entry.h" |
14 #include "content/browser/appcache/appcache_histograms.h" | 14 #include "content/browser/appcache/appcache_histograms.h" |
15 #include "sql/connection.h" | 15 #include "sql/connection.h" |
16 #include "sql/error_delegate_util.h" | 16 #include "sql/error_delegate_util.h" |
17 #include "sql/meta_table.h" | 17 #include "sql/meta_table.h" |
18 #include "sql/statement.h" | 18 #include "sql/statement.h" |
19 #include "sql/transaction.h" | 19 #include "sql/transaction.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 // Schema ------------------------------------------------------------------- | 23 // Schema ------------------------------------------------------------------- |
24 namespace { | 24 namespace { |
25 | 25 |
26 #if defined(APPCACHE_USE_SIMPLE_CACHE) | 26 const int kCurrentVersion = 7; |
27 const int kCurrentVersion = 6; | 27 const int kCompatibleVersion = 7; |
28 const int kCompatibleVersion = 6; | |
29 #else | |
30 const int kCurrentVersion = 5; | |
31 const int kCompatibleVersion = 5; | |
32 #endif | |
33 | 28 |
34 // A mechanism to run experiments that may affect in data being persisted | 29 // A mechanism to run experiments that may affect in data being persisted |
35 // in different ways such that when the experiment is toggled on/off via | 30 // in different ways such that when the experiment is toggled on/off via |
36 // cmd line flags, the database gets reset. The active flags are stored at | 31 // cmd line flags, the database gets reset. The active flags are stored at |
37 // the time of database creation and compared when reopening. If different | 32 // the time of database creation and compared when reopening. If different |
38 // the database is reset. | 33 // the database is reset. |
39 const char kExperimentFlagsKey[] = "ExperimentFlags"; | 34 const char kExperimentFlagsKey[] = "ExperimentFlags"; |
40 | 35 |
41 const char kGroupsTable[] = "Groups"; | 36 const char kGroupsTable[] = "Groups"; |
42 const char kCachesTable[] = "Caches"; | 37 const char kCachesTable[] = "Caches"; |
(...skipping 13 matching lines...) Expand all Loading... | |
56 const char* columns; | 51 const char* columns; |
57 bool unique; | 52 bool unique; |
58 }; | 53 }; |
59 | 54 |
60 const TableInfo kTables[] = { | 55 const TableInfo kTables[] = { |
61 { kGroupsTable, | 56 { kGroupsTable, |
62 "(group_id INTEGER PRIMARY KEY," | 57 "(group_id INTEGER PRIMARY KEY," |
63 " origin TEXT," | 58 " origin TEXT," |
64 " manifest_url TEXT," | 59 " manifest_url TEXT," |
65 " creation_time INTEGER," | 60 " creation_time INTEGER," |
66 " last_access_time INTEGER)" }, | 61 " last_access_time INTEGER," |
62 " last_full_update_check_time INTEGER," | |
63 " first_evictable_error_time INTEGER)" }, | |
67 | 64 |
68 { kCachesTable, | 65 { kCachesTable, |
69 "(cache_id INTEGER PRIMARY KEY," | 66 "(cache_id INTEGER PRIMARY KEY," |
70 " group_id INTEGER," | 67 " group_id INTEGER," |
71 " online_wildcard INTEGER CHECK(online_wildcard IN (0, 1))," | 68 " online_wildcard INTEGER CHECK(online_wildcard IN (0, 1))," |
72 " update_time INTEGER," | 69 " update_time INTEGER," |
73 " cache_size INTEGER)" }, // intentionally not normalized | 70 " cache_size INTEGER)" }, // intentionally not normalized |
74 | 71 |
75 { kEntriesTable, | 72 { kEntriesTable, |
76 "(cache_id INTEGER," | 73 "(cache_id INTEGER," |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 (*usage_map)[*origin] = GetOriginUsage(*origin); | 239 (*usage_map)[*origin] = GetOriginUsage(*origin); |
243 } | 240 } |
244 return true; | 241 return true; |
245 } | 242 } |
246 | 243 |
247 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { | 244 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { |
248 DCHECK(origins && origins->empty()); | 245 DCHECK(origins && origins->empty()); |
249 if (!LazyOpen(false)) | 246 if (!LazyOpen(false)) |
250 return false; | 247 return false; |
251 | 248 |
252 const char* kSql = | 249 const char kSql[] = |
253 "SELECT DISTINCT(origin) FROM Groups"; | 250 "SELECT DISTINCT(origin) FROM Groups"; |
254 | 251 |
255 sql::Statement statement(db_->GetUniqueStatement(kSql)); | 252 sql::Statement statement(db_->GetUniqueStatement(kSql)); |
256 | 253 |
257 while (statement.Step()) | 254 while (statement.Step()) |
258 origins->insert(GURL(statement.ColumnString(0))); | 255 origins->insert(GURL(statement.ColumnString(0))); |
259 | 256 |
260 return statement.Succeeded(); | 257 return statement.Succeeded(); |
261 } | 258 } |
262 | 259 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 max_response_id_from_deletables); | 301 max_response_id_from_deletables); |
305 *last_deletable_response_rowid = max_deletable_response_rowid; | 302 *last_deletable_response_rowid = max_deletable_response_rowid; |
306 return true; | 303 return true; |
307 } | 304 } |
308 | 305 |
309 bool AppCacheDatabase::FindGroup(int64 group_id, GroupRecord* record) { | 306 bool AppCacheDatabase::FindGroup(int64 group_id, GroupRecord* record) { |
310 DCHECK(record); | 307 DCHECK(record); |
311 if (!LazyOpen(false)) | 308 if (!LazyOpen(false)) |
312 return false; | 309 return false; |
313 | 310 |
314 const char* kSql = | 311 const char kSql[] = |
315 "SELECT group_id, origin, manifest_url," | 312 "SELECT group_id, origin, manifest_url," |
316 " creation_time, last_access_time" | 313 " creation_time, last_access_time," |
314 " last_full_update_check_time," | |
315 " first_evictable_error_time" | |
317 " FROM Groups WHERE group_id = ?"; | 316 " FROM Groups WHERE group_id = ?"; |
318 | 317 |
319 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 318 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
320 | 319 |
321 statement.BindInt64(0, group_id); | 320 statement.BindInt64(0, group_id); |
322 if (!statement.Step()) | 321 if (!statement.Step()) |
323 return false; | 322 return false; |
324 | 323 |
325 ReadGroupRecord(statement, record); | 324 ReadGroupRecord(statement, record); |
326 DCHECK(record->group_id == group_id); | 325 DCHECK(record->group_id == group_id); |
327 return true; | 326 return true; |
328 } | 327 } |
329 | 328 |
330 bool AppCacheDatabase::FindGroupForManifestUrl( | 329 bool AppCacheDatabase::FindGroupForManifestUrl( |
331 const GURL& manifest_url, GroupRecord* record) { | 330 const GURL& manifest_url, GroupRecord* record) { |
332 DCHECK(record); | 331 DCHECK(record); |
333 if (!LazyOpen(false)) | 332 if (!LazyOpen(false)) |
334 return false; | 333 return false; |
335 | 334 |
336 const char* kSql = | 335 const char kSql[] = |
337 "SELECT group_id, origin, manifest_url," | 336 "SELECT group_id, origin, manifest_url," |
338 " creation_time, last_access_time" | 337 " creation_time, last_access_time," |
338 " last_full_update_check_time," | |
339 " first_evictable_error_time" | |
339 " FROM Groups WHERE manifest_url = ?"; | 340 " FROM Groups WHERE manifest_url = ?"; |
340 | 341 |
341 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 342 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
342 statement.BindString(0, manifest_url.spec()); | 343 statement.BindString(0, manifest_url.spec()); |
343 | 344 |
344 if (!statement.Step()) | 345 if (!statement.Step()) |
345 return false; | 346 return false; |
346 | 347 |
347 ReadGroupRecord(statement, record); | 348 ReadGroupRecord(statement, record); |
348 DCHECK(record->manifest_url == manifest_url); | 349 DCHECK(record->manifest_url == manifest_url); |
349 return true; | 350 return true; |
350 } | 351 } |
351 | 352 |
352 bool AppCacheDatabase::FindGroupsForOrigin( | 353 bool AppCacheDatabase::FindGroupsForOrigin( |
353 const GURL& origin, std::vector<GroupRecord>* records) { | 354 const GURL& origin, std::vector<GroupRecord>* records) { |
354 DCHECK(records && records->empty()); | 355 DCHECK(records && records->empty()); |
355 if (!LazyOpen(false)) | 356 if (!LazyOpen(false)) |
356 return false; | 357 return false; |
357 | 358 |
358 const char* kSql = | 359 const char kSql[] = |
359 "SELECT group_id, origin, manifest_url," | 360 "SELECT group_id, origin, manifest_url," |
360 " creation_time, last_access_time" | 361 " creation_time, last_access_time," |
362 " last_full_update_check_time," | |
363 " first_evictable_error_time" | |
361 " FROM Groups WHERE origin = ?"; | 364 " FROM Groups WHERE origin = ?"; |
362 | 365 |
363 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 366 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
364 statement.BindString(0, origin.spec()); | 367 statement.BindString(0, origin.spec()); |
365 | 368 |
366 while (statement.Step()) { | 369 while (statement.Step()) { |
367 records->push_back(GroupRecord()); | 370 records->push_back(GroupRecord()); |
368 ReadGroupRecord(statement, &records->back()); | 371 ReadGroupRecord(statement, &records->back()); |
369 DCHECK(records->back().origin == origin); | 372 DCHECK(records->back().origin == origin); |
370 } | 373 } |
371 | 374 |
372 return statement.Succeeded(); | 375 return statement.Succeeded(); |
373 } | 376 } |
374 | 377 |
375 bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { | 378 bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { |
376 DCHECK(record); | 379 DCHECK(record); |
377 if (!LazyOpen(false)) | 380 if (!LazyOpen(false)) |
378 return false; | 381 return false; |
379 | 382 |
380 const char* kSql = | 383 const char kSql[] = |
381 "SELECT g.group_id, g.origin, g.manifest_url," | 384 "SELECT g.group_id, g.origin, g.manifest_url," |
382 " g.creation_time, g.last_access_time" | 385 " g.creation_time, g.last_access_time," |
386 " g.last_full_update_check_time," | |
387 " g.first_evictable_error_time" | |
383 " FROM Groups g, Caches c" | 388 " FROM Groups g, Caches c" |
384 " WHERE c.cache_id = ? AND c.group_id = g.group_id"; | 389 " WHERE c.cache_id = ? AND c.group_id = g.group_id"; |
385 | 390 |
386 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 391 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
387 statement.BindInt64(0, cache_id); | 392 statement.BindInt64(0, cache_id); |
388 | 393 |
389 if (!statement.Step()) | 394 if (!statement.Step()) |
390 return false; | 395 return false; |
391 | 396 |
392 ReadGroupRecord(statement, record); | 397 ReadGroupRecord(statement, record); |
393 return true; | 398 return true; |
394 } | 399 } |
395 | 400 |
401 bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { | |
402 if (!LazyOpen(true)) | |
jsbell
2015/07/07 00:18:59
Would be nice to have /* create_if_needed */ comme
| |
403 return false; | |
404 | |
405 const char kSql[] = | |
406 "INSERT INTO Groups" | |
407 " (group_id, origin, manifest_url, creation_time, last_access_time," | |
408 " last_full_update_check_time, first_evictable_error_time)" | |
409 " VALUES(?, ?, ?, ?, ?, ?, ?)"; | |
410 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | |
411 statement.BindInt64(0, record->group_id); | |
412 statement.BindString(1, record->origin.spec()); | |
413 statement.BindString(2, record->manifest_url.spec()); | |
414 statement.BindInt64(3, record->creation_time.ToInternalValue()); | |
415 statement.BindInt64(4, record->last_access_time.ToInternalValue()); | |
416 statement.BindInt64(5, record->last_full_update_check_time.ToInternalValue()); | |
417 statement.BindInt64(6, record->first_evictable_error_time.ToInternalValue()); | |
418 return statement.Run(); | |
419 } | |
420 | |
421 bool AppCacheDatabase::DeleteGroup(int64 group_id) { | |
422 if (!LazyOpen(false)) | |
423 return false; | |
424 | |
425 const char kSql[] = | |
426 "DELETE FROM Groups WHERE group_id = ?"; | |
427 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | |
428 statement.BindInt64(0, group_id); | |
429 return statement.Run(); | |
430 } | |
431 | |
396 bool AppCacheDatabase::UpdateLastAccessTime( | 432 bool AppCacheDatabase::UpdateLastAccessTime( |
397 int64 group_id, base::Time time) { | 433 int64 group_id, base::Time time) { |
398 if (!LazyOpen(true)) | 434 if (!LazyUpdateLastAccessTime(group_id, time)) |
399 return false; | 435 return false; |
400 | 436 return CommitLazyLastAccessTimes(); |
401 const char* kSql = | |
402 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; | |
403 | |
404 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | |
405 statement.BindInt64(0, time.ToInternalValue()); | |
406 statement.BindInt64(1, group_id); | |
407 | |
408 return statement.Run(); | |
409 } | 437 } |
410 | 438 |
411 bool AppCacheDatabase::LazyUpdateLastAccessTime( | 439 bool AppCacheDatabase::LazyUpdateLastAccessTime( |
412 int64 group_id, base::Time time) { | 440 int64 group_id, base::Time time) { |
413 if (!LazyOpen(true)) | 441 if (!LazyOpen(true)) |
414 return false; | 442 return false; |
415 lazy_last_access_times_[group_id] = time; | 443 lazy_last_access_times_[group_id] = time; |
416 return true; | 444 return true; |
417 } | 445 } |
418 | 446 |
419 bool AppCacheDatabase::CommitLazyLastAccessTimes() { | 447 bool AppCacheDatabase::CommitLazyLastAccessTimes() { |
420 if (lazy_last_access_times_.empty()) | 448 if (lazy_last_access_times_.empty()) |
421 return true; | 449 return true; |
422 if (!LazyOpen(false)) | 450 if (!LazyOpen(false)) |
423 return false; | 451 return false; |
424 | 452 |
425 sql::Transaction transaction(db_.get()); | 453 sql::Transaction transaction(db_.get()); |
426 if (!transaction.Begin()) | 454 if (!transaction.Begin()) |
427 return false; | 455 return false; |
428 for (const auto& pair : lazy_last_access_times_) | 456 for (const auto& pair : lazy_last_access_times_) { |
429 UpdateLastAccessTime(pair.first, pair.second); | 457 const char kSql[] = |
458 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; | |
459 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | |
460 statement.BindInt64(0, pair.second.ToInternalValue()); // time | |
461 statement.BindInt64(1, pair.first); // group_id | |
462 statement.Run(); | |
463 } | |
430 lazy_last_access_times_.clear(); | 464 lazy_last_access_times_.clear(); |
431 return transaction.Commit(); | 465 return transaction.Commit(); |
432 } | 466 } |
433 | 467 |
434 bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { | 468 bool AppCacheDatabase::UpdateEvictionTimes( |
469 int64 group_id, | |
470 base::Time last_full_update_check_time, | |
471 base::Time first_evictable_error_time) { | |
435 if (!LazyOpen(true)) | 472 if (!LazyOpen(true)) |
436 return false; | 473 return false; |
437 | 474 |
438 const char* kSql = | 475 const char kSql[] = |
439 "INSERT INTO Groups" | 476 "UPDATE Groups" |
440 " (group_id, origin, manifest_url, creation_time, last_access_time)" | 477 " SET last_full_update_check_time = ?, first_evictable_error_time = ?" |
441 " VALUES(?, ?, ?, ?, ?)"; | 478 " WHERE group_id = ?"; |
442 | |
443 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 479 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
444 statement.BindInt64(0, record->group_id); | 480 statement.BindInt64(0, last_full_update_check_time.ToInternalValue()); |
445 statement.BindString(1, record->origin.spec()); | 481 statement.BindInt64(1, first_evictable_error_time.ToInternalValue()); |
446 statement.BindString(2, record->manifest_url.spec()); | 482 statement.BindInt64(2, group_id); |
447 statement.BindInt64(3, record->creation_time.ToInternalValue()); | 483 return statement.Run(); // Will succeed even if group_id is invalid. |
448 statement.BindInt64(4, record->last_access_time.ToInternalValue()); | |
449 | |
450 return statement.Run(); | |
451 } | |
452 | |
453 bool AppCacheDatabase::DeleteGroup(int64 group_id) { | |
454 if (!LazyOpen(false)) | |
455 return false; | |
456 | |
457 const char* kSql = | |
458 "DELETE FROM Groups WHERE group_id = ?"; | |
459 | |
460 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | |
461 statement.BindInt64(0, group_id); | |
462 | |
463 return statement.Run(); | |
464 } | 484 } |
465 | 485 |
466 bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) { | 486 bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) { |
467 DCHECK(record); | 487 DCHECK(record); |
468 if (!LazyOpen(false)) | 488 if (!LazyOpen(false)) |
469 return false; | 489 return false; |
470 | 490 |
471 const char* kSql = | 491 const char kSql[] = |
472 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" | 492 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" |
473 " FROM Caches WHERE cache_id = ?"; | 493 " FROM Caches WHERE cache_id = ?"; |
474 | 494 |
475 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 495 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
476 statement.BindInt64(0, cache_id); | 496 statement.BindInt64(0, cache_id); |
477 | 497 |
478 if (!statement.Step()) | 498 if (!statement.Step()) |
479 return false; | 499 return false; |
480 | 500 |
481 ReadCacheRecord(statement, record); | 501 ReadCacheRecord(statement, record); |
482 return true; | 502 return true; |
483 } | 503 } |
484 | 504 |
485 bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) { | 505 bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) { |
486 DCHECK(record); | 506 DCHECK(record); |
487 if (!LazyOpen(false)) | 507 if (!LazyOpen(false)) |
488 return false; | 508 return false; |
489 | 509 |
490 const char* kSql = | 510 const char kSql[] = |
491 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" | 511 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" |
492 " FROM Caches WHERE group_id = ?"; | 512 " FROM Caches WHERE group_id = ?"; |
493 | 513 |
494 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 514 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
495 statement.BindInt64(0, group_id); | 515 statement.BindInt64(0, group_id); |
496 | 516 |
497 if (!statement.Step()) | 517 if (!statement.Step()) |
498 return false; | 518 return false; |
499 | 519 |
500 ReadCacheRecord(statement, record); | 520 ReadCacheRecord(statement, record); |
(...skipping 14 matching lines...) Expand all Loading... | |
515 records->push_back(cache_record); | 535 records->push_back(cache_record); |
516 ++iter; | 536 ++iter; |
517 } | 537 } |
518 return true; | 538 return true; |
519 } | 539 } |
520 | 540 |
521 bool AppCacheDatabase::InsertCache(const CacheRecord* record) { | 541 bool AppCacheDatabase::InsertCache(const CacheRecord* record) { |
522 if (!LazyOpen(true)) | 542 if (!LazyOpen(true)) |
523 return false; | 543 return false; |
524 | 544 |
525 const char* kSql = | 545 const char kSql[] = |
526 "INSERT INTO Caches (cache_id, group_id, online_wildcard," | 546 "INSERT INTO Caches (cache_id, group_id, online_wildcard," |
527 " update_time, cache_size)" | 547 " update_time, cache_size)" |
528 " VALUES(?, ?, ?, ?, ?)"; | 548 " VALUES(?, ?, ?, ?, ?)"; |
529 | 549 |
530 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 550 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
531 statement.BindInt64(0, record->cache_id); | 551 statement.BindInt64(0, record->cache_id); |
532 statement.BindInt64(1, record->group_id); | 552 statement.BindInt64(1, record->group_id); |
533 statement.BindBool(2, record->online_wildcard); | 553 statement.BindBool(2, record->online_wildcard); |
534 statement.BindInt64(3, record->update_time.ToInternalValue()); | 554 statement.BindInt64(3, record->update_time.ToInternalValue()); |
535 statement.BindInt64(4, record->cache_size); | 555 statement.BindInt64(4, record->cache_size); |
536 | 556 |
537 return statement.Run(); | 557 return statement.Run(); |
538 } | 558 } |
539 | 559 |
540 bool AppCacheDatabase::DeleteCache(int64 cache_id) { | 560 bool AppCacheDatabase::DeleteCache(int64 cache_id) { |
541 if (!LazyOpen(false)) | 561 if (!LazyOpen(false)) |
542 return false; | 562 return false; |
543 | 563 |
544 const char* kSql = | 564 const char kSql[] = |
545 "DELETE FROM Caches WHERE cache_id = ?"; | 565 "DELETE FROM Caches WHERE cache_id = ?"; |
546 | 566 |
547 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 567 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
548 statement.BindInt64(0, cache_id); | 568 statement.BindInt64(0, cache_id); |
549 | 569 |
550 return statement.Run(); | 570 return statement.Run(); |
551 } | 571 } |
552 | 572 |
553 bool AppCacheDatabase::FindEntriesForCache( | 573 bool AppCacheDatabase::FindEntriesForCache( |
554 int64 cache_id, std::vector<EntryRecord>* records) { | 574 int64 cache_id, std::vector<EntryRecord>* records) { |
555 DCHECK(records && records->empty()); | 575 DCHECK(records && records->empty()); |
556 if (!LazyOpen(false)) | 576 if (!LazyOpen(false)) |
557 return false; | 577 return false; |
558 | 578 |
559 const char* kSql = | 579 const char kSql[] = |
560 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 580 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
561 " WHERE cache_id = ?"; | 581 " WHERE cache_id = ?"; |
562 | 582 |
563 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 583 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
564 statement.BindInt64(0, cache_id); | 584 statement.BindInt64(0, cache_id); |
565 | 585 |
566 while (statement.Step()) { | 586 while (statement.Step()) { |
567 records->push_back(EntryRecord()); | 587 records->push_back(EntryRecord()); |
568 ReadEntryRecord(statement, &records->back()); | 588 ReadEntryRecord(statement, &records->back()); |
569 DCHECK(records->back().cache_id == cache_id); | 589 DCHECK(records->back().cache_id == cache_id); |
570 } | 590 } |
571 | 591 |
572 return statement.Succeeded(); | 592 return statement.Succeeded(); |
573 } | 593 } |
574 | 594 |
575 bool AppCacheDatabase::FindEntriesForUrl( | 595 bool AppCacheDatabase::FindEntriesForUrl( |
576 const GURL& url, std::vector<EntryRecord>* records) { | 596 const GURL& url, std::vector<EntryRecord>* records) { |
577 DCHECK(records && records->empty()); | 597 DCHECK(records && records->empty()); |
578 if (!LazyOpen(false)) | 598 if (!LazyOpen(false)) |
579 return false; | 599 return false; |
580 | 600 |
581 const char* kSql = | 601 const char kSql[] = |
582 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 602 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
583 " WHERE url = ?"; | 603 " WHERE url = ?"; |
584 | 604 |
585 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 605 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
586 statement.BindString(0, url.spec()); | 606 statement.BindString(0, url.spec()); |
587 | 607 |
588 while (statement.Step()) { | 608 while (statement.Step()) { |
589 records->push_back(EntryRecord()); | 609 records->push_back(EntryRecord()); |
590 ReadEntryRecord(statement, &records->back()); | 610 ReadEntryRecord(statement, &records->back()); |
591 DCHECK(records->back().url == url); | 611 DCHECK(records->back().url == url); |
592 } | 612 } |
593 | 613 |
594 return statement.Succeeded(); | 614 return statement.Succeeded(); |
595 } | 615 } |
596 | 616 |
597 bool AppCacheDatabase::FindEntry( | 617 bool AppCacheDatabase::FindEntry( |
598 int64 cache_id, const GURL& url, EntryRecord* record) { | 618 int64 cache_id, const GURL& url, EntryRecord* record) { |
599 DCHECK(record); | 619 DCHECK(record); |
600 if (!LazyOpen(false)) | 620 if (!LazyOpen(false)) |
601 return false; | 621 return false; |
602 | 622 |
603 const char* kSql = | 623 const char kSql[] = |
604 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 624 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
605 " WHERE cache_id = ? AND url = ?"; | 625 " WHERE cache_id = ? AND url = ?"; |
606 | 626 |
607 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 627 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
608 statement.BindInt64(0, cache_id); | 628 statement.BindInt64(0, cache_id); |
609 statement.BindString(1, url.spec()); | 629 statement.BindString(1, url.spec()); |
610 | 630 |
611 if (!statement.Step()) | 631 if (!statement.Step()) |
612 return false; | 632 return false; |
613 | 633 |
614 ReadEntryRecord(statement, record); | 634 ReadEntryRecord(statement, record); |
615 DCHECK(record->cache_id == cache_id); | 635 DCHECK(record->cache_id == cache_id); |
616 DCHECK(record->url == url); | 636 DCHECK(record->url == url); |
617 return true; | 637 return true; |
618 } | 638 } |
619 | 639 |
620 bool AppCacheDatabase::InsertEntry(const EntryRecord* record) { | 640 bool AppCacheDatabase::InsertEntry(const EntryRecord* record) { |
621 if (!LazyOpen(true)) | 641 if (!LazyOpen(true)) |
622 return false; | 642 return false; |
623 | 643 |
624 const char* kSql = | 644 const char kSql[] = |
625 "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)" | 645 "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)" |
626 " VALUES(?, ?, ?, ?, ?)"; | 646 " VALUES(?, ?, ?, ?, ?)"; |
627 | 647 |
628 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 648 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
629 statement.BindInt64(0, record->cache_id); | 649 statement.BindInt64(0, record->cache_id); |
630 statement.BindString(1, record->url.spec()); | 650 statement.BindString(1, record->url.spec()); |
631 statement.BindInt(2, record->flags); | 651 statement.BindInt(2, record->flags); |
632 statement.BindInt64(3, record->response_id); | 652 statement.BindInt64(3, record->response_id); |
633 statement.BindInt64(4, record->response_size); | 653 statement.BindInt64(4, record->response_size); |
634 | 654 |
(...skipping 13 matching lines...) Expand all Loading... | |
648 return false; | 668 return false; |
649 ++iter; | 669 ++iter; |
650 } | 670 } |
651 return transaction.Commit(); | 671 return transaction.Commit(); |
652 } | 672 } |
653 | 673 |
654 bool AppCacheDatabase::DeleteEntriesForCache(int64 cache_id) { | 674 bool AppCacheDatabase::DeleteEntriesForCache(int64 cache_id) { |
655 if (!LazyOpen(false)) | 675 if (!LazyOpen(false)) |
656 return false; | 676 return false; |
657 | 677 |
658 const char* kSql = | 678 const char kSql[] = |
659 "DELETE FROM Entries WHERE cache_id = ?"; | 679 "DELETE FROM Entries WHERE cache_id = ?"; |
660 | 680 |
661 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 681 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
662 statement.BindInt64(0, cache_id); | 682 statement.BindInt64(0, cache_id); |
663 | 683 |
664 return statement.Run(); | 684 return statement.Run(); |
665 } | 685 } |
666 | 686 |
667 bool AppCacheDatabase::AddEntryFlags( | 687 bool AppCacheDatabase::AddEntryFlags( |
668 const GURL& entry_url, int64 cache_id, int additional_flags) { | 688 const GURL& entry_url, int64 cache_id, int additional_flags) { |
669 if (!LazyOpen(false)) | 689 if (!LazyOpen(false)) |
670 return false; | 690 return false; |
671 | 691 |
672 const char* kSql = | 692 const char kSql[] = |
673 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; | 693 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; |
674 | 694 |
675 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 695 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
676 statement.BindInt(0, additional_flags); | 696 statement.BindInt(0, additional_flags); |
677 statement.BindInt64(1, cache_id); | 697 statement.BindInt64(1, cache_id); |
678 statement.BindString(2, entry_url.spec()); | 698 statement.BindString(2, entry_url.spec()); |
679 | 699 |
680 return statement.Run() && db_->GetLastChangeCount(); | 700 return statement.Run() && db_->GetLastChangeCount(); |
681 } | 701 } |
682 | 702 |
683 bool AppCacheDatabase::FindNamespacesForOrigin( | 703 bool AppCacheDatabase::FindNamespacesForOrigin( |
684 const GURL& origin, | 704 const GURL& origin, |
685 std::vector<NamespaceRecord>* intercepts, | 705 std::vector<NamespaceRecord>* intercepts, |
686 std::vector<NamespaceRecord>* fallbacks) { | 706 std::vector<NamespaceRecord>* fallbacks) { |
687 DCHECK(intercepts && intercepts->empty()); | 707 DCHECK(intercepts && intercepts->empty()); |
688 DCHECK(fallbacks && fallbacks->empty()); | 708 DCHECK(fallbacks && fallbacks->empty()); |
689 if (!LazyOpen(false)) | 709 if (!LazyOpen(false)) |
690 return false; | 710 return false; |
691 | 711 |
692 const char* kSql = | 712 const char kSql[] = |
693 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" | 713 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" |
694 " FROM Namespaces WHERE origin = ?"; | 714 " FROM Namespaces WHERE origin = ?"; |
695 | 715 |
696 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 716 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
697 statement.BindString(0, origin.spec()); | 717 statement.BindString(0, origin.spec()); |
698 | 718 |
699 ReadNamespaceRecords(&statement, intercepts, fallbacks); | 719 ReadNamespaceRecords(&statement, intercepts, fallbacks); |
700 | 720 |
701 return statement.Succeeded(); | 721 return statement.Succeeded(); |
702 } | 722 } |
703 | 723 |
704 bool AppCacheDatabase::FindNamespacesForCache( | 724 bool AppCacheDatabase::FindNamespacesForCache( |
705 int64 cache_id, | 725 int64 cache_id, |
706 std::vector<NamespaceRecord>* intercepts, | 726 std::vector<NamespaceRecord>* intercepts, |
707 std::vector<NamespaceRecord>* fallbacks) { | 727 std::vector<NamespaceRecord>* fallbacks) { |
708 DCHECK(intercepts && intercepts->empty()); | 728 DCHECK(intercepts && intercepts->empty()); |
709 DCHECK(fallbacks && fallbacks->empty()); | 729 DCHECK(fallbacks && fallbacks->empty()); |
710 if (!LazyOpen(false)) | 730 if (!LazyOpen(false)) |
711 return false; | 731 return false; |
712 | 732 |
713 const char* kSql = | 733 const char kSql[] = |
714 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" | 734 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" |
715 " FROM Namespaces WHERE cache_id = ?"; | 735 " FROM Namespaces WHERE cache_id = ?"; |
716 | 736 |
717 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 737 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
718 statement.BindInt64(0, cache_id); | 738 statement.BindInt64(0, cache_id); |
719 | 739 |
720 ReadNamespaceRecords(&statement, intercepts, fallbacks); | 740 ReadNamespaceRecords(&statement, intercepts, fallbacks); |
721 | 741 |
722 return statement.Succeeded(); | 742 return statement.Succeeded(); |
723 } | 743 } |
724 | 744 |
725 bool AppCacheDatabase::InsertNamespace( | 745 bool AppCacheDatabase::InsertNamespace( |
726 const NamespaceRecord* record) { | 746 const NamespaceRecord* record) { |
727 if (!LazyOpen(true)) | 747 if (!LazyOpen(true)) |
728 return false; | 748 return false; |
729 | 749 |
730 const char* kSql = | 750 const char kSql[] = |
731 "INSERT INTO Namespaces" | 751 "INSERT INTO Namespaces" |
732 " (cache_id, origin, type, namespace_url, target_url, is_pattern)" | 752 " (cache_id, origin, type, namespace_url, target_url, is_pattern)" |
733 " VALUES (?, ?, ?, ?, ?, ?)"; | 753 " VALUES (?, ?, ?, ?, ?, ?)"; |
734 | 754 |
735 // Note: quick and dirty storage for the 'executable' bit w/o changing | 755 // Note: quick and dirty storage for the 'executable' bit w/o changing |
736 // schemas, we use the high bit of 'type' field. | 756 // schemas, we use the high bit of 'type' field. |
737 int type_with_executable_bit = record->namespace_.type; | 757 int type_with_executable_bit = record->namespace_.type; |
738 if (record->namespace_.is_executable) { | 758 if (record->namespace_.is_executable) { |
739 type_with_executable_bit |= 0x8000000; | 759 type_with_executable_bit |= 0x8000000; |
740 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 760 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 23 matching lines...) Expand all Loading... | |
764 return false; | 784 return false; |
765 ++iter; | 785 ++iter; |
766 } | 786 } |
767 return transaction.Commit(); | 787 return transaction.Commit(); |
768 } | 788 } |
769 | 789 |
770 bool AppCacheDatabase::DeleteNamespacesForCache(int64 cache_id) { | 790 bool AppCacheDatabase::DeleteNamespacesForCache(int64 cache_id) { |
771 if (!LazyOpen(false)) | 791 if (!LazyOpen(false)) |
772 return false; | 792 return false; |
773 | 793 |
774 const char* kSql = | 794 const char kSql[] = |
775 "DELETE FROM Namespaces WHERE cache_id = ?"; | 795 "DELETE FROM Namespaces WHERE cache_id = ?"; |
776 | 796 |
777 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 797 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
778 statement.BindInt64(0, cache_id); | 798 statement.BindInt64(0, cache_id); |
779 | 799 |
780 return statement.Run(); | 800 return statement.Run(); |
781 } | 801 } |
782 | 802 |
783 bool AppCacheDatabase::FindOnlineWhiteListForCache( | 803 bool AppCacheDatabase::FindOnlineWhiteListForCache( |
784 int64 cache_id, std::vector<OnlineWhiteListRecord>* records) { | 804 int64 cache_id, std::vector<OnlineWhiteListRecord>* records) { |
785 DCHECK(records && records->empty()); | 805 DCHECK(records && records->empty()); |
786 if (!LazyOpen(false)) | 806 if (!LazyOpen(false)) |
787 return false; | 807 return false; |
788 | 808 |
789 const char* kSql = | 809 const char kSql[] = |
790 "SELECT cache_id, namespace_url, is_pattern FROM OnlineWhiteLists" | 810 "SELECT cache_id, namespace_url, is_pattern FROM OnlineWhiteLists" |
791 " WHERE cache_id = ?"; | 811 " WHERE cache_id = ?"; |
792 | 812 |
793 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 813 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
794 statement.BindInt64(0, cache_id); | 814 statement.BindInt64(0, cache_id); |
795 | 815 |
796 while (statement.Step()) { | 816 while (statement.Step()) { |
797 records->push_back(OnlineWhiteListRecord()); | 817 records->push_back(OnlineWhiteListRecord()); |
798 this->ReadOnlineWhiteListRecord(statement, &records->back()); | 818 this->ReadOnlineWhiteListRecord(statement, &records->back()); |
799 DCHECK(records->back().cache_id == cache_id); | 819 DCHECK(records->back().cache_id == cache_id); |
800 } | 820 } |
801 return statement.Succeeded(); | 821 return statement.Succeeded(); |
802 } | 822 } |
803 | 823 |
804 bool AppCacheDatabase::InsertOnlineWhiteList( | 824 bool AppCacheDatabase::InsertOnlineWhiteList( |
805 const OnlineWhiteListRecord* record) { | 825 const OnlineWhiteListRecord* record) { |
806 if (!LazyOpen(true)) | 826 if (!LazyOpen(true)) |
807 return false; | 827 return false; |
808 | 828 |
809 const char* kSql = | 829 const char kSql[] = |
810 "INSERT INTO OnlineWhiteLists (cache_id, namespace_url, is_pattern)" | 830 "INSERT INTO OnlineWhiteLists (cache_id, namespace_url, is_pattern)" |
811 " VALUES (?, ?, ?)"; | 831 " VALUES (?, ?, ?)"; |
812 | 832 |
813 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 833 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
814 statement.BindInt64(0, record->cache_id); | 834 statement.BindInt64(0, record->cache_id); |
815 statement.BindString(1, record->namespace_url.spec()); | 835 statement.BindString(1, record->namespace_url.spec()); |
816 statement.BindBool(2, record->is_pattern); | 836 statement.BindBool(2, record->is_pattern); |
817 | 837 |
818 return statement.Run(); | 838 return statement.Run(); |
819 } | 839 } |
(...skipping 11 matching lines...) Expand all Loading... | |
831 return false; | 851 return false; |
832 ++iter; | 852 ++iter; |
833 } | 853 } |
834 return transaction.Commit(); | 854 return transaction.Commit(); |
835 } | 855 } |
836 | 856 |
837 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64 cache_id) { | 857 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64 cache_id) { |
838 if (!LazyOpen(false)) | 858 if (!LazyOpen(false)) |
839 return false; | 859 return false; |
840 | 860 |
841 const char* kSql = | 861 const char kSql[] = |
842 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; | 862 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; |
843 | 863 |
844 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 864 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
845 statement.BindInt64(0, cache_id); | 865 statement.BindInt64(0, cache_id); |
846 | 866 |
847 return statement.Run(); | 867 return statement.Run(); |
848 } | 868 } |
849 | 869 |
850 bool AppCacheDatabase::GetDeletableResponseIds( | 870 bool AppCacheDatabase::GetDeletableResponseIds( |
851 std::vector<int64>* response_ids, int64 max_rowid, int limit) { | 871 std::vector<int64>* response_ids, int64 max_rowid, int limit) { |
852 if (!LazyOpen(false)) | 872 if (!LazyOpen(false)) |
853 return false; | 873 return false; |
854 | 874 |
855 const char* kSql = | 875 const char kSql[] = |
856 "SELECT response_id FROM DeletableResponseIds " | 876 "SELECT response_id FROM DeletableResponseIds " |
857 " WHERE rowid <= ?" | 877 " WHERE rowid <= ?" |
858 " LIMIT ?"; | 878 " LIMIT ?"; |
859 | 879 |
860 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 880 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
861 statement.BindInt64(0, max_rowid); | 881 statement.BindInt64(0, max_rowid); |
862 statement.BindInt64(1, limit); | 882 statement.BindInt64(1, limit); |
863 | 883 |
864 while (statement.Step()) | 884 while (statement.Step()) |
865 response_ids->push_back(statement.ColumnInt64(0)); | 885 response_ids->push_back(statement.ColumnInt64(0)); |
866 return statement.Succeeded(); | 886 return statement.Succeeded(); |
867 } | 887 } |
868 | 888 |
869 bool AppCacheDatabase::InsertDeletableResponseIds( | 889 bool AppCacheDatabase::InsertDeletableResponseIds( |
870 const std::vector<int64>& response_ids) { | 890 const std::vector<int64>& response_ids) { |
871 const char* kSql = | 891 const char kSql[] = |
872 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; | 892 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; |
873 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); | 893 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); |
874 } | 894 } |
875 | 895 |
876 bool AppCacheDatabase::DeleteDeletableResponseIds( | 896 bool AppCacheDatabase::DeleteDeletableResponseIds( |
877 const std::vector<int64>& response_ids) { | 897 const std::vector<int64>& response_ids) { |
878 const char* kSql = | 898 const char kSql[] = |
879 "DELETE FROM DeletableResponseIds WHERE response_id = ?"; | 899 "DELETE FROM DeletableResponseIds WHERE response_id = ?"; |
880 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); | 900 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); |
881 } | 901 } |
882 | 902 |
883 bool AppCacheDatabase::RunCachedStatementWithIds( | 903 bool AppCacheDatabase::RunCachedStatementWithIds( |
884 const sql::StatementID& statement_id, const char* sql, | 904 const sql::StatementID& statement_id, const char* sql, |
885 const std::vector<int64>& ids) { | 905 const std::vector<int64>& ids) { |
886 DCHECK(sql); | 906 DCHECK(sql); |
887 if (!LazyOpen(true)) | 907 if (!LazyOpen(true)) |
888 return false; | 908 return false; |
(...skipping 28 matching lines...) Expand all Loading... | |
917 } | 937 } |
918 | 938 |
919 bool AppCacheDatabase::FindResponseIdsForCacheHelper( | 939 bool AppCacheDatabase::FindResponseIdsForCacheHelper( |
920 int64 cache_id, std::vector<int64>* ids_vector, | 940 int64 cache_id, std::vector<int64>* ids_vector, |
921 std::set<int64>* ids_set) { | 941 std::set<int64>* ids_set) { |
922 DCHECK(ids_vector || ids_set); | 942 DCHECK(ids_vector || ids_set); |
923 DCHECK(!(ids_vector && ids_set)); | 943 DCHECK(!(ids_vector && ids_set)); |
924 if (!LazyOpen(false)) | 944 if (!LazyOpen(false)) |
925 return false; | 945 return false; |
926 | 946 |
927 const char* kSql = | 947 const char kSql[] = |
928 "SELECT response_id FROM Entries WHERE cache_id = ?"; | 948 "SELECT response_id FROM Entries WHERE cache_id = ?"; |
929 | 949 |
930 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 950 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
931 | 951 |
932 statement.BindInt64(0, cache_id); | 952 statement.BindInt64(0, cache_id); |
933 while (statement.Step()) { | 953 while (statement.Step()) { |
934 int64 id = statement.ColumnInt64(0); | 954 int64 id = statement.ColumnInt64(0); |
935 if (ids_set) | 955 if (ids_set) |
936 ids_set->insert(id); | 956 ids_set->insert(id); |
937 else | 957 else |
(...skipping 11 matching lines...) Expand all Loading... | |
949 record->creation_time = | 969 record->creation_time = |
950 base::Time::FromInternalValue(statement.ColumnInt64(3)); | 970 base::Time::FromInternalValue(statement.ColumnInt64(3)); |
951 | 971 |
952 const auto found = lazy_last_access_times_.find(record->group_id); | 972 const auto found = lazy_last_access_times_.find(record->group_id); |
953 if (found != lazy_last_access_times_.end()) { | 973 if (found != lazy_last_access_times_.end()) { |
954 record->last_access_time = found->second; | 974 record->last_access_time = found->second; |
955 } else { | 975 } else { |
956 record->last_access_time = | 976 record->last_access_time = |
957 base::Time::FromInternalValue(statement.ColumnInt64(4)); | 977 base::Time::FromInternalValue(statement.ColumnInt64(4)); |
958 } | 978 } |
979 | |
980 record->last_full_update_check_time = | |
981 base::Time::FromInternalValue(statement.ColumnInt64(5)); | |
982 record->first_evictable_error_time = | |
983 base::Time::FromInternalValue(statement.ColumnInt64(6)); | |
959 } | 984 } |
960 | 985 |
961 void AppCacheDatabase::ReadCacheRecord( | 986 void AppCacheDatabase::ReadCacheRecord( |
962 const sql::Statement& statement, CacheRecord* record) { | 987 const sql::Statement& statement, CacheRecord* record) { |
963 record->cache_id = statement.ColumnInt64(0); | 988 record->cache_id = statement.ColumnInt64(0); |
964 record->group_id = statement.ColumnInt64(1); | 989 record->group_id = statement.ColumnInt64(1); |
965 record->online_wildcard = statement.ColumnBool(2); | 990 record->online_wildcard = statement.ColumnBool(2); |
966 record->update_time = | 991 record->update_time = |
967 base::Time::FromInternalValue(statement.ColumnInt64(3)); | 992 base::Time::FromInternalValue(statement.ColumnInt64(3)); |
968 record->cache_size = statement.ColumnInt64(4); | 993 record->cache_size = statement.ColumnInt64(4); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 for (int i = 0; i < kIndexCount; ++i) { | 1152 for (int i = 0; i < kIndexCount; ++i) { |
1128 if (!CreateIndex(db_.get(), kIndexes[i])) | 1153 if (!CreateIndex(db_.get(), kIndexes[i])) |
1129 return false; | 1154 return false; |
1130 } | 1155 } |
1131 | 1156 |
1132 return transaction.Commit(); | 1157 return transaction.Commit(); |
1133 } | 1158 } |
1134 | 1159 |
1135 bool AppCacheDatabase::UpgradeSchema() { | 1160 bool AppCacheDatabase::UpgradeSchema() { |
1136 #if defined(APPCACHE_USE_SIMPLE_CACHE) | 1161 #if defined(APPCACHE_USE_SIMPLE_CACHE) |
1137 return DeleteExistingAndCreateNewDatabase(); | 1162 if (meta_table_->GetVersionNumber() < 6) |
1138 #else | 1163 return DeleteExistingAndCreateNewDatabase(); |
1164 #endif | |
1139 if (meta_table_->GetVersionNumber() == 3) { | 1165 if (meta_table_->GetVersionNumber() == 3) { |
1140 // version 3 was pre 12/17/2011 | 1166 // version 3 was pre 12/17/2011 |
1141 DCHECK_EQ(strcmp(kNamespacesTable, kTables[3].table_name), 0); | 1167 DCHECK_EQ(strcmp(kNamespacesTable, kTables[3].table_name), 0); |
1142 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[6].table_name), 0); | 1168 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[6].table_name), 0); |
1143 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[7].table_name), 0); | 1169 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[7].table_name), 0); |
1144 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[8].table_name), 0); | 1170 DCHECK_EQ(strcmp(kNamespacesTable, kIndexes[8].table_name), 0); |
1145 | 1171 |
1146 const TableInfo kNamespaceTable_v4 = { | 1172 const TableInfo kNamespaceTable_v4 = { |
1147 kNamespacesTable, | 1173 kNamespacesTable, |
1148 "(cache_id INTEGER," | 1174 "(cache_id INTEGER," |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1200 " is_pattern INTEGER CHECK(is_pattern IN (0, 1))")) { | 1226 " is_pattern INTEGER CHECK(is_pattern IN (0, 1))")) { |
1201 return false; | 1227 return false; |
1202 } | 1228 } |
1203 if (!db_->Execute( | 1229 if (!db_->Execute( |
1204 "ALTER TABLE OnlineWhitelists ADD COLUMN" | 1230 "ALTER TABLE OnlineWhitelists ADD COLUMN" |
1205 " is_pattern INTEGER CHECK(is_pattern IN (0, 1))")) { | 1231 " is_pattern INTEGER CHECK(is_pattern IN (0, 1))")) { |
1206 return false; | 1232 return false; |
1207 } | 1233 } |
1208 meta_table_->SetVersionNumber(5); | 1234 meta_table_->SetVersionNumber(5); |
1209 meta_table_->SetCompatibleVersionNumber(5); | 1235 meta_table_->SetCompatibleVersionNumber(5); |
1236 if (!transaction.Commit()) | |
1237 return false; | |
1238 } | |
1239 | |
1240 #if defined(APPCACHE_USE_SIMPLE_CACHE) | |
1241 // The schema version number was increased to 6 when we switched to the | |
1242 // SimpleCache for Android, but the SQL part of the schema is identical | |
1243 // to v5 on desktop chrome. | |
1244 if (meta_table_->GetVersionNumber() == 6) { | |
1245 #else | |
1246 if (meta_table_->GetVersionNumber() == 5) { | |
1247 #endif | |
1248 // Versions 5 and 6 were pre-May 2015. | |
jsbell
2015/07/07 00:18:59
Bump to July ?
| |
1249 // Version 7 adds support for expiring caches that are failing to update. | |
1250 sql::Transaction transaction(db_.get()); | |
1251 if (!transaction.Begin() || | |
1252 !db_->Execute( | |
1253 "ALTER TABLE Groups ADD COLUMN" | |
1254 " last_full_update_check_time INTEGER") || | |
1255 !db_->Execute( | |
1256 "ALTER TABLE Groups ADD COLUMN" | |
1257 " first_evictable_error_time INTEGER") || | |
1258 !db_->Execute( | |
1259 "UPDATE Groups" | |
1260 " SET last_full_update_check_time =" | |
1261 " (SELECT update_time FROM Caches" | |
1262 " WHERE Caches.group_id = Groups.group_id)")) { | |
1263 return false; | |
1264 } | |
1265 meta_table_->SetVersionNumber(7); | |
1266 meta_table_->SetCompatibleVersionNumber(7); | |
1210 return transaction.Commit(); | 1267 return transaction.Commit(); |
1211 } | 1268 } |
1212 | 1269 |
1213 // If there is no upgrade path for the version on disk to the current | 1270 // If there is no upgrade path for the version on disk to the current |
1214 // version, nuke everything and start over. | 1271 // version, nuke everything and start over. |
1215 return DeleteExistingAndCreateNewDatabase(); | 1272 return DeleteExistingAndCreateNewDatabase(); |
1216 #endif | |
1217 } | 1273 } |
1218 | 1274 |
1219 void AppCacheDatabase::ResetConnectionAndTables() { | 1275 void AppCacheDatabase::ResetConnectionAndTables() { |
1220 meta_table_.reset(); | 1276 meta_table_.reset(); |
1221 db_.reset(); | 1277 db_.reset(); |
1222 } | 1278 } |
1223 | 1279 |
1224 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { | 1280 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { |
1225 DCHECK(!db_file_path_.empty()); | 1281 DCHECK(!db_file_path_.empty()); |
1226 DCHECK(base::PathExists(db_file_path_)); | 1282 DCHECK(base::PathExists(db_file_path_)); |
(...skipping 22 matching lines...) Expand all Loading... | |
1249 } | 1305 } |
1250 | 1306 |
1251 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) { | 1307 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) { |
1252 was_corruption_detected_ |= sql::IsErrorCatastrophic(err); | 1308 was_corruption_detected_ |= sql::IsErrorCatastrophic(err); |
1253 if (!db_->ShouldIgnoreSqliteError(err)) | 1309 if (!db_->ShouldIgnoreSqliteError(err)) |
1254 DLOG(ERROR) << db_->GetErrorMessage(); | 1310 DLOG(ERROR) << db_->GetErrorMessage(); |
1255 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check? | 1311 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check? |
1256 } | 1312 } |
1257 | 1313 |
1258 } // namespace content | 1314 } // namespace content |
OLD | NEW |