Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: content/browser/frame_host/navigation_entry_screenshot_manager.cc

Issue 213413005: Ensure RenderViewHost is not shut down until a screenshot of the page is taken. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementing review feedback. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 entry->GetUniqueID()), 143 entry->GetUniqueID()),
144 preferred_format); 144 preferred_format);
145 } 145 }
146 146
147 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( 147 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS(
148 int interval_ms) { 148 int interval_ms) {
149 DCHECK_GE(interval_ms, 0); 149 DCHECK_GE(interval_ms, 0);
150 min_screenshot_interval_ms_ = interval_ms; 150 min_screenshot_interval_ms_ = interval_ms;
151 } 151 }
152 152
153 void NavigationEntryScreenshotManager::OnScreenshotTaken(int unique_id, 153 void NavigationEntryScreenshotManager::OnScreenshotTaken(
154 bool success, 154 int unique_id,
155 const SkBitmap& bitmap) { 155 bool success,
156 const SkBitmap& bitmap) {
156 NavigationEntryImpl* entry = NULL; 157 NavigationEntryImpl* entry = NULL;
157 int entry_count = owner_->GetEntryCount(); 158 int entry_count = owner_->GetEntryCount();
158 for (int i = 0; i < entry_count; ++i) { 159 for (int i = 0; i < entry_count; ++i) {
159 NavigationEntry* iter = owner_->GetEntryAtIndex(i); 160 NavigationEntry* iter = owner_->GetEntryAtIndex(i);
160 if (iter->GetUniqueID() == unique_id) { 161 if (iter->GetUniqueID() == unique_id) {
161 entry = NavigationEntryImpl::FromNavigationEntry(iter); 162 entry = NavigationEntryImpl::FromNavigationEntry(iter);
162 break; 163 break;
163 } 164 }
164 } 165 }
165 166
166 if (!entry) { 167 if (!entry) {
167 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; 168 LOG(ERROR) << "Invalid entry with unique id: " << unique_id;
168 return; 169 return;
169 } 170 }
170 171
171 if (!success || bitmap.empty() || bitmap.isNull()) { 172 if (!success || bitmap.empty() || bitmap.isNull()) {
172 if (!ClearScreenshot(entry)) 173 ClearScreenshot(entry);
173 OnScreenshotSet(entry);
174 return; 174 return;
175 } 175 }
176 176
177 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData(); 177 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData();
178 screenshot->EncodeScreenshot( 178 screenshot->EncodeScreenshot(
179 bitmap, 179 bitmap,
180 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete, 180 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete,
181 screenshot_factory_.GetWeakPtr(), 181 screenshot_factory_.GetWeakPtr(),
182 unique_id, 182 unique_id,
183 screenshot)); 183 screenshot));
(...skipping 24 matching lines...) Expand all
208 } 208 }
209 } 209 }
210 if (!entry) 210 if (!entry)
211 return; 211 return;
212 entry->SetScreenshotPNGData(screenshot->data()); 212 entry->SetScreenshotPNGData(screenshot->data());
213 OnScreenshotSet(entry); 213 OnScreenshotSet(entry);
214 } 214 }
215 215
216 void NavigationEntryScreenshotManager::OnScreenshotSet( 216 void NavigationEntryScreenshotManager::OnScreenshotSet(
217 NavigationEntryImpl* entry) { 217 NavigationEntryImpl* entry) {
218 if (entry->screenshot().get()) 218 CHECK(entry->screenshot().get());
219 PurgeScreenshotsIfNecessary(); 219 PurgeScreenshotsIfNecessary();
220 } 220 }
221 221
222 bool NavigationEntryScreenshotManager::ClearScreenshot( 222 bool NavigationEntryScreenshotManager::ClearScreenshot(
223 NavigationEntryImpl* entry) { 223 NavigationEntryImpl* entry) {
224 if (!entry->screenshot().get()) 224 if (!entry->screenshot().get())
225 return false; 225 return false;
226 226
227 entry->SetScreenshotPNGData(NULL); 227 entry->SetScreenshotPNGData(NULL);
228 return true; 228 return true;
229 } 229 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 owner_->GetEntryAtIndex(forward)); 287 owner_->GetEntryAtIndex(forward));
288 if (ClearScreenshot(entry)) 288 if (ClearScreenshot(entry))
289 --screenshot_count; 289 --screenshot_count;
290 ++forward; 290 ++forward;
291 } 291 }
292 CHECK_GE(screenshot_count, 0); 292 CHECK_GE(screenshot_count, 0);
293 CHECK_LE(screenshot_count, kMaxScreenshots); 293 CHECK_LE(screenshot_count, kMaxScreenshots);
294 } 294 }
295 295
296 } // namespace content 296 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698