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" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/public/browser/render_widget_host.h" | 12 #include "content/public/browser/render_widget_host.h" |
13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
14 #include "content/public/browser/site_instance.h" | |
14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
15 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
17 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 18 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
18 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Minimum delay between taking screenshots. | 23 // Minimum delay between taking screenshots. |
23 const int kMinScreenshotIntervalMS = 1000; | 24 const int kMinScreenshotIntervalMS = 1000; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 owner_->GetEntryAtIndex(i))); | 128 owner_->GetEntryAtIndex(i))); |
128 } | 129 } |
129 DCHECK_EQ(GetScreenshotCount(), 0); | 130 DCHECK_EQ(GetScreenshotCount(), 0); |
130 } | 131 } |
131 | 132 |
132 void NavigationEntryScreenshotManager::TakeScreenshotImpl( | 133 void NavigationEntryScreenshotManager::TakeScreenshotImpl( |
133 RenderViewHost* host, | 134 RenderViewHost* host, |
134 NavigationEntryImpl* entry) { | 135 NavigationEntryImpl* entry) { |
135 DCHECK(host && host->GetView()); | 136 DCHECK(host && host->GetView()); |
136 DCHECK(entry); | 137 DCHECK(entry); |
138 scoped_refptr<SiteInstanceImpl> site_instance( | |
139 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())); | |
140 scoped_ptr<SiteInstanceKeepAlive> keep_alive( | |
mfomitchev
2014/02/14 16:21:36
Why not just keep_alive = site_instance->AcquireKe
| |
141 site_instance->AcquireKeepAlive()); | |
137 host->CopyFromBackingStore(gfx::Rect(), | 142 host->CopyFromBackingStore(gfx::Rect(), |
138 host->GetView()->GetViewBounds().size(), | 143 host->GetView()->GetViewBounds().size(), |
139 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken, | 144 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken, |
140 screenshot_factory_.GetWeakPtr(), | 145 screenshot_factory_.GetWeakPtr(), |
141 entry->GetUniqueID())); | 146 entry->GetUniqueID(), |
147 base::Passed(&keep_alive))); | |
142 } | 148 } |
143 | 149 |
144 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( | 150 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( |
145 int interval_ms) { | 151 int interval_ms) { |
146 DCHECK_GE(interval_ms, 0); | 152 DCHECK_GE(interval_ms, 0); |
147 min_screenshot_interval_ms_ = interval_ms; | 153 min_screenshot_interval_ms_ = interval_ms; |
148 } | 154 } |
149 | 155 |
150 void NavigationEntryScreenshotManager::OnScreenshotTaken(int unique_id, | 156 void NavigationEntryScreenshotManager::OnScreenshotTaken( |
151 bool success, | 157 int unique_id, |
152 const SkBitmap& bitmap) { | 158 scoped_ptr<SiteInstanceKeepAlive> site_instance, |
mfomitchev
2014/02/14 16:21:36
rename this to keep_alive?
| |
159 bool success, | |
160 const SkBitmap& bitmap) { | |
161 site_instance.reset(); | |
mfomitchev
2014/02/14 16:21:36
The biggest question for me is whether this will g
| |
153 NavigationEntryImpl* entry = NULL; | 162 NavigationEntryImpl* entry = NULL; |
154 int entry_count = owner_->GetEntryCount(); | 163 int entry_count = owner_->GetEntryCount(); |
155 for (int i = 0; i < entry_count; ++i) { | 164 for (int i = 0; i < entry_count; ++i) { |
156 NavigationEntry* iter = owner_->GetEntryAtIndex(i); | 165 NavigationEntry* iter = owner_->GetEntryAtIndex(i); |
157 if (iter->GetUniqueID() == unique_id) { | 166 if (iter->GetUniqueID() == unique_id) { |
158 entry = NavigationEntryImpl::FromNavigationEntry(iter); | 167 entry = NavigationEntryImpl::FromNavigationEntry(iter); |
159 break; | 168 break; |
160 } | 169 } |
161 } | 170 } |
162 | 171 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 owner_->GetEntryAtIndex(forward)); | 293 owner_->GetEntryAtIndex(forward)); |
285 if (ClearScreenshot(entry)) | 294 if (ClearScreenshot(entry)) |
286 --screenshot_count; | 295 --screenshot_count; |
287 ++forward; | 296 ++forward; |
288 } | 297 } |
289 CHECK_GE(screenshot_count, 0); | 298 CHECK_GE(screenshot_count, 0); |
290 CHECK_LE(screenshot_count, kMaxScreenshots); | 299 CHECK_LE(screenshot_count, kMaxScreenshots); |
291 } | 300 } |
292 | 301 |
293 } // namespace content | 302 } // namespace content |
OLD | NEW |