| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 *thumbnail, kImageQuality, &jpeg_data); | 366 *thumbnail, kImageQuality, &jpeg_data); |
| 367 if (encoded) { | 367 if (encoded) { |
| 368 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 368 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 369 "INSERT OR REPLACE INTO thumbnails " | 369 "INSERT OR REPLACE INTO thumbnails " |
| 370 "(url_id, boring_score, good_clipping, at_top, last_updated, data) " | 370 "(url_id, boring_score, good_clipping, at_top, last_updated, data) " |
| 371 "VALUES (?,?,?,?,?,?)")); | 371 "VALUES (?,?,?,?,?,?)")); |
| 372 statement.BindInt64(0, id); | 372 statement.BindInt64(0, id); |
| 373 statement.BindDouble(1, score.boring_score); | 373 statement.BindDouble(1, score.boring_score); |
| 374 statement.BindBool(2, score.good_clipping); | 374 statement.BindBool(2, score.good_clipping); |
| 375 statement.BindBool(3, score.at_top); | 375 statement.BindBool(3, score.at_top); |
| 376 statement.BindInt64(4, score.time_at_snapshot.ToTimeT()); | 376 statement.BindInt64(4, score.time_at_snapshot.ToInternalValue()); |
| 377 statement.BindBlob(5, &jpeg_data[0], | 377 statement.BindBlob(5, &jpeg_data[0], |
| 378 static_cast<int>(jpeg_data.size())); | 378 static_cast<int>(jpeg_data.size())); |
| 379 | 379 |
| 380 if (!statement.Run()) | 380 if (!statement.Run()) |
| 381 return false; | 381 return false; |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Publish the thumbnail to any indexers listening to us. | 384 // Publish the thumbnail to any indexers listening to us. |
| 385 // The tests may send an invalid url. Hence avoid publishing those. | 385 // The tests may send an invalid url. Hence avoid publishing those. |
| 386 if (url.is_valid() && history_publisher_ != NULL) | 386 if (url.is_valid() && history_publisher_ != NULL) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 "FROM thumbnails WHERE url_id=?")); | 434 "FROM thumbnails WHERE url_id=?")); |
| 435 select_statement.BindInt64(0, id); | 435 select_statement.BindInt64(0, id); |
| 436 | 436 |
| 437 if (!select_statement.Step()) | 437 if (!select_statement.Step()) |
| 438 return false; | 438 return false; |
| 439 | 439 |
| 440 double current_boring_score = select_statement.ColumnDouble(0); | 440 double current_boring_score = select_statement.ColumnDouble(0); |
| 441 bool current_clipping = select_statement.ColumnBool(1); | 441 bool current_clipping = select_statement.ColumnBool(1); |
| 442 bool current_at_top = select_statement.ColumnBool(2); | 442 bool current_at_top = select_statement.ColumnBool(2); |
| 443 base::Time last_updated = | 443 base::Time last_updated = |
| 444 base::Time::FromTimeT(select_statement.ColumnInt64(3)); | 444 base::Time::FromInternalValue(select_statement.ColumnInt64(3)); |
| 445 *score = ThumbnailScore(current_boring_score, current_clipping, | 445 *score = ThumbnailScore(current_boring_score, current_clipping, |
| 446 current_at_top, last_updated); | 446 current_at_top, last_updated); |
| 447 return true; | 447 return true; |
| 448 } | 448 } |
| 449 | 449 |
| 450 bool ThumbnailDatabase::GetFaviconBitmaps( | 450 bool ThumbnailDatabase::GetFaviconBitmaps( |
| 451 FaviconID icon_id, | 451 FaviconID icon_id, |
| 452 std::vector<FaviconBitmap>* favicon_bitmaps) { | 452 std::vector<FaviconBitmap>* favicon_bitmaps) { |
| 453 DCHECK(icon_id); | 453 DCHECK(icon_id); |
| 454 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 454 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 455 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " | 455 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " |
| 456 "WHERE icon_id=?")); | 456 "WHERE icon_id=?")); |
| 457 statement.BindInt64(0, icon_id); | 457 statement.BindInt64(0, icon_id); |
| 458 | 458 |
| 459 bool result = false; | 459 bool result = false; |
| 460 while (statement.Step()) { | 460 while (statement.Step()) { |
| 461 result = true; | 461 result = true; |
| 462 if (!favicon_bitmaps) | 462 if (!favicon_bitmaps) |
| 463 return result; | 463 return result; |
| 464 | 464 |
| 465 FaviconBitmap favicon_bitmap; | 465 FaviconBitmap favicon_bitmap; |
| 466 favicon_bitmap.bitmap_id = statement.ColumnInt64(0); | 466 favicon_bitmap.bitmap_id = statement.ColumnInt64(0); |
| 467 favicon_bitmap.icon_id = icon_id; | 467 favicon_bitmap.icon_id = icon_id; |
| 468 favicon_bitmap.last_updated = | 468 favicon_bitmap.last_updated = |
| 469 base::Time::FromTimeT(statement.ColumnInt64(1)); | 469 base::Time::FromInternalValue(statement.ColumnInt64(1)); |
| 470 if (statement.ColumnByteLength(2) > 0) { | 470 if (statement.ColumnByteLength(2) > 0) { |
| 471 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | 471 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 472 statement.ColumnBlobAsVector(2, &data->data()); | 472 statement.ColumnBlobAsVector(2, &data->data()); |
| 473 favicon_bitmap.bitmap_data = data; | 473 favicon_bitmap.bitmap_data = data; |
| 474 } | 474 } |
| 475 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), | 475 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), |
| 476 statement.ColumnInt(4)); | 476 statement.ColumnInt(4)); |
| 477 favicon_bitmaps->push_back(favicon_bitmap); | 477 favicon_bitmaps->push_back(favicon_bitmap); |
| 478 } | 478 } |
| 479 return result; | 479 return result; |
| 480 } | 480 } |
| 481 | 481 |
| 482 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( | 482 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( |
| 483 FaviconID icon_id, | 483 FaviconID icon_id, |
| 484 const scoped_refptr<base::RefCountedMemory>& icon_data, | 484 const scoped_refptr<base::RefCountedMemory>& icon_data, |
| 485 base::Time time, | 485 base::Time time, |
| 486 const gfx::Size& pixel_size) { | 486 const gfx::Size& pixel_size) { |
| 487 DCHECK(icon_id); | 487 DCHECK(icon_id); |
| 488 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 488 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 489 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " | 489 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " |
| 490 "height) VALUES (?, ?, ?, ?, ?)")); | 490 "height) VALUES (?, ?, ?, ?, ?)")); |
| 491 statement.BindInt64(0, icon_id); | 491 statement.BindInt64(0, icon_id); |
| 492 if (icon_data.get() && icon_data->size()) { | 492 if (icon_data.get() && icon_data->size()) { |
| 493 statement.BindBlob(1, icon_data->front(), | 493 statement.BindBlob(1, icon_data->front(), |
| 494 static_cast<int>(icon_data->size())); | 494 static_cast<int>(icon_data->size())); |
| 495 } else { | 495 } else { |
| 496 statement.BindNull(1); | 496 statement.BindNull(1); |
| 497 } | 497 } |
| 498 statement.BindInt64(2, time.ToTimeT()); | 498 statement.BindInt64(2, time.ToInternalValue()); |
| 499 statement.BindInt(3, pixel_size.width()); | 499 statement.BindInt(3, pixel_size.width()); |
| 500 statement.BindInt(4, pixel_size.height()); | 500 statement.BindInt(4, pixel_size.height()); |
| 501 | 501 |
| 502 if (!statement.Run()) | 502 if (!statement.Run()) |
| 503 return 0; | 503 return 0; |
| 504 return db_.GetLastInsertRowId(); | 504 return db_.GetLastInsertRowId(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { | 507 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { |
| 508 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 508 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 } | 1028 } |
| 1029 parsing_errors |= !base::StringToInt(t.token(), &height); | 1029 parsing_errors |= !base::StringToInt(t.token(), &height); |
| 1030 favicon_sizes->push_back(gfx::Size(width, height)); | 1030 favicon_sizes->push_back(gfx::Size(width, height)); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 if (parsing_errors) | 1033 if (parsing_errors) |
| 1034 favicon_sizes->clear(); | 1034 favicon_sizes->clear(); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 } // namespace history | 1037 } // namespace history |
| OLD | NEW |