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 "chrome/browser/history/thumbnail_database.h" | 5 #include "chrome/browser/history/thumbnail_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_tokenizer.h" |
13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
14 #include "base/time.h" | 16 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 18 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
17 #include "chrome/browser/history/history_publisher.h" | 19 #include "chrome/browser/history/history_publisher.h" |
18 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
19 #include "chrome/browser/history/url_database.h" | 21 #include "chrome/browser/history/url_database.h" |
20 #include "chrome/common/thumbnail_score.h" | 22 #include "chrome/common/thumbnail_score.h" |
21 #include "sql/statement.h" | 23 #include "sql/statement.h" |
22 #include "sql/transaction.h" | 24 #include "sql/transaction.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // | 66 // |
65 // id Unique ID. | 67 // id Unique ID. |
66 // icon_id The ID of the favicon that the bitmap is associated to. | 68 // icon_id The ID of the favicon that the bitmap is associated to. |
67 // last_updated The time at which this favicon was inserted into the | 69 // last_updated The time at which this favicon was inserted into the |
68 // table. This is used to determine if it needs to be | 70 // table. This is used to determine if it needs to be |
69 // redownloaded from the web. | 71 // redownloaded from the web. |
70 // image_data PNG encoded data of the favicon. | 72 // image_data PNG encoded data of the favicon. |
71 // width Pixel width of |image_data|. | 73 // width Pixel width of |image_data|. |
72 // height Pixel height of |image_data|. | 74 // height Pixel height of |image_data|. |
73 | 75 |
74 | |
75 | |
76 static void FillIconMapping(const sql::Statement& statement, | 76 static void FillIconMapping(const sql::Statement& statement, |
77 const GURL& page_url, | 77 const GURL& page_url, |
78 history::IconMapping* icon_mapping) { | 78 history::IconMapping* icon_mapping) { |
79 icon_mapping->mapping_id = statement.ColumnInt64(0); | 79 icon_mapping->mapping_id = statement.ColumnInt64(0); |
80 icon_mapping->icon_id = statement.ColumnInt64(1); | 80 icon_mapping->icon_id = statement.ColumnInt64(1); |
81 icon_mapping->icon_type = | 81 icon_mapping->icon_type = |
82 static_cast<history::IconType>(statement.ColumnInt(2)); | 82 static_cast<history::IconType>(statement.ColumnInt(2)); |
| 83 icon_mapping->icon_url = GURL(statement.ColumnString(3)); |
83 icon_mapping->page_url = page_url; | 84 icon_mapping->page_url = page_url; |
84 } | 85 } |
85 | 86 |
86 namespace history { | 87 namespace history { |
87 | 88 |
88 // Version number of the database. | 89 // Version number of the database. |
89 static const int kCurrentVersionNumber = 6; | 90 static const int kCurrentVersionNumber = 6; |
90 static const int kCompatibleVersionNumber = 6; | 91 static const int kCompatibleVersionNumber = 6; |
91 | 92 |
92 // Use 90 quality (out of 100) which is pretty high, because we're very | 93 // Use 90 quality (out of 100) which is pretty high, because we're very |
93 // sensitive to artifacts for these small sized, highly detailed images. | 94 // sensitive to artifacts for these small sized, highly detailed images. |
94 static const int kImageQuality = 90; | 95 static const int kImageQuality = 90; |
95 | 96 |
96 ThumbnailDatabase::IconMappingEnumerator::IconMappingEnumerator() { | 97 ThumbnailDatabase::IconMappingEnumerator::IconMappingEnumerator() { |
97 } | 98 } |
98 | 99 |
99 ThumbnailDatabase::IconMappingEnumerator::~IconMappingEnumerator() { | 100 ThumbnailDatabase::IconMappingEnumerator::~IconMappingEnumerator() { |
100 } | 101 } |
101 | 102 |
102 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( | 103 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( |
103 IconMapping* icon_mapping) { | 104 IconMapping* icon_mapping) { |
104 if (!statement_.Step()) | 105 if (!statement_.Step()) |
105 return false; | 106 return false; |
106 FillIconMapping(statement_, GURL(statement_.ColumnString(3)), icon_mapping); | 107 FillIconMapping(statement_, GURL(statement_.ColumnString(4)), icon_mapping); |
107 return true; | 108 return true; |
108 } | 109 } |
109 | 110 |
110 ThumbnailDatabase::ThumbnailDatabase() | 111 ThumbnailDatabase::ThumbnailDatabase() |
111 : history_publisher_(NULL), | 112 : history_publisher_(NULL), |
112 use_top_sites_(false) { | 113 use_top_sites_(false) { |
113 } | 114 } |
114 | 115 |
115 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { | 116 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { |
116 LOG(WARNING) << "Unable to update to thumbnail database to version " << | 117 LOG(WARNING) << "Unable to update to thumbnail database to version " << |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 double current_boring_score = select_statement.ColumnDouble(0); | 441 double current_boring_score = select_statement.ColumnDouble(0); |
441 bool current_clipping = select_statement.ColumnBool(1); | 442 bool current_clipping = select_statement.ColumnBool(1); |
442 bool current_at_top = select_statement.ColumnBool(2); | 443 bool current_at_top = select_statement.ColumnBool(2); |
443 base::Time last_updated = | 444 base::Time last_updated = |
444 base::Time::FromTimeT(select_statement.ColumnInt64(3)); | 445 base::Time::FromTimeT(select_statement.ColumnInt64(3)); |
445 *score = ThumbnailScore(current_boring_score, current_clipping, | 446 *score = ThumbnailScore(current_boring_score, current_clipping, |
446 current_at_top, last_updated); | 447 current_at_top, last_updated); |
447 return true; | 448 return true; |
448 } | 449 } |
449 | 450 |
| 451 bool ThumbnailDatabase::GetFaviconBitmapIDSizeList( |
| 452 FaviconID icon_id, |
| 453 std::vector<FaviconBitmapIDSize>* bitmap_id_size_list) { |
| 454 DCHECK(icon_id); |
| 455 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 456 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); |
| 457 statement.BindInt64(0, icon_id); |
| 458 |
| 459 bool result = false; |
| 460 while (statement.Step()) { |
| 461 result = true; |
| 462 FaviconBitmapIDSize bitmap_id_size; |
| 463 bitmap_id_size.bitmap_id = statement.ColumnInt(0); |
| 464 bitmap_id_size.pixel_size = gfx::Size(statement.ColumnInt(1), |
| 465 statement.ColumnInt(2)); |
| 466 bitmap_id_size_list->push_back(bitmap_id_size); |
| 467 } |
| 468 return result; |
| 469 } |
| 470 |
450 bool ThumbnailDatabase::GetFaviconBitmaps( | 471 bool ThumbnailDatabase::GetFaviconBitmaps( |
451 FaviconID icon_id, | 472 FaviconID icon_id, |
452 std::vector<FaviconBitmap>* favicon_bitmaps) { | 473 std::vector<FaviconBitmap>* favicon_bitmaps) { |
453 DCHECK(icon_id); | 474 DCHECK(icon_id); |
454 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 475 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
455 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " | 476 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " |
456 "WHERE icon_id=?")); | 477 "WHERE icon_id=?")); |
457 statement.BindInt64(0, icon_id); | 478 statement.BindInt64(0, icon_id); |
458 | 479 |
459 bool result = false; | 480 bool result = false; |
(...skipping 12 matching lines...) Expand all Loading... |
472 statement.ColumnBlobAsVector(2, &data->data()); | 493 statement.ColumnBlobAsVector(2, &data->data()); |
473 favicon_bitmap.bitmap_data = data; | 494 favicon_bitmap.bitmap_data = data; |
474 } | 495 } |
475 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), | 496 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), |
476 statement.ColumnInt(4)); | 497 statement.ColumnInt(4)); |
477 favicon_bitmaps->push_back(favicon_bitmap); | 498 favicon_bitmaps->push_back(favicon_bitmap); |
478 } | 499 } |
479 return result; | 500 return result; |
480 } | 501 } |
481 | 502 |
| 503 bool ThumbnailDatabase::GetFaviconBitmap( |
| 504 FaviconBitmapID bitmap_id, |
| 505 base::Time* last_updated, |
| 506 scoped_refptr<base::RefCountedMemory>* png_icon_data, |
| 507 gfx::Size* pixel_size) { |
| 508 DCHECK(bitmap_id); |
| 509 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 510 "SELECT last_updated, image_data, width, height FROM favicon_bitmaps " |
| 511 "WHERE id=?")); |
| 512 statement.BindInt64(0, bitmap_id); |
| 513 |
| 514 if (!statement.Step()) |
| 515 return false; |
| 516 |
| 517 if (last_updated) |
| 518 *last_updated = base::Time::FromTimeT(statement.ColumnInt64(0)); |
| 519 |
| 520 if (png_icon_data && statement.ColumnByteLength(1) > 0) { |
| 521 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 522 statement.ColumnBlobAsVector(2, &data->data()); |
| 523 *png_icon_data = data; |
| 524 } |
| 525 |
| 526 if (pixel_size) { |
| 527 *pixel_size = gfx::Size(statement.ColumnInt(2), |
| 528 statement.ColumnInt(3)); |
| 529 } |
| 530 return true; |
| 531 } |
| 532 |
482 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( | 533 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( |
483 FaviconID icon_id, | 534 FaviconID icon_id, |
484 const scoped_refptr<base::RefCountedMemory>& icon_data, | 535 const scoped_refptr<base::RefCountedMemory>& icon_data, |
485 base::Time time, | 536 base::Time time, |
486 const gfx::Size& pixel_size) { | 537 const gfx::Size& pixel_size) { |
487 DCHECK(icon_id); | 538 DCHECK(icon_id); |
488 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 539 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
489 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " | 540 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " |
490 "height) VALUES (?, ?, ?, ?, ?)")); | 541 "height) VALUES (?, ?, ?, ?, ?)")); |
491 statement.BindInt64(0, icon_id); | 542 statement.BindInt64(0, icon_id); |
492 if (icon_data->size()) { | 543 if (icon_data->size()) { |
493 statement.BindBlob(1, icon_data->front(), | 544 statement.BindBlob(1, icon_data->front(), |
494 static_cast<int>(icon_data->size())); | 545 static_cast<int>(icon_data->size())); |
495 } else { | 546 } else { |
496 statement.BindNull(1); | 547 statement.BindNull(1); |
497 } | 548 } |
498 statement.BindInt64(2, time.ToTimeT()); | 549 statement.BindInt64(2, time.ToTimeT()); |
499 statement.BindInt(3, pixel_size.width()); | 550 statement.BindInt(3, pixel_size.width()); |
500 statement.BindInt(4, pixel_size.height()); | 551 statement.BindInt(4, pixel_size.height()); |
501 | 552 |
502 if (!statement.Run()) | 553 if (!statement.Run()) |
503 return 0; | 554 return 0; |
504 return db_.GetLastInsertRowId(); | 555 return db_.GetLastInsertRowId(); |
505 } | 556 } |
506 | 557 |
507 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { | 558 bool ThumbnailDatabase::SetFaviconBitmap( |
| 559 FaviconBitmapID bitmap_id, |
| 560 scoped_refptr<base::RefCountedMemory> icon_data, |
| 561 base::Time time) { |
| 562 DCHECK(bitmap_id); |
508 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 563 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
509 "DELETE FROM favicon_bitmaps WHERE icon_id=?")); | 564 "UPDATE favicon_bitmaps SET image_data=?, last_updated=? WHERE id=?")); |
510 statement.BindInt64(0, icon_id); | 565 if (icon_data.get() && icon_data->size()) { |
| 566 statement.BindBlob(0, icon_data->front(), |
| 567 static_cast<int>(icon_data->size())); |
| 568 } else { |
| 569 statement.BindNull(0); |
| 570 } |
| 571 statement.BindInt64(1, time.ToTimeT()); |
| 572 statement.BindInt64(2, bitmap_id); |
| 573 |
| 574 return statement.Run(); |
| 575 } |
| 576 |
| 577 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { |
| 578 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 579 "DELETE FROM favicon_bitmaps WHERE id=?")); |
| 580 statement.BindInt64(0, bitmap_id); |
511 return statement.Run(); | 581 return statement.Run(); |
512 } | 582 } |
513 | 583 |
514 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, | 584 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, |
515 const std::string& sizes) { | 585 const std::vector<gfx::Size>& sizes) { |
| 586 std::string sizes_as_string; |
| 587 FaviconSizesToDatabaseString(sizes, &sizes_as_string); |
| 588 |
516 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 589 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
517 "UPDATE favicons SET sizes=? WHERE id=?")); | 590 "UPDATE favicons SET sizes=? WHERE id=?")); |
518 statement.BindString(0, sizes); | 591 statement.BindString(0, sizes_as_string); |
519 statement.BindInt64(1, icon_id); | 592 statement.BindInt64(1, icon_id); |
520 | 593 |
521 return statement.Run(); | 594 return statement.Run(); |
522 } | 595 } |
523 | 596 |
524 bool ThumbnailDatabase::SetFaviconOutOfDate(FaviconID icon_id) { | 597 bool ThumbnailDatabase::SetFaviconOutOfDate(FaviconID icon_id) { |
525 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 598 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
526 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); | 599 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); |
527 statement.BindInt64(0, 0); | 600 statement.BindInt64(0, 0); |
528 statement.BindInt64(1, icon_id); | 601 statement.BindInt64(1, icon_id); |
529 | 602 |
530 return statement.Run(); | 603 return statement.Run(); |
531 } | 604 } |
532 | 605 |
533 FaviconID ThumbnailDatabase::GetFaviconIDForFaviconURL(const GURL& icon_url, | 606 FaviconID ThumbnailDatabase::GetFaviconIDForFaviconURL(const GURL& icon_url, |
534 int required_icon_type, | 607 int required_icon_type) { |
535 IconType* icon_type) { | |
536 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 608 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
537 "SELECT id, icon_type FROM favicons WHERE url=? AND (icon_type & ? > 0) " | 609 "SELECT id FROM favicons WHERE url=? AND (icon_type & ? > 0) " |
538 "ORDER BY icon_type DESC")); | 610 "ORDER BY icon_type DESC")); |
539 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); | 611 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); |
540 statement.BindInt(1, required_icon_type); | 612 statement.BindInt(1, required_icon_type); |
541 | 613 |
542 if (!statement.Step()) | 614 if (!statement.Step()) |
543 return 0; // not cached | 615 return 0; // not cached |
544 | |
545 if (icon_type) | |
546 *icon_type = static_cast<IconType>(statement.ColumnInt(1)); | |
547 return statement.ColumnInt64(0); | 616 return statement.ColumnInt64(0); |
548 } | 617 } |
549 | 618 |
550 bool ThumbnailDatabase::GetFavicon( | |
551 FaviconID icon_id, | |
552 base::Time* last_updated, | |
553 scoped_refptr<base::RefCountedMemory>* png_icon_data, | |
554 GURL* icon_url, | |
555 IconType* icon_type) { | |
556 DCHECK(icon_id); | |
557 | |
558 std::vector<FaviconBitmap> favicon_bitmaps; | |
559 if (!GetFaviconBitmaps(icon_id, &favicon_bitmaps)) | |
560 return false; | |
561 | |
562 if (favicon_bitmaps.empty()) | |
563 return false; | |
564 | |
565 if (last_updated) | |
566 *last_updated = favicon_bitmaps[0].last_updated; | |
567 | |
568 *png_icon_data = favicon_bitmaps[0].bitmap_data; | |
569 | |
570 return GetFaviconHeader(icon_id, icon_url, icon_type, NULL); | |
571 } | |
572 | |
573 bool ThumbnailDatabase::GetFaviconHeader( | 619 bool ThumbnailDatabase::GetFaviconHeader( |
574 FaviconID icon_id, | 620 FaviconID icon_id, |
575 GURL* icon_url, | 621 GURL* icon_url, |
576 IconType* icon_type, | 622 IconType* icon_type, |
577 std::string* sizes) { | 623 std::vector<gfx::Size>* sizes) { |
578 DCHECK(icon_id); | 624 DCHECK(icon_id); |
579 | 625 |
580 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 626 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
581 "SELECT url, icon_type, sizes FROM favicons WHERE id=?")); | 627 "SELECT url, icon_type, sizes FROM favicons WHERE id=?")); |
582 statement.BindInt64(0, icon_id); | 628 statement.BindInt64(0, icon_id); |
583 | 629 |
584 if (!statement.Step()) | 630 if (!statement.Step()) |
585 return false; // No entry for the id. | 631 return false; // No entry for the id. |
586 | 632 |
587 if (icon_url) | 633 if (icon_url) |
588 *icon_url = GURL(statement.ColumnString(0)); | 634 *icon_url = GURL(statement.ColumnString(0)); |
589 if (icon_type) | 635 if (icon_type) |
590 *icon_type = static_cast<history::IconType>(statement.ColumnInt(1)); | 636 *icon_type = static_cast<history::IconType>(statement.ColumnInt(1)); |
591 if (sizes) | 637 if (sizes) { |
592 *sizes = statement.ColumnString(2); | 638 if (!DatabaseStringToFaviconSizes(statement.ColumnString(2), sizes)) |
| 639 return false; |
| 640 } |
593 | 641 |
594 return true; | 642 return true; |
595 } | 643 } |
596 | 644 |
597 FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url, | 645 FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url, |
598 IconType icon_type) { | 646 IconType icon_type) { |
599 | 647 |
600 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 648 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
601 "INSERT INTO favicons (url, icon_type) VALUES (?, ?)")); | 649 "INSERT INTO favicons (url, icon_type) VALUES (?, ?)")); |
602 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); | 650 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); |
603 statement.BindInt(1, icon_type); | 651 statement.BindInt(1, icon_type); |
604 | 652 |
605 if (!statement.Run()) | 653 if (!statement.Run()) |
606 return 0; | 654 return 0; |
607 return db_.GetLastInsertRowId(); | 655 return db_.GetLastInsertRowId(); |
608 } | 656 } |
609 | 657 |
610 FaviconID ThumbnailDatabase::AddFavicon( | 658 FaviconID ThumbnailDatabase::AddFavicon( |
611 const GURL& icon_url, | 659 const GURL& icon_url, |
612 IconType icon_type, | 660 IconType icon_type, |
613 const std::string& sizes, | 661 const std::vector<gfx::Size>& sizes, |
614 const scoped_refptr<base::RefCountedMemory>& icon_data, | 662 const scoped_refptr<base::RefCountedMemory>& icon_data, |
615 base::Time time, | 663 base::Time time, |
616 const gfx::Size& pixel_size) { | 664 const gfx::Size& pixel_size) { |
617 FaviconID icon_id = AddFavicon(icon_url, icon_type); | 665 FaviconID icon_id = AddFavicon(icon_url, icon_type); |
618 if (!icon_id || | 666 if (!icon_id || |
619 !SetFaviconSizes(icon_id, sizes) || | 667 !SetFaviconSizes(icon_id, sizes) || |
620 !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) { | 668 !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) { |
621 return 0; | 669 return 0; |
622 } | 670 } |
623 return icon_id; | 671 return icon_id; |
624 } | 672 } |
625 | 673 |
626 bool ThumbnailDatabase::DeleteFavicon(FaviconID id) { | 674 bool ThumbnailDatabase::DeleteFavicon(FaviconID id) { |
627 sql::Statement statement; | 675 sql::Statement statement; |
628 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | 676 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, |
629 "DELETE FROM favicons WHERE id = ?")); | 677 "DELETE FROM favicons WHERE id = ?")); |
630 statement.BindInt64(0, id); | 678 statement.BindInt64(0, id); |
631 if (!statement.Run()) | 679 if (!statement.Run()) |
632 return false; | 680 return false; |
633 | 681 |
634 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | 682 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, |
635 "DELETE FROM favicon_bitmaps WHERE icon_id = ?")); | 683 "DELETE FROM favicon_bitmaps WHERE icon_id = ?")); |
636 statement.BindInt64(0, id); | 684 statement.BindInt64(0, id); |
637 return statement.Run(); | 685 return statement.Run(); |
638 } | 686 } |
639 | 687 |
640 bool ThumbnailDatabase::GetIconMappingForPageURL(const GURL& page_url, | 688 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
641 IconType required_icon_type, | 689 const GURL& page_url, |
642 IconMapping* icon_mapping) { | 690 int required_icon_types, |
643 std::vector<IconMapping> icon_mappings; | 691 std::vector<IconMapping>* filtered_mapping_data) { |
644 if (!GetIconMappingsForPageURL(page_url, &icon_mappings)) | 692 std::vector<IconMapping> mapping_data; |
| 693 if (!GetIconMappingsForPageURL(page_url, &mapping_data)) |
645 return false; | 694 return false; |
646 | 695 |
647 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); | 696 bool result = false; |
648 m != icon_mappings.end(); ++m) { | 697 for (std::vector<IconMapping>::iterator m = mapping_data.begin(); |
649 if (m->icon_type == required_icon_type) { | 698 m != mapping_data.end(); ++m) { |
650 if (icon_mapping != NULL) | 699 if (m->icon_type & required_icon_types) { |
651 *icon_mapping = *m; | 700 result = true; |
652 return true; | 701 if (filtered_mapping_data == NULL) |
| 702 return result; |
| 703 filtered_mapping_data->push_back(*m); |
653 } | 704 } |
654 } | 705 } |
655 | 706 return result; |
656 return false; | |
657 } | 707 } |
658 | 708 |
659 bool ThumbnailDatabase::GetIconMappingsForPageURL( | 709 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
660 const GURL& page_url, | 710 const GURL& page_url, |
661 std::vector<IconMapping>* mapping_data) { | 711 std::vector<IconMapping>* mapping_data) { |
662 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 712 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
663 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type " | 713 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
| 714 "favicons.url " |
664 "FROM icon_mapping " | 715 "FROM icon_mapping " |
665 "INNER JOIN favicons " | 716 "INNER JOIN favicons " |
666 "ON icon_mapping.icon_id = favicons.id " | 717 "ON icon_mapping.icon_id = favicons.id " |
667 "WHERE icon_mapping.page_url=? " | 718 "WHERE icon_mapping.page_url=? " |
668 "ORDER BY favicons.icon_type DESC")); | 719 "ORDER BY favicons.icon_type DESC")); |
669 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 720 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
670 | 721 |
671 bool result = false; | 722 bool result = false; |
672 while (statement.Step()) { | 723 while (statement.Step()) { |
673 result = true; | 724 result = true; |
(...skipping 23 matching lines...) Expand all Loading... |
697 } | 748 } |
698 | 749 |
699 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { | 750 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { |
700 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 751 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
701 "DELETE FROM icon_mapping WHERE page_url = ?")); | 752 "DELETE FROM icon_mapping WHERE page_url = ?")); |
702 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 753 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
703 | 754 |
704 return statement.Run(); | 755 return statement.Run(); |
705 } | 756 } |
706 | 757 |
| 758 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { |
| 759 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 760 "DELETE FROM icon_mapping WHERE id=?")); |
| 761 statement.BindInt64(0, mapping_id); |
| 762 |
| 763 return statement.Run(); |
| 764 } |
| 765 |
707 bool ThumbnailDatabase::HasMappingFor(FaviconID id) { | 766 bool ThumbnailDatabase::HasMappingFor(FaviconID id) { |
708 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 767 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
709 "SELECT id FROM icon_mapping " | 768 "SELECT id FROM icon_mapping " |
710 "WHERE icon_id=?")); | 769 "WHERE icon_id=?")); |
711 statement.BindInt64(0, id); | 770 statement.BindInt64(0, id); |
712 | 771 |
713 return statement.Step(); | 772 return statement.Step(); |
714 } | 773 } |
715 | 774 |
716 bool ThumbnailDatabase::CloneIconMapping(const GURL& old_page_url, | 775 bool ThumbnailDatabase::CloneIconMappings(const GURL& old_page_url, |
717 const GURL& new_page_url) { | 776 const GURL& new_page_url) { |
718 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 777 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
719 "SELECT icon_id FROM icon_mapping " | 778 "SELECT icon_id FROM icon_mapping " |
720 "WHERE page_url=?")); | 779 "WHERE page_url=?")); |
721 if (!statement.is_valid()) | 780 if (!statement.is_valid()) |
722 return false; | 781 return false; |
723 | 782 |
724 // Do nothing if there are existing bindings | 783 // Do nothing if there are existing bindings |
725 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); | 784 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); |
726 if (statement.Step()) | 785 if (statement.Step()) |
727 return true; | 786 return true; |
728 | 787 |
729 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | 788 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, |
730 "INSERT INTO icon_mapping (page_url, icon_id) " | 789 "INSERT INTO icon_mapping (page_url, icon_id) " |
731 "SELECT ?, icon_id FROM icon_mapping " | 790 "SELECT ?, icon_id FROM icon_mapping " |
732 "WHERE page_url = ?")); | 791 "WHERE page_url = ?")); |
733 | 792 |
734 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); | 793 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); |
735 statement.BindString(1, URLDatabase::GURLToDatabaseURL(old_page_url)); | 794 statement.BindString(1, URLDatabase::GURLToDatabaseURL(old_page_url)); |
736 return statement.Run(); | 795 return statement.Run(); |
737 } | 796 } |
738 | 797 |
739 bool ThumbnailDatabase::InitIconMappingEnumerator( | 798 bool ThumbnailDatabase::InitIconMappingEnumerator( |
740 IconType type, | 799 IconType type, |
741 IconMappingEnumerator* enumerator) { | 800 IconMappingEnumerator* enumerator) { |
742 DCHECK(!enumerator->statement_.is_valid()); | 801 DCHECK(!enumerator->statement_.is_valid()); |
743 enumerator->statement_.Assign(db_.GetCachedStatement( | 802 enumerator->statement_.Assign(db_.GetCachedStatement( |
744 SQL_FROM_HERE, | 803 SQL_FROM_HERE, |
745 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " | 804 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
746 "icon_mapping.page_url " | 805 "favicons.url, icon_mapping.page_url " |
747 "FROM icon_mapping JOIN favicons ON (" | 806 "FROM icon_mapping JOIN favicons ON (" |
748 "icon_mapping.icon_id = favicons.id) " | 807 "icon_mapping.icon_id = favicons.id) " |
749 "WHERE favicons.icon_type = ?")); | 808 "WHERE favicons.icon_type = ?")); |
750 enumerator->statement_.BindInt(0, type); | 809 enumerator->statement_.BindInt(0, type); |
751 return enumerator->statement_.is_valid(); | 810 return enumerator->statement_.is_valid(); |
752 } | 811 } |
753 | 812 |
754 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { | 813 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { |
755 URLDatabase::IconMappingEnumerator e; | 814 URLDatabase::IconMappingEnumerator e; |
756 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) | 815 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 db_.Execute("DROP TABLE favicons") && | 1069 db_.Execute("DROP TABLE favicons") && |
1011 db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons"); | 1070 db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons"); |
1012 if (!success) | 1071 if (!success) |
1013 return false; | 1072 return false; |
1014 | 1073 |
1015 meta_table_.SetVersionNumber(6); | 1074 meta_table_.SetVersionNumber(6); |
1016 meta_table_.SetCompatibleVersionNumber(std::min(6, kCompatibleVersionNumber)); | 1075 meta_table_.SetCompatibleVersionNumber(std::min(6, kCompatibleVersionNumber)); |
1017 return true; | 1076 return true; |
1018 } | 1077 } |
1019 | 1078 |
| 1079 // static |
| 1080 void ThumbnailDatabase::FaviconSizesToDatabaseString( |
| 1081 const FaviconSizes& sizes, |
| 1082 std::string* sizes_string) { |
| 1083 std::vector<std::string> parts; |
| 1084 for (std::vector<gfx::Size>::const_iterator it = sizes.begin(); |
| 1085 it != sizes.end(); ++it) { |
| 1086 parts.push_back(base::IntToString(it->width())); |
| 1087 parts.push_back(base::IntToString(it->height())); |
| 1088 } |
| 1089 *sizes_string = JoinString(parts, ' '); |
| 1090 } |
| 1091 |
| 1092 // static |
| 1093 bool ThumbnailDatabase::DatabaseStringToFaviconSizes( |
| 1094 const std::string sizes_string, |
| 1095 FaviconSizes* sizes) { |
| 1096 bool no_errors = true; |
| 1097 |
| 1098 StringTokenizer t(sizes_string, " "); |
| 1099 while (t.GetNext() && no_errors) { |
| 1100 int width, height = 0; |
| 1101 no_errors &= base::StringToInt(t.token(), &width); |
| 1102 if (!t.GetNext()) { |
| 1103 no_errors = false; |
| 1104 break; |
| 1105 } |
| 1106 no_errors &= base::StringToInt(t.token(), &height); |
| 1107 sizes->push_back(gfx::Size(width, height)); |
| 1108 } |
| 1109 |
| 1110 if (!no_errors) |
| 1111 sizes->clear(); |
| 1112 |
| 1113 return no_errors; |
| 1114 } |
| 1115 |
1020 } // namespace history | 1116 } // namespace history |
OLD | NEW |