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/thumbnail_store.h" | 5 #include "chrome/browser/thumbnail_store.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
| 10 #include "app/gfx/codec/jpeg_codec.h" |
10 #include "app/sql/statement.h" | 11 #include "app/sql/statement.h" |
11 #include "app/sql/transaction.h" | 12 #include "app/sql/transaction.h" |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
14 #include "base/gfx/jpeg_codec.h" | |
15 #include "base/md5.h" | 15 #include "base/md5.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/thread.h" | 17 #include "base/thread.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
21 #include "chrome/common/pref_service.h" | 21 #include "chrome/common/pref_service.h" |
22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
24 | 24 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (!ShouldStoreThumbnailForURL(url) || | 70 if (!ShouldStoreThumbnailForURL(url) || |
71 (cache_->find(url) != cache_->end() && | 71 (cache_->find(url) != cache_->end() && |
72 !ShouldReplaceThumbnailWith((*cache_)[url].score_, score))) | 72 !ShouldReplaceThumbnailWith((*cache_)[url].score_, score))) |
73 return true; | 73 return true; |
74 | 74 |
75 base::TimeTicks encode_start = base::TimeTicks::Now(); | 75 base::TimeTicks encode_start = base::TimeTicks::Now(); |
76 | 76 |
77 // Encode the SkBitmap to jpeg. | 77 // Encode the SkBitmap to jpeg. |
78 scoped_refptr<RefCountedBytes> jpeg_data = new RefCountedBytes; | 78 scoped_refptr<RefCountedBytes> jpeg_data = new RefCountedBytes; |
79 SkAutoLockPixels thumbnail_lock(thumbnail); | 79 SkAutoLockPixels thumbnail_lock(thumbnail); |
80 bool encoded = JPEGCodec::Encode( | 80 bool encoded = gfx::JPEGCodec::Encode( |
81 reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), | 81 reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), |
82 JPEGCodec::FORMAT_BGRA, thumbnail.width(), | 82 gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), |
83 thumbnail.height(), | 83 thumbnail.height(), |
84 static_cast<int>(thumbnail.rowBytes()), 90, | 84 static_cast<int>(thumbnail.rowBytes()), 90, |
85 &jpeg_data->data); | 85 &jpeg_data->data); |
86 | 86 |
87 base::TimeDelta delta = base::TimeTicks::Now() - encode_start; | 87 base::TimeDelta delta = base::TimeTicks::Now() - encode_start; |
88 HISTOGRAM_TIMES("Thumbnail.Encode", delta); | 88 HISTOGRAM_TIMES("Thumbnail.Encode", delta); |
89 | 89 |
90 if (!encoded) | 90 if (!encoded) |
91 return false; | 91 return false; |
92 | 92 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 425 |
426 std::wstring ThumbnailStore::GetDictionaryKeyForURL( | 426 std::wstring ThumbnailStore::GetDictionaryKeyForURL( |
427 const std::string& url) const { | 427 const std::string& url) const { |
428 return ASCIIToWide(MD5String(url)); | 428 return ASCIIToWide(MD5String(url)); |
429 } | 429 } |
430 | 430 |
431 bool ThumbnailStore::IsPopular(const GURL& url) const { | 431 bool ThumbnailStore::IsPopular(const GURL& url) const { |
432 return most_visited_urls_->size() < kMaxCacheSize || | 432 return most_visited_urls_->size() < kMaxCacheSize || |
433 most_visited_urls_->find(url) != most_visited_urls_->end(); | 433 most_visited_urls_->find(url) != most_visited_urls_->end(); |
434 } | 434 } |
OLD | NEW |