| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/codec/jpeg_codec.h" | 7 #include "app/gfx/codec/jpeg_codec.h" |
| 8 #include "app/sql/statement.h" | 8 #include "app/sql/statement.h" |
| 9 #include "app/sql/transaction.h" | 9 #include "app/sql/transaction.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 105 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
| 106 "Thumbnail database version " << cur_version << " is too old to handle."; | 106 "Thumbnail database version " << cur_version << " is too old to handle."; |
| 107 | 107 |
| 108 // Initialization is complete. | 108 // Initialization is complete. |
| 109 if (!transaction.Commit()) { | 109 if (!transaction.Commit()) { |
| 110 db_.Close(); | 110 db_.Close(); |
| 111 return INIT_FAILURE; | 111 return INIT_FAILURE; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // The following code is useful in debugging the thumbnail database. Upon | |
| 115 // startup, it will spit out a file for each thumbnail in the database so you | |
| 116 // can open them in an external viewer. Insert the path name on your system | |
| 117 // into the string below (I recommend using a blank directory since there may | |
| 118 // be a lot of files). | |
| 119 #if 0 | |
| 120 sql::Statement statement(db_.GetUniqueStatement( | |
| 121 "SELECT id, image_data FROM favicons")); | |
| 122 while (statement.Step()) { | |
| 123 int idx = statement.ColumnInt(0); | |
| 124 std::vector<unsigned char> data; | |
| 125 statement.ColumnBlobAsVector(1, &data); | |
| 126 | |
| 127 char filename[256]; | |
| 128 sprintf(filename, "<<< YOUR PATH HERE >>>\\%d.png", idx); | |
| 129 if (!data.empty()) { | |
| 130 file_util::WriteFile(ASCIIToWide(std::string(filename)), | |
| 131 reinterpret_cast<char*>(&data[0]), | |
| 132 data.size()); | |
| 133 } | |
| 134 } | |
| 135 #endif | |
| 136 | |
| 137 return INIT_OK; | 114 return INIT_OK; |
| 138 } | 115 } |
| 139 | 116 |
| 140 bool ThumbnailDatabase::InitThumbnailTable() { | 117 bool ThumbnailDatabase::InitThumbnailTable() { |
| 141 if (!db_.DoesTableExist("thumbnails")) { | 118 if (!db_.DoesTableExist("thumbnails")) { |
| 142 if (!db_.Execute("CREATE TABLE thumbnails (" | 119 if (!db_.Execute("CREATE TABLE thumbnails (" |
| 143 "url_id INTEGER PRIMARY KEY," | 120 "url_id INTEGER PRIMARY KEY," |
| 144 "boring_score DOUBLE DEFAULT 1.0," | 121 "boring_score DOUBLE DEFAULT 1.0," |
| 145 "good_clipping INTEGER DEFAULT 0," | 122 "good_clipping INTEGER DEFAULT 0," |
| 146 "at_top INTEGER DEFAULT 0," | 123 "at_top INTEGER DEFAULT 0," |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // Rename the temporary one. | 425 // Rename the temporary one. |
| 449 if (!db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons")) | 426 if (!db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons")) |
| 450 return false; | 427 return false; |
| 451 | 428 |
| 452 // The renamed table needs the index (the temporary table doesn't have one). | 429 // The renamed table needs the index (the temporary table doesn't have one). |
| 453 InitFavIconsIndex(); | 430 InitFavIconsIndex(); |
| 454 return true; | 431 return true; |
| 455 } | 432 } |
| 456 | 433 |
| 457 } // namespace history | 434 } // namespace history |
| OLD | NEW |