OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 5 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/worker_pool.h" | 8 #include "base/threading/worker_pool.h" |
9 #include "content/browser/frame_host/navigation_controller_impl.h" | 9 #include "content/browser/frame_host/navigation_controller_impl.h" |
10 #include "content/browser/frame_host/navigation_entry_impl.h" | 10 #include "content/browser/frame_host/navigation_entry_impl.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 break; | 159 break; |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 if (!entry) { | 163 if (!entry) { |
164 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; | 164 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; |
165 return; | 165 return; |
166 } | 166 } |
167 | 167 |
168 if (!success || bitmap.empty() || bitmap.isNull()) { | 168 if (!success || bitmap.empty() || bitmap.isNull()) { |
169 if (!ClearScreenshot(entry)) | 169 ClearScreenshot(entry); |
170 OnScreenshotSet(entry); | |
171 return; | 170 return; |
172 } | 171 } |
173 | 172 |
174 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData(); | 173 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData(); |
175 screenshot->EncodeScreenshot( | 174 screenshot->EncodeScreenshot( |
176 bitmap, | 175 bitmap, |
177 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete, | 176 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete, |
178 screenshot_factory_.GetWeakPtr(), | 177 screenshot_factory_.GetWeakPtr(), |
179 unique_id, | 178 unique_id, |
180 screenshot)); | 179 screenshot)); |
(...skipping 24 matching lines...) Expand all Loading... |
205 } | 204 } |
206 } | 205 } |
207 if (!entry) | 206 if (!entry) |
208 return; | 207 return; |
209 entry->SetScreenshotPNGData(screenshot->data()); | 208 entry->SetScreenshotPNGData(screenshot->data()); |
210 OnScreenshotSet(entry); | 209 OnScreenshotSet(entry); |
211 } | 210 } |
212 | 211 |
213 void NavigationEntryScreenshotManager::OnScreenshotSet( | 212 void NavigationEntryScreenshotManager::OnScreenshotSet( |
214 NavigationEntryImpl* entry) { | 213 NavigationEntryImpl* entry) { |
215 if (entry->screenshot().get()) | 214 CHECK(entry->screenshot().get()); |
216 PurgeScreenshotsIfNecessary(); | 215 PurgeScreenshotsIfNecessary(); |
217 } | 216 } |
218 | 217 |
219 bool NavigationEntryScreenshotManager::ClearScreenshot( | 218 bool NavigationEntryScreenshotManager::ClearScreenshot( |
220 NavigationEntryImpl* entry) { | 219 NavigationEntryImpl* entry) { |
221 if (!entry->screenshot().get()) | 220 if (!entry->screenshot().get()) |
222 return false; | 221 return false; |
223 | 222 |
224 entry->SetScreenshotPNGData(NULL); | 223 entry->SetScreenshotPNGData(NULL); |
225 return true; | 224 return true; |
226 } | 225 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 owner_->GetEntryAtIndex(forward)); | 283 owner_->GetEntryAtIndex(forward)); |
285 if (ClearScreenshot(entry)) | 284 if (ClearScreenshot(entry)) |
286 --screenshot_count; | 285 --screenshot_count; |
287 ++forward; | 286 ++forward; |
288 } | 287 } |
289 CHECK_GE(screenshot_count, 0); | 288 CHECK_GE(screenshot_count, 0); |
290 CHECK_LE(screenshot_count, kMaxScreenshots); | 289 CHECK_LE(screenshot_count, kMaxScreenshots); |
291 } | 290 } |
292 | 291 |
293 } // namespace content | 292 } // namespace content |
OLD | NEW |