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

Side by Side Diff: content/browser/appcache/appcache_database.cc

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: INT64_MAX Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #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"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 AppCacheDatabase::~AppCacheDatabase() { 211 AppCacheDatabase::~AppCacheDatabase() {
212 CommitLazyLastAccessTimes(); 212 CommitLazyLastAccessTimes();
213 } 213 }
214 214
215 void AppCacheDatabase::Disable() { 215 void AppCacheDatabase::Disable() {
216 VLOG(1) << "Disabling appcache database."; 216 VLOG(1) << "Disabling appcache database.";
217 is_disabled_ = true; 217 is_disabled_ = true;
218 ResetConnectionAndTables(); 218 ResetConnectionAndTables();
219 } 219 }
220 220
221 int64 AppCacheDatabase::GetOriginUsage(const GURL& origin) { 221 int64_t AppCacheDatabase::GetOriginUsage(const GURL& origin) {
222 std::vector<CacheRecord> records; 222 std::vector<CacheRecord> records;
223 if (!FindCachesForOrigin(origin, &records)) 223 if (!FindCachesForOrigin(origin, &records))
224 return 0; 224 return 0;
225 225
226 int64 origin_usage = 0; 226 int64_t origin_usage = 0;
227 std::vector<CacheRecord>::const_iterator iter = records.begin(); 227 std::vector<CacheRecord>::const_iterator iter = records.begin();
228 while (iter != records.end()) { 228 while (iter != records.end()) {
229 origin_usage += iter->cache_size; 229 origin_usage += iter->cache_size;
230 ++iter; 230 ++iter;
231 } 231 }
232 return origin_usage; 232 return origin_usage;
233 } 233 }
234 234
235 bool AppCacheDatabase::GetAllOriginUsage(std::map<GURL, int64>* usage_map) { 235 bool AppCacheDatabase::GetAllOriginUsage(std::map<GURL, int64_t>* usage_map) {
236 std::set<GURL> origins; 236 std::set<GURL> origins;
237 if (!FindOriginsWithGroups(&origins)) 237 if (!FindOriginsWithGroups(&origins))
238 return false; 238 return false;
239 for (std::set<GURL>::const_iterator origin = origins.begin(); 239 for (std::set<GURL>::const_iterator origin = origins.begin();
240 origin != origins.end(); ++origin) { 240 origin != origins.end(); ++origin) {
241 (*usage_map)[*origin] = GetOriginUsage(*origin); 241 (*usage_map)[*origin] = GetOriginUsage(*origin);
242 } 242 }
243 return true; 243 return true;
244 } 244 }
245 245
246 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { 246 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) {
247 DCHECK(origins && origins->empty()); 247 DCHECK(origins && origins->empty());
248 if (!LazyOpen(kDontCreate)) 248 if (!LazyOpen(kDontCreate))
249 return false; 249 return false;
250 250
251 const char kSql[] = 251 const char kSql[] =
252 "SELECT DISTINCT(origin) FROM Groups"; 252 "SELECT DISTINCT(origin) FROM Groups";
253 253
254 sql::Statement statement(db_->GetUniqueStatement(kSql)); 254 sql::Statement statement(db_->GetUniqueStatement(kSql));
255 255
256 while (statement.Step()) 256 while (statement.Step())
257 origins->insert(GURL(statement.ColumnString(0))); 257 origins->insert(GURL(statement.ColumnString(0)));
258 258
259 return statement.Succeeded(); 259 return statement.Succeeded();
260 } 260 }
261 261
262 bool AppCacheDatabase::FindLastStorageIds( 262 bool AppCacheDatabase::FindLastStorageIds(
263 int64* last_group_id, int64* last_cache_id, int64* last_response_id, 263 int64_t* last_group_id,
264 int64* last_deletable_response_rowid) { 264 int64_t* last_cache_id,
265 int64_t* last_response_id,
266 int64_t* last_deletable_response_rowid) {
265 DCHECK(last_group_id && last_cache_id && last_response_id && 267 DCHECK(last_group_id && last_cache_id && last_response_id &&
266 last_deletable_response_rowid); 268 last_deletable_response_rowid);
267 269
268 *last_group_id = 0; 270 *last_group_id = 0;
269 *last_cache_id = 0; 271 *last_cache_id = 0;
270 *last_response_id = 0; 272 *last_response_id = 0;
271 *last_deletable_response_rowid = 0; 273 *last_deletable_response_rowid = 0;
272 274
273 if (!LazyOpen(kDontCreate)) 275 if (!LazyOpen(kDontCreate))
274 return false; 276 return false;
275 277
276 const char* kMaxGroupIdSql = "SELECT MAX(group_id) FROM Groups"; 278 const char* kMaxGroupIdSql = "SELECT MAX(group_id) FROM Groups";
277 const char* kMaxCacheIdSql = "SELECT MAX(cache_id) FROM Caches"; 279 const char* kMaxCacheIdSql = "SELECT MAX(cache_id) FROM Caches";
278 const char* kMaxResponseIdFromEntriesSql = 280 const char* kMaxResponseIdFromEntriesSql =
279 "SELECT MAX(response_id) FROM Entries"; 281 "SELECT MAX(response_id) FROM Entries";
280 const char* kMaxResponseIdFromDeletablesSql = 282 const char* kMaxResponseIdFromDeletablesSql =
281 "SELECT MAX(response_id) FROM DeletableResponseIds"; 283 "SELECT MAX(response_id) FROM DeletableResponseIds";
282 const char* kMaxDeletableResponseRowIdSql = 284 const char* kMaxDeletableResponseRowIdSql =
283 "SELECT MAX(rowid) FROM DeletableResponseIds"; 285 "SELECT MAX(rowid) FROM DeletableResponseIds";
284 int64 max_group_id; 286 int64_t max_group_id;
285 int64 max_cache_id; 287 int64_t max_cache_id;
286 int64 max_response_id_from_entries; 288 int64_t max_response_id_from_entries;
287 int64 max_response_id_from_deletables; 289 int64_t max_response_id_from_deletables;
288 int64 max_deletable_response_rowid; 290 int64_t max_deletable_response_rowid;
289 if (!RunUniqueStatementWithInt64Result(kMaxGroupIdSql, &max_group_id) || 291 if (!RunUniqueStatementWithInt64Result(kMaxGroupIdSql, &max_group_id) ||
290 !RunUniqueStatementWithInt64Result(kMaxCacheIdSql, &max_cache_id) || 292 !RunUniqueStatementWithInt64Result(kMaxCacheIdSql, &max_cache_id) ||
291 !RunUniqueStatementWithInt64Result(kMaxResponseIdFromEntriesSql, 293 !RunUniqueStatementWithInt64Result(kMaxResponseIdFromEntriesSql,
292 &max_response_id_from_entries) || 294 &max_response_id_from_entries) ||
293 !RunUniqueStatementWithInt64Result(kMaxResponseIdFromDeletablesSql, 295 !RunUniqueStatementWithInt64Result(kMaxResponseIdFromDeletablesSql,
294 &max_response_id_from_deletables) || 296 &max_response_id_from_deletables) ||
295 !RunUniqueStatementWithInt64Result(kMaxDeletableResponseRowIdSql, 297 !RunUniqueStatementWithInt64Result(kMaxDeletableResponseRowIdSql,
296 &max_deletable_response_rowid)) { 298 &max_deletable_response_rowid)) {
297 return false; 299 return false;
298 } 300 }
299 301
300 *last_group_id = max_group_id; 302 *last_group_id = max_group_id;
301 *last_cache_id = max_cache_id; 303 *last_cache_id = max_cache_id;
302 *last_response_id = std::max(max_response_id_from_entries, 304 *last_response_id = std::max(max_response_id_from_entries,
303 max_response_id_from_deletables); 305 max_response_id_from_deletables);
304 *last_deletable_response_rowid = max_deletable_response_rowid; 306 *last_deletable_response_rowid = max_deletable_response_rowid;
305 return true; 307 return true;
306 } 308 }
307 309
308 bool AppCacheDatabase::FindGroup(int64 group_id, GroupRecord* record) { 310 bool AppCacheDatabase::FindGroup(int64_t group_id, GroupRecord* record) {
309 DCHECK(record); 311 DCHECK(record);
310 if (!LazyOpen(kDontCreate)) 312 if (!LazyOpen(kDontCreate))
311 return false; 313 return false;
312 314
313 const char kSql[] = 315 const char kSql[] =
314 "SELECT group_id, origin, manifest_url," 316 "SELECT group_id, origin, manifest_url,"
315 " creation_time, last_access_time," 317 " creation_time, last_access_time,"
316 " last_full_update_check_time," 318 " last_full_update_check_time,"
317 " first_evictable_error_time" 319 " first_evictable_error_time"
318 " FROM Groups WHERE group_id = ?"; 320 " FROM Groups WHERE group_id = ?";
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 372
371 while (statement.Step()) { 373 while (statement.Step()) {
372 records->push_back(GroupRecord()); 374 records->push_back(GroupRecord());
373 ReadGroupRecord(statement, &records->back()); 375 ReadGroupRecord(statement, &records->back());
374 DCHECK(records->back().origin == origin); 376 DCHECK(records->back().origin == origin);
375 } 377 }
376 378
377 return statement.Succeeded(); 379 return statement.Succeeded();
378 } 380 }
379 381
380 bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { 382 bool AppCacheDatabase::FindGroupForCache(int64_t cache_id,
383 GroupRecord* record) {
381 DCHECK(record); 384 DCHECK(record);
382 if (!LazyOpen(kDontCreate)) 385 if (!LazyOpen(kDontCreate))
383 return false; 386 return false;
384 387
385 const char kSql[] = 388 const char kSql[] =
386 "SELECT g.group_id, g.origin, g.manifest_url," 389 "SELECT g.group_id, g.origin, g.manifest_url,"
387 " g.creation_time, g.last_access_time," 390 " g.creation_time, g.last_access_time,"
388 " g.last_full_update_check_time," 391 " g.last_full_update_check_time,"
389 " g.first_evictable_error_time" 392 " g.first_evictable_error_time"
390 " FROM Groups g, Caches c" 393 " FROM Groups g, Caches c"
(...skipping 22 matching lines...) Expand all
413 statement.BindInt64(0, record->group_id); 416 statement.BindInt64(0, record->group_id);
414 statement.BindString(1, record->origin.spec()); 417 statement.BindString(1, record->origin.spec());
415 statement.BindString(2, record->manifest_url.spec()); 418 statement.BindString(2, record->manifest_url.spec());
416 statement.BindInt64(3, record->creation_time.ToInternalValue()); 419 statement.BindInt64(3, record->creation_time.ToInternalValue());
417 statement.BindInt64(4, record->last_access_time.ToInternalValue()); 420 statement.BindInt64(4, record->last_access_time.ToInternalValue());
418 statement.BindInt64(5, record->last_full_update_check_time.ToInternalValue()); 421 statement.BindInt64(5, record->last_full_update_check_time.ToInternalValue());
419 statement.BindInt64(6, record->first_evictable_error_time.ToInternalValue()); 422 statement.BindInt64(6, record->first_evictable_error_time.ToInternalValue());
420 return statement.Run(); 423 return statement.Run();
421 } 424 }
422 425
423 bool AppCacheDatabase::DeleteGroup(int64 group_id) { 426 bool AppCacheDatabase::DeleteGroup(int64_t group_id) {
424 if (!LazyOpen(kDontCreate)) 427 if (!LazyOpen(kDontCreate))
425 return false; 428 return false;
426 429
427 const char kSql[] = 430 const char kSql[] =
428 "DELETE FROM Groups WHERE group_id = ?"; 431 "DELETE FROM Groups WHERE group_id = ?";
429 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 432 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
430 statement.BindInt64(0, group_id); 433 statement.BindInt64(0, group_id);
431 return statement.Run(); 434 return statement.Run();
432 } 435 }
433 436
434 bool AppCacheDatabase::UpdateLastAccessTime( 437 bool AppCacheDatabase::UpdateLastAccessTime(int64_t group_id, base::Time time) {
435 int64 group_id, base::Time time) {
436 if (!LazyUpdateLastAccessTime(group_id, time)) 438 if (!LazyUpdateLastAccessTime(group_id, time))
437 return false; 439 return false;
438 return CommitLazyLastAccessTimes(); 440 return CommitLazyLastAccessTimes();
439 } 441 }
440 442
441 bool AppCacheDatabase::LazyUpdateLastAccessTime( 443 bool AppCacheDatabase::LazyUpdateLastAccessTime(int64_t group_id,
442 int64 group_id, base::Time time) { 444 base::Time time) {
443 if (!LazyOpen(kCreateIfNeeded)) 445 if (!LazyOpen(kCreateIfNeeded))
444 return false; 446 return false;
445 lazy_last_access_times_[group_id] = time; 447 lazy_last_access_times_[group_id] = time;
446 return true; 448 return true;
447 } 449 }
448 450
449 bool AppCacheDatabase::CommitLazyLastAccessTimes() { 451 bool AppCacheDatabase::CommitLazyLastAccessTimes() {
450 if (lazy_last_access_times_.empty()) 452 if (lazy_last_access_times_.empty())
451 return true; 453 return true;
452 if (!LazyOpen(kDontCreate)) 454 if (!LazyOpen(kDontCreate))
453 return false; 455 return false;
454 456
455 sql::Transaction transaction(db_.get()); 457 sql::Transaction transaction(db_.get());
456 if (!transaction.Begin()) 458 if (!transaction.Begin())
457 return false; 459 return false;
458 for (const auto& pair : lazy_last_access_times_) { 460 for (const auto& pair : lazy_last_access_times_) {
459 const char kSql[] = 461 const char kSql[] =
460 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; 462 "UPDATE Groups SET last_access_time = ? WHERE group_id = ?";
461 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 463 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
462 statement.BindInt64(0, pair.second.ToInternalValue()); // time 464 statement.BindInt64(0, pair.second.ToInternalValue()); // time
463 statement.BindInt64(1, pair.first); // group_id 465 statement.BindInt64(1, pair.first); // group_id
464 statement.Run(); 466 statement.Run();
465 } 467 }
466 lazy_last_access_times_.clear(); 468 lazy_last_access_times_.clear();
467 return transaction.Commit(); 469 return transaction.Commit();
468 } 470 }
469 471
470 bool AppCacheDatabase::UpdateEvictionTimes( 472 bool AppCacheDatabase::UpdateEvictionTimes(
471 int64 group_id, 473 int64_t group_id,
472 base::Time last_full_update_check_time, 474 base::Time last_full_update_check_time,
473 base::Time first_evictable_error_time) { 475 base::Time first_evictable_error_time) {
474 if (!LazyOpen(kCreateIfNeeded)) 476 if (!LazyOpen(kCreateIfNeeded))
475 return false; 477 return false;
476 478
477 const char kSql[] = 479 const char kSql[] =
478 "UPDATE Groups" 480 "UPDATE Groups"
479 " SET last_full_update_check_time = ?, first_evictable_error_time = ?" 481 " SET last_full_update_check_time = ?, first_evictable_error_time = ?"
480 " WHERE group_id = ?"; 482 " WHERE group_id = ?";
481 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 483 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
482 statement.BindInt64(0, last_full_update_check_time.ToInternalValue()); 484 statement.BindInt64(0, last_full_update_check_time.ToInternalValue());
483 statement.BindInt64(1, first_evictable_error_time.ToInternalValue()); 485 statement.BindInt64(1, first_evictable_error_time.ToInternalValue());
484 statement.BindInt64(2, group_id); 486 statement.BindInt64(2, group_id);
485 return statement.Run(); // Will succeed even if group_id is invalid. 487 return statement.Run(); // Will succeed even if group_id is invalid.
486 } 488 }
487 489
488 bool AppCacheDatabase::FindCache(int64 cache_id, CacheRecord* record) { 490 bool AppCacheDatabase::FindCache(int64_t cache_id, CacheRecord* record) {
489 DCHECK(record); 491 DCHECK(record);
490 if (!LazyOpen(kDontCreate)) 492 if (!LazyOpen(kDontCreate))
491 return false; 493 return false;
492 494
493 const char kSql[] = 495 const char kSql[] =
494 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" 496 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size"
495 " FROM Caches WHERE cache_id = ?"; 497 " FROM Caches WHERE cache_id = ?";
496 498
497 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 499 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
498 statement.BindInt64(0, cache_id); 500 statement.BindInt64(0, cache_id);
499 501
500 if (!statement.Step()) 502 if (!statement.Step())
501 return false; 503 return false;
502 504
503 ReadCacheRecord(statement, record); 505 ReadCacheRecord(statement, record);
504 return true; 506 return true;
505 } 507 }
506 508
507 bool AppCacheDatabase::FindCacheForGroup(int64 group_id, CacheRecord* record) { 509 bool AppCacheDatabase::FindCacheForGroup(int64_t group_id,
510 CacheRecord* record) {
508 DCHECK(record); 511 DCHECK(record);
509 if (!LazyOpen(kDontCreate)) 512 if (!LazyOpen(kDontCreate))
510 return false; 513 return false;
511 514
512 const char kSql[] = 515 const char kSql[] =
513 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" 516 "SELECT cache_id, group_id, online_wildcard, update_time, cache_size"
514 " FROM Caches WHERE group_id = ?"; 517 " FROM Caches WHERE group_id = ?";
515 518
516 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 519 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
517 statement.BindInt64(0, group_id); 520 statement.BindInt64(0, group_id);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 555 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
553 statement.BindInt64(0, record->cache_id); 556 statement.BindInt64(0, record->cache_id);
554 statement.BindInt64(1, record->group_id); 557 statement.BindInt64(1, record->group_id);
555 statement.BindBool(2, record->online_wildcard); 558 statement.BindBool(2, record->online_wildcard);
556 statement.BindInt64(3, record->update_time.ToInternalValue()); 559 statement.BindInt64(3, record->update_time.ToInternalValue());
557 statement.BindInt64(4, record->cache_size); 560 statement.BindInt64(4, record->cache_size);
558 561
559 return statement.Run(); 562 return statement.Run();
560 } 563 }
561 564
562 bool AppCacheDatabase::DeleteCache(int64 cache_id) { 565 bool AppCacheDatabase::DeleteCache(int64_t cache_id) {
563 if (!LazyOpen(kDontCreate)) 566 if (!LazyOpen(kDontCreate))
564 return false; 567 return false;
565 568
566 const char kSql[] = 569 const char kSql[] =
567 "DELETE FROM Caches WHERE cache_id = ?"; 570 "DELETE FROM Caches WHERE cache_id = ?";
568 571
569 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 572 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
570 statement.BindInt64(0, cache_id); 573 statement.BindInt64(0, cache_id);
571 574
572 return statement.Run(); 575 return statement.Run();
573 } 576 }
574 577
575 bool AppCacheDatabase::FindEntriesForCache( 578 bool AppCacheDatabase::FindEntriesForCache(int64_t cache_id,
576 int64 cache_id, std::vector<EntryRecord>* records) { 579 std::vector<EntryRecord>* records) {
577 DCHECK(records && records->empty()); 580 DCHECK(records && records->empty());
578 if (!LazyOpen(kDontCreate)) 581 if (!LazyOpen(kDontCreate))
579 return false; 582 return false;
580 583
581 const char kSql[] = 584 const char kSql[] =
582 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" 585 "SELECT cache_id, url, flags, response_id, response_size FROM Entries"
583 " WHERE cache_id = ?"; 586 " WHERE cache_id = ?";
584 587
585 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 588 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
586 statement.BindInt64(0, cache_id); 589 statement.BindInt64(0, cache_id);
(...skipping 22 matching lines...) Expand all
609 612
610 while (statement.Step()) { 613 while (statement.Step()) {
611 records->push_back(EntryRecord()); 614 records->push_back(EntryRecord());
612 ReadEntryRecord(statement, &records->back()); 615 ReadEntryRecord(statement, &records->back());
613 DCHECK(records->back().url == url); 616 DCHECK(records->back().url == url);
614 } 617 }
615 618
616 return statement.Succeeded(); 619 return statement.Succeeded();
617 } 620 }
618 621
619 bool AppCacheDatabase::FindEntry( 622 bool AppCacheDatabase::FindEntry(int64_t cache_id,
620 int64 cache_id, const GURL& url, EntryRecord* record) { 623 const GURL& url,
624 EntryRecord* record) {
621 DCHECK(record); 625 DCHECK(record);
622 if (!LazyOpen(kDontCreate)) 626 if (!LazyOpen(kDontCreate))
623 return false; 627 return false;
624 628
625 const char kSql[] = 629 const char kSql[] =
626 "SELECT cache_id, url, flags, response_id, response_size FROM Entries" 630 "SELECT cache_id, url, flags, response_id, response_size FROM Entries"
627 " WHERE cache_id = ? AND url = ?"; 631 " WHERE cache_id = ? AND url = ?";
628 632
629 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 633 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
630 statement.BindInt64(0, cache_id); 634 statement.BindInt64(0, cache_id);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 return false; 670 return false;
667 std::vector<EntryRecord>::const_iterator iter = records.begin(); 671 std::vector<EntryRecord>::const_iterator iter = records.begin();
668 while (iter != records.end()) { 672 while (iter != records.end()) {
669 if (!InsertEntry(&(*iter))) 673 if (!InsertEntry(&(*iter)))
670 return false; 674 return false;
671 ++iter; 675 ++iter;
672 } 676 }
673 return transaction.Commit(); 677 return transaction.Commit();
674 } 678 }
675 679
676 bool AppCacheDatabase::DeleteEntriesForCache(int64 cache_id) { 680 bool AppCacheDatabase::DeleteEntriesForCache(int64_t cache_id) {
677 if (!LazyOpen(kDontCreate)) 681 if (!LazyOpen(kDontCreate))
678 return false; 682 return false;
679 683
680 const char kSql[] = 684 const char kSql[] =
681 "DELETE FROM Entries WHERE cache_id = ?"; 685 "DELETE FROM Entries WHERE cache_id = ?";
682 686
683 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 687 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
684 statement.BindInt64(0, cache_id); 688 statement.BindInt64(0, cache_id);
685 689
686 return statement.Run(); 690 return statement.Run();
687 } 691 }
688 692
689 bool AppCacheDatabase::AddEntryFlags( 693 bool AppCacheDatabase::AddEntryFlags(const GURL& entry_url,
690 const GURL& entry_url, int64 cache_id, int additional_flags) { 694 int64_t cache_id,
695 int additional_flags) {
691 if (!LazyOpen(kDontCreate)) 696 if (!LazyOpen(kDontCreate))
692 return false; 697 return false;
693 698
694 const char kSql[] = 699 const char kSql[] =
695 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; 700 "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?";
696 701
697 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 702 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
698 statement.BindInt(0, additional_flags); 703 statement.BindInt(0, additional_flags);
699 statement.BindInt64(1, cache_id); 704 statement.BindInt64(1, cache_id);
700 statement.BindString(2, entry_url.spec()); 705 statement.BindString(2, entry_url.spec());
(...skipping 16 matching lines...) Expand all
717 722
718 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 723 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
719 statement.BindString(0, origin.spec()); 724 statement.BindString(0, origin.spec());
720 725
721 ReadNamespaceRecords(&statement, intercepts, fallbacks); 726 ReadNamespaceRecords(&statement, intercepts, fallbacks);
722 727
723 return statement.Succeeded(); 728 return statement.Succeeded();
724 } 729 }
725 730
726 bool AppCacheDatabase::FindNamespacesForCache( 731 bool AppCacheDatabase::FindNamespacesForCache(
727 int64 cache_id, 732 int64_t cache_id,
728 std::vector<NamespaceRecord>* intercepts, 733 std::vector<NamespaceRecord>* intercepts,
729 std::vector<NamespaceRecord>* fallbacks) { 734 std::vector<NamespaceRecord>* fallbacks) {
730 DCHECK(intercepts && intercepts->empty()); 735 DCHECK(intercepts && intercepts->empty());
731 DCHECK(fallbacks && fallbacks->empty()); 736 DCHECK(fallbacks && fallbacks->empty());
732 if (!LazyOpen(kDontCreate)) 737 if (!LazyOpen(kDontCreate))
733 return false; 738 return false;
734 739
735 const char kSql[] = 740 const char kSql[] =
736 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" 741 "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern"
737 " FROM Namespaces WHERE cache_id = ?"; 742 " FROM Namespaces WHERE cache_id = ?";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 return false; 787 return false;
783 std::vector<NamespaceRecord>::const_iterator iter = records.begin(); 788 std::vector<NamespaceRecord>::const_iterator iter = records.begin();
784 while (iter != records.end()) { 789 while (iter != records.end()) {
785 if (!InsertNamespace(&(*iter))) 790 if (!InsertNamespace(&(*iter)))
786 return false; 791 return false;
787 ++iter; 792 ++iter;
788 } 793 }
789 return transaction.Commit(); 794 return transaction.Commit();
790 } 795 }
791 796
792 bool AppCacheDatabase::DeleteNamespacesForCache(int64 cache_id) { 797 bool AppCacheDatabase::DeleteNamespacesForCache(int64_t cache_id) {
793 if (!LazyOpen(kDontCreate)) 798 if (!LazyOpen(kDontCreate))
794 return false; 799 return false;
795 800
796 const char kSql[] = 801 const char kSql[] =
797 "DELETE FROM Namespaces WHERE cache_id = ?"; 802 "DELETE FROM Namespaces WHERE cache_id = ?";
798 803
799 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 804 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
800 statement.BindInt64(0, cache_id); 805 statement.BindInt64(0, cache_id);
801 806
802 return statement.Run(); 807 return statement.Run();
803 } 808 }
804 809
805 bool AppCacheDatabase::FindOnlineWhiteListForCache( 810 bool AppCacheDatabase::FindOnlineWhiteListForCache(
806 int64 cache_id, std::vector<OnlineWhiteListRecord>* records) { 811 int64_t cache_id,
812 std::vector<OnlineWhiteListRecord>* records) {
807 DCHECK(records && records->empty()); 813 DCHECK(records && records->empty());
808 if (!LazyOpen(kDontCreate)) 814 if (!LazyOpen(kDontCreate))
809 return false; 815 return false;
810 816
811 const char kSql[] = 817 const char kSql[] =
812 "SELECT cache_id, namespace_url, is_pattern FROM OnlineWhiteLists" 818 "SELECT cache_id, namespace_url, is_pattern FROM OnlineWhiteLists"
813 " WHERE cache_id = ?"; 819 " WHERE cache_id = ?";
814 820
815 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 821 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
816 statement.BindInt64(0, cache_id); 822 statement.BindInt64(0, cache_id);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 return false; 855 return false;
850 std::vector<OnlineWhiteListRecord>::const_iterator iter = records.begin(); 856 std::vector<OnlineWhiteListRecord>::const_iterator iter = records.begin();
851 while (iter != records.end()) { 857 while (iter != records.end()) {
852 if (!InsertOnlineWhiteList(&(*iter))) 858 if (!InsertOnlineWhiteList(&(*iter)))
853 return false; 859 return false;
854 ++iter; 860 ++iter;
855 } 861 }
856 return transaction.Commit(); 862 return transaction.Commit();
857 } 863 }
858 864
859 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64 cache_id) { 865 bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64_t cache_id) {
860 if (!LazyOpen(kDontCreate)) 866 if (!LazyOpen(kDontCreate))
861 return false; 867 return false;
862 868
863 const char kSql[] = 869 const char kSql[] =
864 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; 870 "DELETE FROM OnlineWhiteLists WHERE cache_id = ?";
865 871
866 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 872 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
867 statement.BindInt64(0, cache_id); 873 statement.BindInt64(0, cache_id);
868 874
869 return statement.Run(); 875 return statement.Run();
870 } 876 }
871 877
872 bool AppCacheDatabase::GetDeletableResponseIds( 878 bool AppCacheDatabase::GetDeletableResponseIds(
873 std::vector<int64>* response_ids, int64 max_rowid, int limit) { 879 std::vector<int64_t>* response_ids,
880 int64_t max_rowid,
881 int limit) {
874 if (!LazyOpen(kDontCreate)) 882 if (!LazyOpen(kDontCreate))
875 return false; 883 return false;
876 884
877 const char kSql[] = 885 const char kSql[] =
878 "SELECT response_id FROM DeletableResponseIds " 886 "SELECT response_id FROM DeletableResponseIds "
879 " WHERE rowid <= ?" 887 " WHERE rowid <= ?"
880 " LIMIT ?"; 888 " LIMIT ?";
881 889
882 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 890 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
883 statement.BindInt64(0, max_rowid); 891 statement.BindInt64(0, max_rowid);
884 statement.BindInt64(1, limit); 892 statement.BindInt64(1, limit);
885 893
886 while (statement.Step()) 894 while (statement.Step())
887 response_ids->push_back(statement.ColumnInt64(0)); 895 response_ids->push_back(statement.ColumnInt64(0));
888 return statement.Succeeded(); 896 return statement.Succeeded();
889 } 897 }
890 898
891 bool AppCacheDatabase::InsertDeletableResponseIds( 899 bool AppCacheDatabase::InsertDeletableResponseIds(
892 const std::vector<int64>& response_ids) { 900 const std::vector<int64_t>& response_ids) {
893 const char kSql[] = 901 const char kSql[] =
894 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; 902 "INSERT INTO DeletableResponseIds (response_id) VALUES (?)";
895 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); 903 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids);
896 } 904 }
897 905
898 bool AppCacheDatabase::DeleteDeletableResponseIds( 906 bool AppCacheDatabase::DeleteDeletableResponseIds(
899 const std::vector<int64>& response_ids) { 907 const std::vector<int64_t>& response_ids) {
900 const char kSql[] = 908 const char kSql[] =
901 "DELETE FROM DeletableResponseIds WHERE response_id = ?"; 909 "DELETE FROM DeletableResponseIds WHERE response_id = ?";
902 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); 910 return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids);
903 } 911 }
904 912
905 bool AppCacheDatabase::RunCachedStatementWithIds( 913 bool AppCacheDatabase::RunCachedStatementWithIds(
906 const sql::StatementID& statement_id, const char* sql, 914 const sql::StatementID& statement_id,
907 const std::vector<int64>& ids) { 915 const char* sql,
916 const std::vector<int64_t>& ids) {
908 DCHECK(sql); 917 DCHECK(sql);
909 if (!LazyOpen(kCreateIfNeeded)) 918 if (!LazyOpen(kCreateIfNeeded))
910 return false; 919 return false;
911 920
912 sql::Transaction transaction(db_.get()); 921 sql::Transaction transaction(db_.get());
913 if (!transaction.Begin()) 922 if (!transaction.Begin())
914 return false; 923 return false;
915 924
916 sql::Statement statement(db_->GetCachedStatement(statement_id, sql)); 925 sql::Statement statement(db_->GetCachedStatement(statement_id, sql));
917 926
918 std::vector<int64>::const_iterator iter = ids.begin(); 927 std::vector<int64_t>::const_iterator iter = ids.begin();
919 while (iter != ids.end()) { 928 while (iter != ids.end()) {
920 statement.BindInt64(0, *iter); 929 statement.BindInt64(0, *iter);
921 if (!statement.Run()) 930 if (!statement.Run())
922 return false; 931 return false;
923 statement.Reset(true); 932 statement.Reset(true);
924 ++iter; 933 ++iter;
925 } 934 }
926 935
927 return transaction.Commit(); 936 return transaction.Commit();
928 } 937 }
929 938
930 bool AppCacheDatabase::RunUniqueStatementWithInt64Result( 939 bool AppCacheDatabase::RunUniqueStatementWithInt64Result(const char* sql,
931 const char* sql, int64* result) { 940 int64_t* result) {
932 DCHECK(sql); 941 DCHECK(sql);
933 sql::Statement statement(db_->GetUniqueStatement(sql)); 942 sql::Statement statement(db_->GetUniqueStatement(sql));
934 if (!statement.Step()) { 943 if (!statement.Step()) {
935 return false; 944 return false;
936 } 945 }
937 *result = statement.ColumnInt64(0); 946 *result = statement.ColumnInt64(0);
938 return true; 947 return true;
939 } 948 }
940 949
941 bool AppCacheDatabase::FindResponseIdsForCacheHelper( 950 bool AppCacheDatabase::FindResponseIdsForCacheHelper(
942 int64 cache_id, std::vector<int64>* ids_vector, 951 int64_t cache_id,
943 std::set<int64>* ids_set) { 952 std::vector<int64_t>* ids_vector,
953 std::set<int64_t>* ids_set) {
944 DCHECK(ids_vector || ids_set); 954 DCHECK(ids_vector || ids_set);
945 DCHECK(!(ids_vector && ids_set)); 955 DCHECK(!(ids_vector && ids_set));
946 if (!LazyOpen(kDontCreate)) 956 if (!LazyOpen(kDontCreate))
947 return false; 957 return false;
948 958
949 const char kSql[] = 959 const char kSql[] =
950 "SELECT response_id FROM Entries WHERE cache_id = ?"; 960 "SELECT response_id FROM Entries WHERE cache_id = ?";
951 961
952 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 962 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
953 963
954 statement.BindInt64(0, cache_id); 964 statement.BindInt64(0, cache_id);
955 while (statement.Step()) { 965 while (statement.Step()) {
956 int64 id = statement.ColumnInt64(0); 966 int64_t id = statement.ColumnInt64(0);
957 if (ids_set) 967 if (ids_set)
958 ids_set->insert(id); 968 ids_set->insert(id);
959 else 969 else
960 ids_vector->push_back(id); 970 ids_vector->push_back(id);
961 } 971 }
962 972
963 return statement.Succeeded(); 973 return statement.Succeeded();
964 } 974 }
965 975
966 void AppCacheDatabase::ReadGroupRecord( 976 void AppCacheDatabase::ReadGroupRecord(
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1317 }
1308 1318
1309 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) { 1319 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) {
1310 was_corruption_detected_ |= sql::IsErrorCatastrophic(err); 1320 was_corruption_detected_ |= sql::IsErrorCatastrophic(err);
1311 if (!db_->ShouldIgnoreSqliteError(err)) 1321 if (!db_->ShouldIgnoreSqliteError(err))
1312 DLOG(ERROR) << db_->GetErrorMessage(); 1322 DLOG(ERROR) << db_->GetErrorMessage();
1313 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check? 1323 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check?
1314 } 1324 }
1315 1325
1316 } // namespace content 1326 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_database.h ('k') | content/browser/appcache/appcache_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698