| 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/appcache/appcache_database.h" | 5 #include "webkit/appcache/appcache_database.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { | 235 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { |
| 236 DCHECK(origins && origins->empty()); | 236 DCHECK(origins && origins->empty()); |
| 237 if (!LazyOpen(false)) | 237 if (!LazyOpen(false)) |
| 238 return false; | 238 return false; |
| 239 | 239 |
| 240 const char* kSql = | 240 const char* kSql = |
| 241 "SELECT DISTINCT(origin) FROM Groups"; | 241 "SELECT DISTINCT(origin) FROM Groups"; |
| 242 | 242 |
| 243 sql::Statement statement; | 243 sql::Statement statement(db_->GetUniqueStatement(kSql)); |
| 244 if (!PrepareUniqueStatement(kSql, &statement)) | |
| 245 return false; | |
| 246 | 244 |
| 247 while (statement.Step()) | 245 while (statement.Step()) |
| 248 origins->insert(GURL(statement.ColumnString(0))); | 246 origins->insert(GURL(statement.ColumnString(0))); |
| 249 | 247 |
| 250 return statement.Succeeded(); | 248 return statement.Succeeded(); |
| 251 } | 249 } |
| 252 | 250 |
| 253 bool AppCacheDatabase::FindLastStorageIds( | 251 bool AppCacheDatabase::FindLastStorageIds( |
| 254 int64* last_group_id, int64* last_cache_id, int64* last_response_id, | 252 int64* last_group_id, int64* last_cache_id, int64* last_response_id, |
| 255 int64* last_deletable_response_rowid) { | 253 int64* last_deletable_response_rowid) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 bool AppCacheDatabase::FindGroup(int64 group_id, GroupRecord* record) { | 297 bool AppCacheDatabase::FindGroup(int64 group_id, GroupRecord* record) { |
| 300 DCHECK(record); | 298 DCHECK(record); |
| 301 if (!LazyOpen(false)) | 299 if (!LazyOpen(false)) |
| 302 return false; | 300 return false; |
| 303 | 301 |
| 304 const char* kSql = | 302 const char* kSql = |
| 305 "SELECT group_id, origin, manifest_url," | 303 "SELECT group_id, origin, manifest_url," |
| 306 " creation_time, last_access_time" | 304 " creation_time, last_access_time" |
| 307 " FROM Groups WHERE group_id = ?"; | 305 " FROM Groups WHERE group_id = ?"; |
| 308 | 306 |
| 309 sql::Statement statement; | 307 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 310 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 311 return false; | |
| 312 | 308 |
| 313 statement.BindInt64(0, group_id); | 309 statement.BindInt64(0, group_id); |
| 314 if (!statement.Step() || !statement.Succeeded()) | 310 if (!statement.Step()) |
| 315 return false; | 311 return false; |
| 316 | 312 |
| 317 ReadGroupRecord(statement, record); | 313 ReadGroupRecord(statement, record); |
| 318 DCHECK(record->group_id == group_id); | 314 DCHECK(record->group_id == group_id); |
| 319 return true; | 315 return true; |
| 320 } | 316 } |
| 321 | 317 |
| 322 bool AppCacheDatabase::FindGroupForManifestUrl( | 318 bool AppCacheDatabase::FindGroupForManifestUrl( |
| 323 const GURL& manifest_url, GroupRecord* record) { | 319 const GURL& manifest_url, GroupRecord* record) { |
| 324 DCHECK(record); | 320 DCHECK(record); |
| 325 if (!LazyOpen(false)) | 321 if (!LazyOpen(false)) |
| 326 return false; | 322 return false; |
| 327 | 323 |
| 328 const char* kSql = | 324 const char* kSql = |
| 329 "SELECT group_id, origin, manifest_url," | 325 "SELECT group_id, origin, manifest_url," |
| 330 " creation_time, last_access_time" | 326 " creation_time, last_access_time" |
| 331 " FROM Groups WHERE manifest_url = ?"; | 327 " FROM Groups WHERE manifest_url = ?"; |
| 332 | 328 |
| 333 sql::Statement statement; | 329 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 334 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 330 statement.BindString(0, manifest_url.spec()); |
| 335 return false; | |
| 336 | 331 |
| 337 statement.BindString(0, manifest_url.spec()); | 332 if (!statement.Step()) |
| 338 if (!statement.Step() || !statement.Succeeded()) | |
| 339 return false; | 333 return false; |
| 340 | 334 |
| 341 ReadGroupRecord(statement, record); | 335 ReadGroupRecord(statement, record); |
| 342 DCHECK(record->manifest_url == manifest_url); | 336 DCHECK(record->manifest_url == manifest_url); |
| 343 return true; | 337 return true; |
| 344 } | 338 } |
| 345 | 339 |
| 346 bool AppCacheDatabase::FindGroupsForOrigin( | 340 bool AppCacheDatabase::FindGroupsForOrigin( |
| 347 const GURL& origin, std::vector<GroupRecord>* records) { | 341 const GURL& origin, std::vector<GroupRecord>* records) { |
| 348 DCHECK(records && records->empty()); | 342 DCHECK(records && records->empty()); |
| 349 if (!LazyOpen(false)) | 343 if (!LazyOpen(false)) |
| 350 return false; | 344 return false; |
| 351 | 345 |
| 352 const char* kSql = | 346 const char* kSql = |
| 353 "SELECT group_id, origin, manifest_url," | 347 "SELECT group_id, origin, manifest_url," |
| 354 " creation_time, last_access_time" | 348 " creation_time, last_access_time" |
| 355 " FROM Groups WHERE origin = ?"; | 349 " FROM Groups WHERE origin = ?"; |
| 356 | 350 |
| 357 sql::Statement statement; | 351 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 358 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 352 statement.BindString(0, origin.spec()); |
| 359 return false; | |
| 360 | 353 |
| 361 statement.BindString(0, origin.spec()); | |
| 362 while (statement.Step()) { | 354 while (statement.Step()) { |
| 363 records->push_back(GroupRecord()); | 355 records->push_back(GroupRecord()); |
| 364 ReadGroupRecord(statement, &records->back()); | 356 ReadGroupRecord(statement, &records->back()); |
| 365 DCHECK(records->back().origin == origin); | 357 DCHECK(records->back().origin == origin); |
| 366 } | 358 } |
| 367 | 359 |
| 368 return statement.Succeeded(); | 360 return statement.Succeeded(); |
| 369 } | 361 } |
| 370 | 362 |
| 371 bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { | 363 bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { |
| 372 DCHECK(record); | 364 DCHECK(record); |
| 373 if (!LazyOpen(false)) | 365 if (!LazyOpen(false)) |
| 374 return false; | 366 return false; |
| 375 | 367 |
| 376 const char* kSql = | 368 const char* kSql = |
| 377 "SELECT g.group_id, g.origin, g.manifest_url," | 369 "SELECT g.group_id, g.origin, g.manifest_url," |
| 378 " g.creation_time, g.last_access_time" | 370 " g.creation_time, g.last_access_time" |
| 379 " FROM Groups g, Caches c" | 371 " FROM Groups g, Caches c" |
| 380 " WHERE c.cache_id = ? AND c.group_id = g.group_id"; | 372 " WHERE c.cache_id = ? AND c.group_id = g.group_id"; |
| 381 | 373 |
| 382 sql::Statement statement; | 374 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 383 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 375 statement.BindInt64(0, cache_id); |
| 384 return false; | |
| 385 | 376 |
| 386 statement.BindInt64(0, cache_id); | 377 if (!statement.Step()) |
| 387 if (!statement.Step() || !statement.Succeeded()) | |
| 388 return false; | 378 return false; |
| 389 | 379 |
| 390 ReadGroupRecord(statement, record); | 380 ReadGroupRecord(statement, record); |
| 391 return true; | 381 return true; |
| 392 } | 382 } |
| 393 | 383 |
| 394 bool AppCacheDatabase::UpdateGroupLastAccessTime( | 384 bool AppCacheDatabase::UpdateGroupLastAccessTime( |
| 395 int64 group_id, base::Time time) { | 385 int64 group_id, base::Time time) { |
| 396 if (!LazyOpen(true)) | 386 if (!LazyOpen(true)) |
| 397 return false; | 387 return false; |
| 398 | 388 |
| 399 const char* kSql = | 389 const char* kSql = |
| 400 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; | 390 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; |
| 401 | 391 |
| 402 sql::Statement statement; | 392 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 403 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 404 return false; | |
| 405 | |
| 406 statement.BindInt64(0, time.ToInternalValue()); | 393 statement.BindInt64(0, time.ToInternalValue()); |
| 407 statement.BindInt64(1, group_id); | 394 statement.BindInt64(1, group_id); |
| 395 |
| 408 return statement.Run() && db_->GetLastChangeCount(); | 396 return statement.Run() && db_->GetLastChangeCount(); |
| 409 } | 397 } |
| 410 | 398 |
| 411 bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { | 399 bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { |
| 412 if (!LazyOpen(true)) | 400 if (!LazyOpen(true)) |
| 413 return false; | 401 return false; |
| 414 | 402 |
| 415 const char* kSql = | 403 const char* kSql = |
| 416 "INSERT INTO Groups" | 404 "INSERT INTO Groups" |
| 417 " (group_id, origin, manifest_url, creation_time, last_access_time)" | 405 " (group_id, origin, manifest_url, creation_time, last_access_time)" |
| 418 " VALUES(?, ?, ?, ?, ?)"; | 406 " VALUES(?, ?, ?, ?, ?)"; |
| 419 | 407 |
| 420 sql::Statement statement; | 408 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 421 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 422 return false; | |
| 423 | |
| 424 statement.BindInt64(0, record->group_id); | 409 statement.BindInt64(0, record->group_id); |
| 425 statement.BindString(1, record->origin.spec()); | 410 statement.BindString(1, record->origin.spec()); |
| 426 statement.BindString(2, record->manifest_url.spec()); | 411 statement.BindString(2, record->manifest_url.spec()); |
| 427 statement.BindInt64(3, record->creation_time.ToInternalValue()); | 412 statement.BindInt64(3, record->creation_time.ToInternalValue()); |
| 428 statement.BindInt64(4, record->last_access_time.ToInternalValue()); | 413 statement.BindInt64(4, record->last_access_time.ToInternalValue()); |
| 414 |
| 429 return statement.Run(); | 415 return statement.Run(); |
| 430 } | 416 } |
| 431 | 417 |
| 432 bool AppCacheDatabase::DeleteGroup(int64 group_id) { | 418 bool AppCacheDatabase::DeleteGroup(int64 group_id) { |
| 433 if (!LazyOpen(false)) | 419 if (!LazyOpen(false)) |
| 434 return false; | 420 return false; |
| 435 | 421 |
| 436 const char* kSql = | 422 const char* kSql = |
| 437 "DELETE FROM Groups WHERE group_id = ?"; | 423 "DELETE FROM Groups WHERE group_id = ?"; |
| 438 | 424 |
| 439 sql::Statement statement; | 425 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 440 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 426 statement.BindInt64(0, group_id); |
| 441 return false; | |
| 442 | 427 |
| 443 statement.BindInt64(0, group_id); | |
| 444 return statement.Run(); | 428 return statement.Run(); |
| 445 } | 429 } |
| 446 | 430 |
| 447 bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) { | 431 bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) { |
| 448 DCHECK(record); | 432 DCHECK(record); |
| 449 if (!LazyOpen(false)) | 433 if (!LazyOpen(false)) |
| 450 return false; | 434 return false; |
| 451 | 435 |
| 452 const char* kSql = | 436 const char* kSql = |
| 453 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" | 437 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" |
| 454 " FROM Caches WHERE cache_id = ?"; | 438 " FROM Caches WHERE cache_id = ?"; |
| 455 | 439 |
| 456 sql::Statement statement; | 440 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 457 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 441 statement.BindInt64(0, cache_id); |
| 458 return false; | |
| 459 | 442 |
| 460 statement.BindInt64(0, cache_id); | 443 if (!statement.Step()) |
| 461 if (!statement.Step() || !statement.Succeeded()) | |
| 462 return false; | 444 return false; |
| 463 | 445 |
| 464 ReadCacheRecord(statement, record); | 446 ReadCacheRecord(statement, record); |
| 465 return true; | 447 return true; |
| 466 } | 448 } |
| 467 | 449 |
| 468 bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) { | 450 bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) { |
| 469 DCHECK(record); | 451 DCHECK(record); |
| 470 if (!LazyOpen(false)) | 452 if (!LazyOpen(false)) |
| 471 return false; | 453 return false; |
| 472 | 454 |
| 473 const char* kSql = | 455 const char* kSql = |
| 474 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" | 456 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" |
| 475 " FROM Caches WHERE group_id = ?"; | 457 " FROM Caches WHERE group_id = ?"; |
| 476 | 458 |
| 477 sql::Statement statement; | 459 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 478 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 460 statement.BindInt64(0, group_id); |
| 479 return false; | |
| 480 | 461 |
| 481 statement.BindInt64(0, group_id); | 462 if (!statement.Step()) |
| 482 if (!statement.Step() || !statement.Succeeded()) | |
| 483 return false; | 463 return false; |
| 484 | 464 |
| 485 ReadCacheRecord(statement, record); | 465 ReadCacheRecord(statement, record); |
| 486 return true; | 466 return true; |
| 487 } | 467 } |
| 488 | 468 |
| 489 bool AppCacheDatabase::FindCachesForOrigin( | 469 bool AppCacheDatabase::FindCachesForOrigin( |
| 490 const GURL& origin, std::vector<CacheRecord>* records) { | 470 const GURL& origin, std::vector<CacheRecord>* records) { |
| 491 DCHECK(records); | 471 DCHECK(records); |
| 492 std::vector<GroupRecord> group_records; | 472 std::vector<GroupRecord> group_records; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 505 | 485 |
| 506 bool AppCacheDatabase::InsertCache(const CacheRecord* record) { | 486 bool AppCacheDatabase::InsertCache(const CacheRecord* record) { |
| 507 if (!LazyOpen(true)) | 487 if (!LazyOpen(true)) |
| 508 return false; | 488 return false; |
| 509 | 489 |
| 510 const char* kSql = | 490 const char* kSql = |
| 511 "INSERT INTO Caches (cache_id, group_id, online_wildcard," | 491 "INSERT INTO Caches (cache_id, group_id, online_wildcard," |
| 512 " update_time, cache_size)" | 492 " update_time, cache_size)" |
| 513 " VALUES(?, ?, ?, ?, ?)"; | 493 " VALUES(?, ?, ?, ?, ?)"; |
| 514 | 494 |
| 515 sql::Statement statement; | 495 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 516 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 517 return false; | |
| 518 | |
| 519 statement.BindInt64(0, record->cache_id); | 496 statement.BindInt64(0, record->cache_id); |
| 520 statement.BindInt64(1, record->group_id); | 497 statement.BindInt64(1, record->group_id); |
| 521 statement.BindBool(2, record->online_wildcard); | 498 statement.BindBool(2, record->online_wildcard); |
| 522 statement.BindInt64(3, record->update_time.ToInternalValue()); | 499 statement.BindInt64(3, record->update_time.ToInternalValue()); |
| 523 statement.BindInt64(4, record->cache_size); | 500 statement.BindInt64(4, record->cache_size); |
| 501 |
| 524 return statement.Run(); | 502 return statement.Run(); |
| 525 } | 503 } |
| 526 | 504 |
| 527 bool AppCacheDatabase::DeleteCache(int64 cache_id) { | 505 bool AppCacheDatabase::DeleteCache(int64 cache_id) { |
| 528 if (!LazyOpen(false)) | 506 if (!LazyOpen(false)) |
| 529 return false; | 507 return false; |
| 530 | 508 |
| 531 const char* kSql = | 509 const char* kSql = |
| 532 "DELETE FROM Caches WHERE cache_id = ?"; | 510 "DELETE FROM Caches WHERE cache_id = ?"; |
| 533 | 511 |
| 534 sql::Statement statement; | 512 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 535 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 513 statement.BindInt64(0, cache_id); |
| 536 return false; | |
| 537 | 514 |
| 538 statement.BindInt64(0, cache_id); | |
| 539 return statement.Run(); | 515 return statement.Run(); |
| 540 } | 516 } |
| 541 | 517 |
| 542 bool AppCacheDatabase::FindEntriesForCache( | 518 bool AppCacheDatabase::FindEntriesForCache( |
| 543 int64 cache_id, std::vector<EntryRecord>* records) { | 519 int64 cache_id, std::vector<EntryRecord>* records) { |
| 544 DCHECK(records && records->empty()); | 520 DCHECK(records && records->empty()); |
| 545 if (!LazyOpen(false)) | 521 if (!LazyOpen(false)) |
| 546 return false; | 522 return false; |
| 547 | 523 |
| 548 const char* kSql = | 524 const char* kSql = |
| 549 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 525 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
| 550 " WHERE cache_id = ?"; | 526 " WHERE cache_id = ?"; |
| 551 | 527 |
| 552 sql::Statement statement; | 528 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 553 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 529 statement.BindInt64(0, cache_id); |
| 554 return false; | |
| 555 | 530 |
| 556 statement.BindInt64(0, cache_id); | |
| 557 while (statement.Step()) { | 531 while (statement.Step()) { |
| 558 records->push_back(EntryRecord()); | 532 records->push_back(EntryRecord()); |
| 559 ReadEntryRecord(statement, &records->back()); | 533 ReadEntryRecord(statement, &records->back()); |
| 560 DCHECK(records->back().cache_id == cache_id); | 534 DCHECK(records->back().cache_id == cache_id); |
| 561 } | 535 } |
| 562 | 536 |
| 563 return statement.Succeeded(); | 537 return statement.Succeeded(); |
| 564 } | 538 } |
| 565 | 539 |
| 566 bool AppCacheDatabase::FindEntriesForUrl( | 540 bool AppCacheDatabase::FindEntriesForUrl( |
| 567 const GURL& url, std::vector<EntryRecord>* records) { | 541 const GURL& url, std::vector<EntryRecord>* records) { |
| 568 DCHECK(records && records->empty()); | 542 DCHECK(records && records->empty()); |
| 569 if (!LazyOpen(false)) | 543 if (!LazyOpen(false)) |
| 570 return false; | 544 return false; |
| 571 | 545 |
| 572 const char* kSql = | 546 const char* kSql = |
| 573 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 547 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
| 574 " WHERE url = ?"; | 548 " WHERE url = ?"; |
| 575 | 549 |
| 576 sql::Statement statement; | 550 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 577 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 551 statement.BindString(0, url.spec()); |
| 578 return false; | |
| 579 | 552 |
| 580 statement.BindString(0, url.spec()); | |
| 581 while (statement.Step()) { | 553 while (statement.Step()) { |
| 582 records->push_back(EntryRecord()); | 554 records->push_back(EntryRecord()); |
| 583 ReadEntryRecord(statement, &records->back()); | 555 ReadEntryRecord(statement, &records->back()); |
| 584 DCHECK(records->back().url == url); | 556 DCHECK(records->back().url == url); |
| 585 } | 557 } |
| 586 | 558 |
| 587 return statement.Succeeded(); | 559 return statement.Succeeded(); |
| 588 } | 560 } |
| 589 | 561 |
| 590 bool AppCacheDatabase::FindEntry( | 562 bool AppCacheDatabase::FindEntry( |
| 591 int64 cache_id, const GURL& url, EntryRecord* record) { | 563 int64 cache_id, const GURL& url, EntryRecord* record) { |
| 592 DCHECK(record); | 564 DCHECK(record); |
| 593 if (!LazyOpen(false)) | 565 if (!LazyOpen(false)) |
| 594 return false; | 566 return false; |
| 595 | 567 |
| 596 const char* kSql = | 568 const char* kSql = |
| 597 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" | 569 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" |
| 598 " WHERE cache_id = ? AND url = ?"; | 570 " WHERE cache_id = ? AND url = ?"; |
| 599 | 571 |
| 600 sql::Statement statement; | 572 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 601 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 602 return false; | |
| 603 | |
| 604 statement.BindInt64(0, cache_id); | 573 statement.BindInt64(0, cache_id); |
| 605 statement.BindString(1, url.spec()); | 574 statement.BindString(1, url.spec()); |
| 606 if (!statement.Step() || !statement.Succeeded()) | 575 |
| 576 if (!statement.Step()) |
| 607 return false; | 577 return false; |
| 608 | 578 |
| 609 ReadEntryRecord(statement, record); | 579 ReadEntryRecord(statement, record); |
| 610 DCHECK(record->cache_id == cache_id); | 580 DCHECK(record->cache_id == cache_id); |
| 611 DCHECK(record->url == url); | 581 DCHECK(record->url == url); |
| 612 return true; | 582 return true; |
| 613 } | 583 } |
| 614 | 584 |
| 615 bool AppCacheDatabase::InsertEntry(const EntryRecord* record) { | 585 bool AppCacheDatabase::InsertEntry(const EntryRecord* record) { |
| 616 if (!LazyOpen(true)) | 586 if (!LazyOpen(true)) |
| 617 return false; | 587 return false; |
| 618 | 588 |
| 619 const char* kSql = | 589 const char* kSql = |
| 620 "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)" | 590 "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)" |
| 621 " VALUES(?, ?, ?, ?, ?)"; | 591 " VALUES(?, ?, ?, ?, ?)"; |
| 622 | 592 |
| 623 sql::Statement statement; | 593 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 624 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 625 return false; | |
| 626 | |
| 627 statement.BindInt64(0, record->cache_id); | 594 statement.BindInt64(0, record->cache_id); |
| 628 statement.BindString(1, record->url.spec()); | 595 statement.BindString(1, record->url.spec()); |
| 629 statement.BindInt(2, record->flags); | 596 statement.BindInt(2, record->flags); |
| 630 statement.BindInt64(3, record->response_id); | 597 statement.BindInt64(3, record->response_id); |
| 631 statement.BindInt64(4, record->response_size); | 598 statement.BindInt64(4, record->response_size); |
| 599 |
| 632 return statement.Run(); | 600 return statement.Run(); |
| 633 } | 601 } |
| 634 | 602 |
| 635 bool AppCacheDatabase::InsertEntryRecords( | 603 bool AppCacheDatabase::InsertEntryRecords( |
| 636 const std::vector<EntryRecord>& records) { | 604 const std::vector<EntryRecord>& records) { |
| 637 if (records.empty()) | 605 if (records.empty()) |
| 638 return true; | 606 return true; |
| 639 sql::Transaction transaction(db_.get()); | 607 sql::Transaction transaction(db_.get()); |
| 640 if (!transaction.Begin()) | 608 if (!transaction.Begin()) |
| 641 return false; | 609 return false; |
| 642 std::vector<EntryRecord>::const_iterator iter = records.begin(); | 610 std::vector<EntryRecord>::const_iterator iter = records.begin(); |
| 643 while (iter != records.end()) { | 611 while (iter != records.end()) { |
| 644 if (!InsertEntry(&(*iter))) | 612 if (!InsertEntry(&(*iter))) |
| 645 return false; | 613 return false; |
| 646 ++iter; | 614 ++iter; |
| 647 } | 615 } |
| 648 return transaction.Commit(); | 616 return transaction.Commit(); |
| 649 } | 617 } |
| 650 | 618 |
| 651 bool AppCacheDatabase::DeleteEntriesForCache(int64 cache_id) { | 619 bool AppCacheDatabase::DeleteEntriesForCache(int64 cache_id) { |
| 652 if (!LazyOpen(false)) | 620 if (!LazyOpen(false)) |
| 653 return false; | 621 return false; |
| 654 | 622 |
| 655 const char* kSql = | 623 const char* kSql = |
| 656 "DELETE FROM Entries WHERE cache_id = ?"; | 624 "DELETE FROM Entries WHERE cache_id = ?"; |
| 657 | 625 |
| 658 sql::Statement statement; | 626 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 659 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 627 statement.BindInt64(0, cache_id); |
| 660 return false; | |
| 661 | 628 |
| 662 statement.BindInt64(0, cache_id); | |
| 663 return statement.Run(); | 629 return statement.Run(); |
| 664 } | 630 } |
| 665 | 631 |
| 666 bool AppCacheDatabase::AddEntryFlags( | 632 bool AppCacheDatabase::AddEntryFlags( |
| 667 const GURL& entry_url, int64 cache_id, int additional_flags) { | 633 const GURL& entry_url, int64 cache_id, int additional_flags) { |
| 668 if (!LazyOpen(false)) | 634 if (!LazyOpen(false)) |
| 669 return false; | 635 return false; |
| 670 | 636 |
| 671 const char* kSql = | 637 const char* kSql = |
| 672 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; | 638 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; |
| 673 | 639 |
| 674 sql::Statement statement; | 640 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 675 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 676 return false; | |
| 677 | |
| 678 statement.BindInt(0, additional_flags); | 641 statement.BindInt(0, additional_flags); |
| 679 statement.BindInt64(1, cache_id); | 642 statement.BindInt64(1, cache_id); |
| 680 statement.BindString(2, entry_url.spec()); | 643 statement.BindString(2, entry_url.spec()); |
| 644 |
| 681 return statement.Run() && db_->GetLastChangeCount(); | 645 return statement.Run() && db_->GetLastChangeCount(); |
| 682 } | 646 } |
| 683 | 647 |
| 684 bool AppCacheDatabase::FindNamespacesForOrigin( | 648 bool AppCacheDatabase::FindNamespacesForOrigin( |
| 685 const GURL& origin, | 649 const GURL& origin, |
| 686 std::vector<NamespaceRecord>* intercepts, | 650 std::vector<NamespaceRecord>* intercepts, |
| 687 std::vector<NamespaceRecord>* fallbacks) { | 651 std::vector<NamespaceRecord>* fallbacks) { |
| 688 DCHECK(intercepts && intercepts->empty()); | 652 DCHECK(intercepts && intercepts->empty()); |
| 689 DCHECK(fallbacks && fallbacks->empty()); | 653 DCHECK(fallbacks && fallbacks->empty()); |
| 690 if (!LazyOpen(false)) | 654 if (!LazyOpen(false)) |
| 691 return false; | 655 return false; |
| 692 | 656 |
| 693 const char* kSql = | 657 const char* kSql = |
| 694 "SELECT cache_id, origin, type, namespace_url, target_url" | 658 "SELECT cache_id, origin, type, namespace_url, target_url" |
| 695 " FROM Namespaces WHERE origin = ?"; | 659 " FROM Namespaces WHERE origin = ?"; |
| 696 | 660 |
| 697 sql::Statement statement; | 661 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 698 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 662 statement.BindString(0, origin.spec()); |
| 699 return false; | |
| 700 | 663 |
| 701 statement.BindString(0, origin.spec()); | |
| 702 ReadNamespaceRecords(&statement, intercepts, fallbacks); | 664 ReadNamespaceRecords(&statement, intercepts, fallbacks); |
| 665 |
| 703 return statement.Succeeded(); | 666 return statement.Succeeded(); |
| 704 } | 667 } |
| 705 | 668 |
| 706 bool AppCacheDatabase::FindNamespacesForCache( | 669 bool AppCacheDatabase::FindNamespacesForCache( |
| 707 int64 cache_id, | 670 int64 cache_id, |
| 708 std::vector<NamespaceRecord>* intercepts, | 671 std::vector<NamespaceRecord>* intercepts, |
| 709 std::vector<NamespaceRecord>* fallbacks) { | 672 std::vector<NamespaceRecord>* fallbacks) { |
| 710 DCHECK(intercepts && intercepts->empty()); | 673 DCHECK(intercepts && intercepts->empty()); |
| 711 DCHECK(fallbacks && fallbacks->empty()); | 674 DCHECK(fallbacks && fallbacks->empty()); |
| 712 if (!LazyOpen(false)) | 675 if (!LazyOpen(false)) |
| 713 return false; | 676 return false; |
| 714 | 677 |
| 715 const char* kSql = | 678 const char* kSql = |
| 716 "SELECT cache_id, origin, type, namespace_url, target_url" | 679 "SELECT cache_id, origin, type, namespace_url, target_url" |
| 717 " FROM Namespaces WHERE cache_id = ?"; | 680 " FROM Namespaces WHERE cache_id = ?"; |
| 718 | 681 |
| 719 sql::Statement statement; | 682 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 720 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 683 statement.BindInt64(0, cache_id); |
| 721 return false; | |
| 722 | 684 |
| 723 statement.BindInt64(0, cache_id); | |
| 724 ReadNamespaceRecords(&statement, intercepts, fallbacks); | 685 ReadNamespaceRecords(&statement, intercepts, fallbacks); |
| 686 |
| 725 return statement.Succeeded(); | 687 return statement.Succeeded(); |
| 726 } | 688 } |
| 727 | 689 |
| 728 bool AppCacheDatabase::InsertNamespace( | 690 bool AppCacheDatabase::InsertNamespace( |
| 729 const NamespaceRecord* record) { | 691 const NamespaceRecord* record) { |
| 730 if (!LazyOpen(true)) | 692 if (!LazyOpen(true)) |
| 731 return false; | 693 return false; |
| 732 | 694 |
| 733 const char* kSql = | 695 const char* kSql = |
| 734 "INSERT INTO Namespaces" | 696 "INSERT INTO Namespaces" |
| 735 " (cache_id, origin, type, namespace_url, target_url)" | 697 " (cache_id, origin, type, namespace_url, target_url)" |
| 736 " VALUES (?, ?, ?, ?, ?)"; | 698 " VALUES (?, ?, ?, ?, ?)"; |
| 737 | 699 |
| 738 sql::Statement statement; | 700 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 739 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 740 return false; | |
| 741 | |
| 742 statement.BindInt64(0, record->cache_id); | 701 statement.BindInt64(0, record->cache_id); |
| 743 statement.BindString(1, record->origin.spec()); | 702 statement.BindString(1, record->origin.spec()); |
| 744 statement.BindInt(2, record->type); | 703 statement.BindInt(2, record->type); |
| 745 statement.BindString(3, record->namespace_url.spec()); | 704 statement.BindString(3, record->namespace_url.spec()); |
| 746 statement.BindString(4, record->target_url.spec()); | 705 statement.BindString(4, record->target_url.spec()); |
| 706 |
| 747 return statement.Run(); | 707 return statement.Run(); |
| 748 } | 708 } |
| 749 | 709 |
| 750 bool AppCacheDatabase::InsertNamespaceRecords( | 710 bool AppCacheDatabase::InsertNamespaceRecords( |
| 751 const std::vector<NamespaceRecord>& records) { | 711 const std::vector<NamespaceRecord>& records) { |
| 752 if (records.empty()) | 712 if (records.empty()) |
| 753 return true; | 713 return true; |
| 754 sql::Transaction transaction(db_.get()); | 714 sql::Transaction transaction(db_.get()); |
| 755 if (!transaction.Begin()) | 715 if (!transaction.Begin()) |
| 756 return false; | 716 return false; |
| 757 std::vector<NamespaceRecord>::const_iterator iter = records.begin(); | 717 std::vector<NamespaceRecord>::const_iterator iter = records.begin(); |
| 758 while (iter != records.end()) { | 718 while (iter != records.end()) { |
| 759 if (!InsertNamespace(&(*iter))) | 719 if (!InsertNamespace(&(*iter))) |
| 760 return false; | 720 return false; |
| 761 ++iter; | 721 ++iter; |
| 762 } | 722 } |
| 763 return transaction.Commit(); | 723 return transaction.Commit(); |
| 764 } | 724 } |
| 765 | 725 |
| 766 bool AppCacheDatabase::DeleteNamespacesForCache(int64 cache_id) { | 726 bool AppCacheDatabase::DeleteNamespacesForCache(int64 cache_id) { |
| 767 if (!LazyOpen(false)) | 727 if (!LazyOpen(false)) |
| 768 return false; | 728 return false; |
| 769 | 729 |
| 770 const char* kSql = | 730 const char* kSql = |
| 771 "DELETE FROM Namespaces WHERE cache_id = ?"; | 731 "DELETE FROM Namespaces WHERE cache_id = ?"; |
| 772 | 732 |
| 773 sql::Statement statement; | 733 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 774 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 734 statement.BindInt64(0, cache_id); |
| 775 return false; | |
| 776 | 735 |
| 777 statement.BindInt64(0, cache_id); | |
| 778 return statement.Run(); | 736 return statement.Run(); |
| 779 } | 737 } |
| 780 | 738 |
| 781 bool AppCacheDatabase::FindOnlineWhiteListForCache( | 739 bool AppCacheDatabase::FindOnlineWhiteListForCache( |
| 782 int64 cache_id, std::vector<OnlineWhiteListRecord>* records) { | 740 int64 cache_id, std::vector<OnlineWhiteListRecord>* records) { |
| 783 DCHECK(records && records->empty()); | 741 DCHECK(records && records->empty()); |
| 784 if (!LazyOpen(false)) | 742 if (!LazyOpen(false)) |
| 785 return false; | 743 return false; |
| 786 | 744 |
| 787 const char* kSql = | 745 const char* kSql = |
| 788 "SELECT cache_id, namespace_url FROM OnlineWhiteLists" | 746 "SELECT cache_id, namespace_url FROM OnlineWhiteLists" |
| 789 " WHERE cache_id = ?"; | 747 " WHERE cache_id = ?"; |
| 790 | 748 |
| 791 sql::Statement statement; | 749 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 792 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 750 statement.BindInt64(0, cache_id); |
| 793 return false; | |
| 794 | 751 |
| 795 statement.BindInt64(0, cache_id); | |
| 796 while (statement.Step()) { | 752 while (statement.Step()) { |
| 797 records->push_back(OnlineWhiteListRecord()); | 753 records->push_back(OnlineWhiteListRecord()); |
| 798 this->ReadOnlineWhiteListRecord(statement, &records->back()); | 754 this->ReadOnlineWhiteListRecord(statement, &records->back()); |
| 799 DCHECK(records->back().cache_id == cache_id); | 755 DCHECK(records->back().cache_id == cache_id); |
| 800 } | 756 } |
| 801 return statement.Succeeded(); | 757 return statement.Succeeded(); |
| 802 } | 758 } |
| 803 | 759 |
| 804 bool AppCacheDatabase::InsertOnlineWhiteList( | 760 bool AppCacheDatabase::InsertOnlineWhiteList( |
| 805 const OnlineWhiteListRecord* record) { | 761 const OnlineWhiteListRecord* record) { |
| 806 if (!LazyOpen(true)) | 762 if (!LazyOpen(true)) |
| 807 return false; | 763 return false; |
| 808 | 764 |
| 809 const char* kSql = | 765 const char* kSql = |
| 810 "INSERT INTO OnlineWhiteLists (cache_id, namespace_url) VALUES (?, ?)"; | 766 "INSERT INTO OnlineWhiteLists (cache_id, namespace_url) VALUES (?, ?)"; |
| 811 | 767 |
| 812 sql::Statement statement; | 768 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 813 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 814 return false; | |
| 815 | |
| 816 statement.BindInt64(0, record->cache_id); | 769 statement.BindInt64(0, record->cache_id); |
| 817 statement.BindString(1, record->namespace_url.spec()); | 770 statement.BindString(1, record->namespace_url.spec()); |
| 771 |
| 818 return statement.Run(); | 772 return statement.Run(); |
| 819 } | 773 } |
| 820 | 774 |
| 821 bool AppCacheDatabase::InsertOnlineWhiteListRecords( | 775 bool AppCacheDatabase::InsertOnlineWhiteListRecords( |
| 822 const std::vector<OnlineWhiteListRecord>& records) { | 776 const std::vector<OnlineWhiteListRecord>& records) { |
| 823 if (records.empty()) | 777 if (records.empty()) |
| 824 return true; | 778 return true; |
| 825 sql::Transaction transaction(db_.get()); | 779 sql::Transaction transaction(db_.get()); |
| 826 if (!transaction.Begin()) | 780 if (!transaction.Begin()) |
| 827 return false; | 781 return false; |
| 828 std::vector<OnlineWhiteListRecord>::const_iterator iter = records.begin(); | 782 std::vector<OnlineWhiteListRecord>::const_iterator iter = records.begin(); |
| 829 while (iter != records.end()) { | 783 while (iter != records.end()) { |
| 830 if (!InsertOnlineWhiteList(&(*iter))) | 784 if (!InsertOnlineWhiteList(&(*iter))) |
| 831 return false; | 785 return false; |
| 832 ++iter; | 786 ++iter; |
| 833 } | 787 } |
| 834 return transaction.Commit(); | 788 return transaction.Commit(); |
| 835 } | 789 } |
| 836 | 790 |
| 837 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64 cache_id) { | 791 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64 cache_id) { |
| 838 if (!LazyOpen(false)) | 792 if (!LazyOpen(false)) |
| 839 return false; | 793 return false; |
| 840 | 794 |
| 841 const char* kSql = | 795 const char* kSql = |
| 842 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; | 796 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; |
| 843 | 797 |
| 844 sql::Statement statement; | 798 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 845 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | 799 statement.BindInt64(0, cache_id); |
| 846 return false; | |
| 847 | 800 |
| 848 statement.BindInt64(0, cache_id); | |
| 849 return statement.Run(); | 801 return statement.Run(); |
| 850 } | 802 } |
| 851 | 803 |
| 852 bool AppCacheDatabase::GetDeletableResponseIds( | 804 bool AppCacheDatabase::GetDeletableResponseIds( |
| 853 std::vector<int64>* response_ids, int64 max_rowid, int limit) { | 805 std::vector<int64>* response_ids, int64 max_rowid, int limit) { |
| 854 if (!LazyOpen(false)) | 806 if (!LazyOpen(false)) |
| 855 return false; | 807 return false; |
| 856 | 808 |
| 857 const char* kSql = | 809 const char* kSql = |
| 858 "SELECT response_id FROM DeletableResponseIds " | 810 "SELECT response_id FROM DeletableResponseIds " |
| 859 " WHERE rowid <= ?" | 811 " WHERE rowid <= ?" |
| 860 " LIMIT ?"; | 812 " LIMIT ?"; |
| 861 sql::Statement statement; | |
| 862 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 863 return false; | |
| 864 | 813 |
| 814 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 865 statement.BindInt64(0, max_rowid); | 815 statement.BindInt64(0, max_rowid); |
| 866 statement.BindInt64(1, limit); | 816 statement.BindInt64(1, limit); |
| 817 |
| 867 while (statement.Step()) | 818 while (statement.Step()) |
| 868 response_ids->push_back(statement.ColumnInt64(0)); | 819 response_ids->push_back(statement.ColumnInt64(0)); |
| 869 return statement.Succeeded(); | 820 return statement.Succeeded(); |
| 870 } | 821 } |
| 871 | 822 |
| 872 bool AppCacheDatabase::InsertDeletableResponseIds( | 823 bool AppCacheDatabase::InsertDeletableResponseIds( |
| 873 const std::vector<int64>& response_ids) { | 824 const std::vector<int64>& response_ids) { |
| 874 const char* kSql = | 825 const char* kSql = |
| 875 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; | 826 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; |
| 876 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); | 827 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); |
| 877 } | 828 } |
| 878 | 829 |
| 879 bool AppCacheDatabase::DeleteDeletableResponseIds( | 830 bool AppCacheDatabase::DeleteDeletableResponseIds( |
| 880 const std::vector<int64>& response_ids) { | 831 const std::vector<int64>& response_ids) { |
| 881 const char* kSql = | 832 const char* kSql = |
| 882 "DELETE FROM DeletableResponseIds WHERE response_id = ?"; | 833 "DELETE FROM DeletableResponseIds WHERE response_id = ?"; |
| 883 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); | 834 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); |
| 884 } | 835 } |
| 885 | 836 |
| 886 bool AppCacheDatabase::RunCachedStatementWithIds( | 837 bool AppCacheDatabase::RunCachedStatementWithIds( |
| 887 const sql::StatementID& statement_id, const char* sql, | 838 const sql::StatementID& statement_id, const char* sql, |
| 888 const std::vector<int64>& ids) { | 839 const std::vector<int64>& ids) { |
| 840 DCHECK(sql); |
| 889 if (!LazyOpen(true)) | 841 if (!LazyOpen(true)) |
| 890 return false; | 842 return false; |
| 891 | 843 |
| 892 sql::Transaction transaction(db_.get()); | 844 sql::Transaction transaction(db_.get()); |
| 893 if (!transaction.Begin()) | 845 if (!transaction.Begin()) |
| 894 return false; | 846 return false; |
| 895 | 847 |
| 896 sql::Statement statement; | 848 sql::Statement statement(db_->GetCachedStatement(statement_id, sql)); |
| 897 if (!PrepareCachedStatement(statement_id, sql, &statement)) | |
| 898 return false; | |
| 899 | 849 |
| 900 std::vector<int64>::const_iterator iter = ids.begin(); | 850 std::vector<int64>::const_iterator iter = ids.begin(); |
| 901 while (iter != ids.end()) { | 851 while (iter != ids.end()) { |
| 902 statement.BindInt64(0, *iter); | 852 statement.BindInt64(0, *iter); |
| 903 if (!statement.Run()) | 853 if (!statement.Run()) |
| 904 return false; | 854 return false; |
| 905 statement.Reset(); | 855 statement.Reset(); |
| 906 ++iter; | 856 ++iter; |
| 907 } | 857 } |
| 908 | 858 |
| 909 return transaction.Commit(); | 859 return transaction.Commit(); |
| 910 } | 860 } |
| 911 | 861 |
| 912 bool AppCacheDatabase::RunUniqueStatementWithInt64Result( | 862 bool AppCacheDatabase::RunUniqueStatementWithInt64Result( |
| 913 const char* sql, int64* result) { | 863 const char* sql, int64* result) { |
| 914 sql::Statement statement; | 864 DCHECK(sql); |
| 915 if (!PrepareUniqueStatement(sql, &statement) || | 865 sql::Statement statement(db_->GetUniqueStatement(sql)); |
| 916 !statement.Step()) { | 866 if (!statement.Step()) { |
| 917 return false; | 867 return false; |
| 918 } | 868 } |
| 919 *result = statement.ColumnInt64(0); | 869 *result = statement.ColumnInt64(0); |
| 920 return true; | 870 return true; |
| 921 } | 871 } |
| 922 | 872 |
| 923 bool AppCacheDatabase::PrepareUniqueStatement( | |
| 924 const char* sql, sql::Statement* statement) { | |
| 925 DCHECK(sql && statement); | |
| 926 statement->Assign(db_->GetUniqueStatement(sql)); | |
| 927 if (!statement->is_valid()) { | |
| 928 NOTREACHED() << db_->GetErrorMessage(); | |
| 929 return false; | |
| 930 } | |
| 931 return true; | |
| 932 } | |
| 933 | |
| 934 bool AppCacheDatabase::PrepareCachedStatement( | |
| 935 const sql::StatementID& id, const char* sql, sql::Statement* statement) { | |
| 936 DCHECK(sql && statement); | |
| 937 statement->Assign(db_->GetCachedStatement(id, sql)); | |
| 938 if (!statement->is_valid()) { | |
| 939 NOTREACHED() << db_->GetErrorMessage(); | |
| 940 return false; | |
| 941 } | |
| 942 return true; | |
| 943 } | |
| 944 | |
| 945 bool AppCacheDatabase::FindResponseIdsForCacheHelper( | 873 bool AppCacheDatabase::FindResponseIdsForCacheHelper( |
| 946 int64 cache_id, std::vector<int64>* ids_vector, | 874 int64 cache_id, std::vector<int64>* ids_vector, |
| 947 std::set<int64>* ids_set) { | 875 std::set<int64>* ids_set) { |
| 948 DCHECK(ids_vector || ids_set); | 876 DCHECK(ids_vector || ids_set); |
| 949 DCHECK(!(ids_vector && ids_set)); | 877 DCHECK(!(ids_vector && ids_set)); |
| 950 if (!LazyOpen(false)) | 878 if (!LazyOpen(false)) |
| 951 return false; | 879 return false; |
| 952 | 880 |
| 953 const char* kSql = | 881 const char* kSql = |
| 954 "SELECT response_id FROM Entries WHERE cache_id = ?"; | 882 "SELECT response_id FROM Entries WHERE cache_id = ?"; |
| 955 | 883 |
| 956 sql::Statement statement; | 884 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 957 if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) | |
| 958 return false; | |
| 959 | 885 |
| 960 statement.BindInt64(0, cache_id); | 886 statement.BindInt64(0, cache_id); |
| 961 while (statement.Step()) { | 887 while (statement.Step()) { |
| 962 int64 id = statement.ColumnInt64(0); | 888 int64 id = statement.ColumnInt64(0); |
| 963 if (ids_set) | 889 if (ids_set) |
| 964 ids_set->insert(id); | 890 ids_set->insert(id); |
| 965 else | 891 else |
| 966 ids_vector->push_back(id); | 892 ids_vector->push_back(id); |
| 967 } | 893 } |
| 968 | 894 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 | 1125 |
| 1200 // So we can't go recursive. | 1126 // So we can't go recursive. |
| 1201 if (is_recreating_) | 1127 if (is_recreating_) |
| 1202 return false; | 1128 return false; |
| 1203 | 1129 |
| 1204 AutoReset<bool> auto_reset(&is_recreating_, true); | 1130 AutoReset<bool> auto_reset(&is_recreating_, true); |
| 1205 return LazyOpen(true); | 1131 return LazyOpen(true); |
| 1206 } | 1132 } |
| 1207 | 1133 |
| 1208 } // namespace appcache | 1134 } // namespace appcache |
| OLD | NEW |