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

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: Fixing some unit tests. 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(int unique_id,
nasko 2014/03/26 22:48:27 Let's fix the alignment of params on this method w
mfomitchev 2014/03/27 21:51:34 Done.
154 bool success, 154 bool success,
155 const SkBitmap& bitmap) { 155 const SkBitmap& bitmap) {
156 NavigationEntryImpl* entry = NULL; 156 NavigationEntryImpl* entry = NULL;
157 int entry_count = owner_->GetEntryCount(); 157 int entry_count = owner_->GetEntryCount();
158 for (int i = 0; i < entry_count; ++i) { 158 for (int i = 0; i < entry_count; ++i) {
159 NavigationEntry* iter = owner_->GetEntryAtIndex(i); 159 NavigationEntry* iter = owner_->GetEntryAtIndex(i);
160 if (iter->GetUniqueID() == unique_id) { 160 if (iter->GetUniqueID() == unique_id) {
161 entry = NavigationEntryImpl::FromNavigationEntry(iter); 161 entry = NavigationEntryImpl::FromNavigationEntry(iter);
162 break; 162 break;
163 } 163 }
164 } 164 }
165 165
166 if (!entry) { 166 if (!entry) {
167 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; 167 LOG(ERROR) << "Invalid entry with unique id: " << unique_id;
168 return; 168 return;
169 } 169 }
170 170
171 if (!success || bitmap.empty() || bitmap.isNull()) { 171 if (!success || bitmap.empty() || bitmap.isNull()) {
172 if (!ClearScreenshot(entry)) 172 ClearScreenshot(entry);
173 OnScreenshotSet(entry);
174 return; 173 return;
175 } 174 }
176 175
177 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData(); 176 scoped_refptr<ScreenshotData> screenshot = new ScreenshotData();
178 screenshot->EncodeScreenshot( 177 screenshot->EncodeScreenshot(
179 bitmap, 178 bitmap,
180 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete, 179 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotEncodeComplete,
181 screenshot_factory_.GetWeakPtr(), 180 screenshot_factory_.GetWeakPtr(),
182 unique_id, 181 unique_id,
183 screenshot)); 182 screenshot));
(...skipping 24 matching lines...) Expand all
208 } 207 }
209 } 208 }
210 if (!entry) 209 if (!entry)
211 return; 210 return;
212 entry->SetScreenshotPNGData(screenshot->data()); 211 entry->SetScreenshotPNGData(screenshot->data());
213 OnScreenshotSet(entry); 212 OnScreenshotSet(entry);
214 } 213 }
215 214
216 void NavigationEntryScreenshotManager::OnScreenshotSet( 215 void NavigationEntryScreenshotManager::OnScreenshotSet(
217 NavigationEntryImpl* entry) { 216 NavigationEntryImpl* entry) {
218 if (entry->screenshot().get()) 217 CHECK(entry->screenshot().get());
219 PurgeScreenshotsIfNecessary(); 218 PurgeScreenshotsIfNecessary();
220 } 219 }
221 220
222 bool NavigationEntryScreenshotManager::ClearScreenshot( 221 bool NavigationEntryScreenshotManager::ClearScreenshot(
223 NavigationEntryImpl* entry) { 222 NavigationEntryImpl* entry) {
224 if (!entry->screenshot().get()) 223 if (!entry->screenshot().get())
225 return false; 224 return false;
226 225
227 entry->SetScreenshotPNGData(NULL); 226 entry->SetScreenshotPNGData(NULL);
228 return true; 227 return true;
229 } 228 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 owner_->GetEntryAtIndex(forward)); 286 owner_->GetEntryAtIndex(forward));
288 if (ClearScreenshot(entry)) 287 if (ClearScreenshot(entry))
289 --screenshot_count; 288 --screenshot_count;
290 ++forward; 289 ++forward;
291 } 290 }
292 CHECK_GE(screenshot_count, 0); 291 CHECK_GE(screenshot_count, 0);
293 CHECK_LE(screenshot_count, kMaxScreenshots); 292 CHECK_LE(screenshot_count, kMaxScreenshots);
294 } 293 }
295 294
296 } // namespace content 295 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698