| 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" |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 *icon_url = GURL(statement.ColumnString(0)); | 568 *icon_url = GURL(statement.ColumnString(0)); |
| 569 if (icon_type) | 569 if (icon_type) |
| 570 *icon_type = static_cast<history::IconType>(statement.ColumnInt(1)); | 570 *icon_type = static_cast<history::IconType>(statement.ColumnInt(1)); |
| 571 if (favicon_sizes) | 571 if (favicon_sizes) |
| 572 DatabaseStringToFaviconSizes(statement.ColumnString(2), favicon_sizes); | 572 DatabaseStringToFaviconSizes(statement.ColumnString(2), favicon_sizes); |
| 573 | 573 |
| 574 return true; | 574 return true; |
| 575 } | 575 } |
| 576 | 576 |
| 577 FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url, | 577 FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url, |
| 578 IconType icon_type) { | 578 IconType icon_type, |
| 579 const FaviconSizes& favicon_sizes) { |
| 580 std::string favicon_sizes_as_string; |
| 581 FaviconSizesToDatabaseString(favicon_sizes, &favicon_sizes_as_string); |
| 579 | 582 |
| 580 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 583 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 581 "INSERT INTO favicons (url, icon_type) VALUES (?, ?)")); | 584 "INSERT INTO favicons (url, icon_type, sizes) VALUES (?, ?, ?)")); |
| 582 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); | 585 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); |
| 583 statement.BindInt(1, icon_type); | 586 statement.BindInt(1, icon_type); |
| 587 statement.BindString(2, favicon_sizes_as_string); |
| 584 | 588 |
| 585 if (!statement.Run()) | 589 if (!statement.Run()) |
| 586 return 0; | 590 return 0; |
| 587 return db_.GetLastInsertRowId(); | 591 return db_.GetLastInsertRowId(); |
| 588 } | 592 } |
| 589 | 593 |
| 590 FaviconID ThumbnailDatabase::AddFavicon( | 594 FaviconID ThumbnailDatabase::AddFavicon( |
| 591 const GURL& icon_url, | 595 const GURL& icon_url, |
| 592 IconType icon_type, | 596 IconType icon_type, |
| 593 const FaviconSizes& favicon_sizes, | 597 const FaviconSizes& favicon_sizes, |
| 594 const scoped_refptr<base::RefCountedMemory>& icon_data, | 598 const scoped_refptr<base::RefCountedMemory>& icon_data, |
| 595 base::Time time, | 599 base::Time time, |
| 596 const gfx::Size& pixel_size) { | 600 const gfx::Size& pixel_size) { |
| 597 FaviconID icon_id = AddFavicon(icon_url, icon_type); | 601 FaviconID icon_id = AddFavicon(icon_url, icon_type, favicon_sizes); |
| 598 if (!icon_id || | 602 if (!icon_id || !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) |
| 599 !SetFaviconSizes(icon_id, favicon_sizes) || | |
| 600 !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) { | |
| 601 return 0; | 603 return 0; |
| 602 } | 604 |
| 603 return icon_id; | 605 return icon_id; |
| 604 } | 606 } |
| 605 | 607 |
| 606 bool ThumbnailDatabase::DeleteFavicon(FaviconID id) { | 608 bool ThumbnailDatabase::DeleteFavicon(FaviconID id) { |
| 607 sql::Statement statement; | 609 sql::Statement statement; |
| 608 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | 610 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, |
| 609 "DELETE FROM favicons WHERE id = ?")); | 611 "DELETE FROM favicons WHERE id = ?")); |
| 610 statement.BindInt64(0, id); | 612 statement.BindInt64(0, id); |
| 611 if (!statement.Run()) | 613 if (!statement.Run()) |
| 612 return false; | 614 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 625 if (!GetIconMappingsForPageURL(page_url, &mapping_data)) | 627 if (!GetIconMappingsForPageURL(page_url, &mapping_data)) |
| 626 return false; | 628 return false; |
| 627 | 629 |
| 628 bool result = false; | 630 bool result = false; |
| 629 for (std::vector<IconMapping>::iterator m = mapping_data.begin(); | 631 for (std::vector<IconMapping>::iterator m = mapping_data.begin(); |
| 630 m != mapping_data.end(); ++m) { | 632 m != mapping_data.end(); ++m) { |
| 631 if (m->icon_type & required_icon_types) { | 633 if (m->icon_type & required_icon_types) { |
| 632 result = true; | 634 result = true; |
| 633 if (!filtered_mapping_data) | 635 if (!filtered_mapping_data) |
| 634 return result; | 636 return result; |
| 637 |
| 638 // Restrict icon type of subsequent matches to |m->icon_type|. |
| 639 // |m->icon_type| is the largest IconType in |mapping_data| because |
| 640 // |mapping_data| is sorted in descending order of IconType. |
| 641 required_icon_types = m->icon_type; |
| 642 |
| 635 filtered_mapping_data->push_back(*m); | 643 filtered_mapping_data->push_back(*m); |
| 636 } | 644 } |
| 637 } | 645 } |
| 638 return result; | 646 return result; |
| 639 } | 647 } |
| 640 | 648 |
| 641 bool ThumbnailDatabase::GetIconMappingsForPageURL( | 649 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
| 642 const GURL& page_url, | 650 const GURL& page_url, |
| 643 std::vector<IconMapping>* mapping_data) { | 651 std::vector<IconMapping>* mapping_data) { |
| 644 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 652 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1044 } |
| 1037 parsing_errors |= !base::StringToInt(t.token(), &height); | 1045 parsing_errors |= !base::StringToInt(t.token(), &height); |
| 1038 favicon_sizes->push_back(gfx::Size(width, height)); | 1046 favicon_sizes->push_back(gfx::Size(width, height)); |
| 1039 } | 1047 } |
| 1040 | 1048 |
| 1041 if (parsing_errors) | 1049 if (parsing_errors) |
| 1042 favicon_sizes->clear(); | 1050 favicon_sizes->clear(); |
| 1043 } | 1051 } |
| 1044 | 1052 |
| 1045 } // namespace history | 1053 } // namespace history |
| OLD | NEW |