Chromium Code Reviews| 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 "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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 538 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 539 "SELECT id FROM icon_mapping " | 539 "SELECT id FROM icon_mapping " |
| 540 "WHERE icon_id=?")); | 540 "WHERE icon_id=?")); |
| 541 if (!statement) | 541 if (!statement) |
| 542 return false; | 542 return false; |
| 543 | 543 |
| 544 statement.BindInt64(0, id); | 544 statement.BindInt64(0, id); |
| 545 return statement.Step(); | 545 return statement.Step(); |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool ThumbnailDatabase::CloneIconMapping(const GURL& old_page_url, | |
| 549 const GURL& new_page_url) { | |
| 550 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 551 "SELECT COUNT(*) FROM icon_mapping " | |
| 552 "WHERE page_url=?")); | |
| 553 if (!statement) | |
| 554 return false; | |
| 555 | |
| 556 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); | |
| 557 if (!statement.Step()) | |
| 558 return false; | |
| 559 | |
| 560 // Do nothing if there are existing bindings | |
| 561 if (statement.ColumnInt(0) != 0) | |
| 562 return true; | |
| 563 | |
| 564 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 565 "INSERT INTO icon_mapping (page_url, icon_id) " | |
|
Greg Billock
2011/11/11 17:47:56
Will sqlite support a fancier conditional insert h
groby-ooo-7-16
2011/11/14 23:53:36
yes, fancier statements are supported. Here's what
| |
| 566 "SELECT ?, icon_id FROM icon_mapping " | |
| 567 "WHERE page_url = ?")); | |
| 568 if (!statement) | |
| 569 return false; | |
| 570 | |
| 571 statement.BindString(0, URLDatabase::GURLToDatabaseURL(new_page_url)); | |
| 572 statement.BindString(1, URLDatabase::GURLToDatabaseURL(old_page_url)); | |
| 573 return statement.Run(); | |
| 574 } | |
| 575 | |
| 576 | |
| 548 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { | 577 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { |
| 549 URLDatabase::IconMappingEnumerator e; | 578 URLDatabase::IconMappingEnumerator e; |
| 550 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) | 579 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) |
| 551 return false; | 580 return false; |
| 552 | 581 |
| 553 IconMapping info; | 582 IconMapping info; |
| 554 while (e.GetNextIconMapping(&info)) { | 583 while (e.GetNextIconMapping(&info)) { |
| 555 // TODO: Using bulk insert to improve the performance. | 584 // TODO: Using bulk insert to improve the performance. |
| 556 if (!AddIconMapping(info.page_url, info.icon_id)) | 585 if (!AddIconMapping(info.page_url, info.icon_id)) |
| 557 return false; | 586 return false; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 if (!db_.Execute("ALTER TABLE favicons ADD sizes LONGVARCHAR")) { | 782 if (!db_.Execute("ALTER TABLE favicons ADD sizes LONGVARCHAR")) { |
| 754 NOTREACHED(); | 783 NOTREACHED(); |
| 755 return false; | 784 return false; |
| 756 } | 785 } |
| 757 meta_table_.SetVersionNumber(5); | 786 meta_table_.SetVersionNumber(5); |
| 758 meta_table_.SetCompatibleVersionNumber(std::min(5, kCompatibleVersionNumber)); | 787 meta_table_.SetCompatibleVersionNumber(std::min(5, kCompatibleVersionNumber)); |
| 759 return true; | 788 return true; |
| 760 } | 789 } |
| 761 | 790 |
| 762 } // namespace history | 791 } // namespace history |
| OLD | NEW |