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/dom_ui/dom_ui_thumbnail_source.h" | 5 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" |
6 | 6 |
7 #include "app/gfx/codec/jpeg_codec.h" | 7 #include "app/gfx/codec/jpeg_codec.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 void DOMUIThumbnailSource::DoDataRequest(const std::string& path, | 57 void DOMUIThumbnailSource::DoDataRequest(const std::string& path, |
58 int request_id) { | 58 int request_id) { |
59 RefCountedBytes* data = NULL; | 59 RefCountedBytes* data = NULL; |
60 scoped_refptr<ThumbnailStore> store_ = profile_->GetThumbnailStore(); | 60 scoped_refptr<ThumbnailStore> store_ = profile_->GetThumbnailStore(); |
61 if (store_->GetPageThumbnail(GURL(path), &data)) { | 61 if (store_->GetPageThumbnail(GURL(path), &data)) { |
62 // Got the thumbnail. | 62 // Got the thumbnail. |
63 SendResponse(request_id, data); | 63 SendResponse(request_id, data); |
64 } else { | 64 } else { |
65 // Don't have the thumbnail so return the default thumbnail. | 65 // Don't have the thumbnail so return the default thumbnail. |
66 if (!default_thumbnail_.get()) { | 66 if (!default_thumbnail_.get()) { |
67 default_thumbnail_ = new RefCountedBytes; | 67 default_thumbnail_ = |
68 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( | 68 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( |
69 IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data); | 69 IDR_DEFAULT_THUMBNAIL); |
70 } | 70 } |
71 SendResponse(request_id, default_thumbnail_); | 71 SendResponse(request_id, default_thumbnail_); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void DOMUIThumbnailSource::OnThumbnailDataAvailable( | 75 void DOMUIThumbnailSource::OnThumbnailDataAvailable( |
76 HistoryService::Handle request_handle, | 76 HistoryService::Handle request_handle, |
77 scoped_refptr<RefCountedBytes> data) { | 77 scoped_refptr<RefCountedBytes> data) { |
78 HistoryService* hs = | 78 HistoryService* hs = |
79 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 79 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
80 int request_id = cancelable_consumer_.GetClientData(hs, request_handle); | 80 int request_id = cancelable_consumer_.GetClientData(hs, request_handle); |
81 // Forward the data along to the networking system. | 81 // Forward the data along to the networking system. |
82 if (data.get() && !data->data.empty()) { | 82 if (data.get() && !data->data.empty()) { |
83 SendResponse(request_id, data); | 83 SendResponse(request_id, data); |
84 } else { | 84 } else { |
85 if (!default_thumbnail_.get()) { | 85 if (!default_thumbnail_.get()) { |
86 default_thumbnail_ = new RefCountedBytes; | 86 default_thumbnail_ = |
87 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( | 87 ResourceBundle::GetSharedInstance().LoadImageResourceBytes( |
88 IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data); | 88 IDR_DEFAULT_THUMBNAIL); |
89 } | 89 } |
90 | 90 |
91 SendResponse(request_id, default_thumbnail_); | 91 SendResponse(request_id, default_thumbnail_); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void DOMUIThumbnailSource::Observe(NotificationType type, | 95 void DOMUIThumbnailSource::Observe(NotificationType type, |
96 const NotificationSource& source, | 96 const NotificationSource& source, |
97 const NotificationDetails& details) { | 97 const NotificationDetails& details) { |
98 if (type.value != NotificationType::THUMBNAIL_STORE_READY) { | 98 if (type.value != NotificationType::THUMBNAIL_STORE_READY) { |
99 NOTREACHED(); | 99 NOTREACHED(); |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 // This notification is sent only once. | 103 // This notification is sent only once. |
104 registrar_.RemoveAll(); | 104 registrar_.RemoveAll(); |
105 | 105 |
106 for (size_t i = 0; i < pending_requests_.size(); ++i) | 106 for (size_t i = 0; i < pending_requests_.size(); ++i) |
107 DoDataRequest(pending_requests_[i].first, pending_requests_[i].second); | 107 DoDataRequest(pending_requests_[i].first, pending_requests_[i].second); |
108 | 108 |
109 pending_requests_.clear(); | 109 pending_requests_.clear(); |
110 } | 110 } |
OLD | NEW |