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

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 23694031: Fix race conditions in window snapshot code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added screenshot sync test to telemetry unittests, updated cc unittest Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/debug/trace_event.h" 16 #include "base/debug/trace_event.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/i18n/char_iterator.h" 18 #include "base/i18n/char_iterator.h"
19 #include "base/json/json_writer.h" 19 #include "base/json/json_writer.h"
20 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/message_loop/message_loop_proxy.h" 22 #include "base/message_loop/message_loop_proxy.h"
23 #include "base/metrics/histogram.h" 23 #include "base/metrics/histogram.h"
24 #include "base/path_service.h" 24 #include "base/path_service.h"
25 #include "base/process/kill.h" 25 #include "base/process/kill.h"
26 #include "base/process/process.h"
26 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/string_piece.h" 28 #include "base/strings/string_piece.h"
28 #include "base/strings/string_split.h" 29 #include "base/strings/string_split.h"
29 #include "base/strings/string_util.h" 30 #include "base/strings/string_util.h"
30 #include "base/strings/sys_string_conversions.h" 31 #include "base/strings/sys_string_conversions.h"
31 #include "base/strings/utf_string_conversions.h" 32 #include "base/strings/utf_string_conversions.h"
32 #include "base/time/time.h" 33 #include "base/time/time.h"
33 #include "content/child/appcache/appcache_dispatcher.h" 34 #include "content/child/appcache/appcache_dispatcher.h"
34 #include "content/child/appcache/web_application_cache_host_impl.h" 35 #include "content/child/appcache/web_application_cache_host_impl.h"
35 #include "content/child/child_thread.h" 36 #include "content/child/child_thread.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 188 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
188 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 189 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
189 #include "third_party/WebKit/public/web/WebSettings.h" 190 #include "third_party/WebKit/public/web/WebSettings.h"
190 #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" 191 #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h"
191 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 192 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
192 #include "third_party/WebKit/public/web/WebUserMediaClient.h" 193 #include "third_party/WebKit/public/web/WebUserMediaClient.h"
193 #include "third_party/WebKit/public/web/WebView.h" 194 #include "third_party/WebKit/public/web/WebView.h"
194 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 195 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
195 #include "third_party/WebKit/public/web/default/WebRenderTheme.h" 196 #include "third_party/WebKit/public/web/default/WebRenderTheme.h"
196 #include "ui/base/ui_base_switches_util.h" 197 #include "ui/base/ui_base_switches_util.h"
198 #include "ui/events/latency_info.h"
197 #include "ui/gfx/native_widget_types.h" 199 #include "ui/gfx/native_widget_types.h"
198 #include "ui/gfx/point.h" 200 #include "ui/gfx/point.h"
199 #include "ui/gfx/rect.h" 201 #include "ui/gfx/rect.h"
200 #include "ui/gfx/rect_conversions.h" 202 #include "ui/gfx/rect_conversions.h"
201 #include "ui/gfx/size_conversions.h" 203 #include "ui/gfx/size_conversions.h"
202 #include "ui/shell_dialogs/selected_file_info.h" 204 #include "ui/shell_dialogs/selected_file_info.h"
203 #include "v8/include/v8.h" 205 #include "v8/include/v8.h"
204 #include "webkit/child/weburlresponse_extradata_impl.h" 206 #include "webkit/child/weburlresponse_extradata_impl.h"
205 207
206 #if defined(OS_ANDROID) 208 #if defined(OS_ANDROID)
(...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 if (RenderThreadImpl::current()) // Will be NULL during unit tests. 2232 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2231 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); 2233 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
2232 2234
2233 message->EnableMessagePumping(); // Runs a nested message loop. 2235 message->EnableMessagePumping(); // Runs a nested message loop.
2234 return Send(message); 2236 return Send(message);
2235 } 2237 }
2236 2238
2237 void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { 2239 void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2238 int id = next_snapshot_id_++; 2240 int id = next_snapshot_id_++;
2239 pending_snapshots_.insert(std::make_pair(id, callback)); 2241 pending_snapshots_.insert(std::make_pair(id, callback));
2240 Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id)); 2242 ui::LatencyInfo latency_info;
2243 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2244 GetLatencyComponentId(),
2245 id);
2246 if (RenderWidgetCompositor* rwc = compositor()) {
2247 rwc->SetLatencyInfo(latency_info);
2248 } else {
2249 latency_info_.MergeWith(latency_info);
2250 }
2251 ScheduleCompositeWithForcedRedraw();
2241 } 2252 }
2242 2253
2243 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, 2254 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2244 const gfx::Size& size, const std::vector<unsigned char>& png) { 2255 const gfx::Size& size, const std::vector<unsigned char>& png) {
2245 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); 2256
2246 DCHECK(it != pending_snapshots_.end()); 2257 // Any pending snapshots with a lower ID than the one received are considered
2247 it->second.Run(size, png); 2258 // to be implicitly complete, and returned the same snapshot data.
2248 pending_snapshots_.erase(it); 2259 PendingSnapshotMap::iterator it = pending_snapshots_.begin();
2260 while(it != pending_snapshots_.end()) {
2261 if (it->first <= snapshot_id) {
2262 it->second.Run(size, png);
2263 pending_snapshots_.erase(it++);
2264 } else {
2265 ++it;
2266 }
2267 }
2249 } 2268 }
2250 2269
2251 // WebKit::WebViewClient ------------------------------------------------------ 2270 // WebKit::WebViewClient ------------------------------------------------------
2252 2271
2253 WebView* RenderViewImpl::createView( 2272 WebView* RenderViewImpl::createView(
2254 WebFrame* creator, 2273 WebFrame* creator,
2255 const WebURLRequest& request, 2274 const WebURLRequest& request,
2256 const WebWindowFeatures& features, 2275 const WebWindowFeatures& features,
2257 const WebString& frame_name, 2276 const WebString& frame_name,
2258 WebNavigationPolicy policy) { 2277 WebNavigationPolicy policy) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 } 2733 }
2715 } 2734 }
2716 2735
2717 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( 2736 gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2718 const gfx::RectF& rect) const { 2737 const gfx::RectF& rect) const {
2719 gfx::RectF window_rect = rect; 2738 gfx::RectF window_rect = rect;
2720 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); 2739 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2721 return window_rect; 2740 return window_rect;
2722 } 2741 }
2723 2742
2743 int64 RenderViewImpl::GetLatencyComponentId() {
2744 // Note: this must match the logic in RenderWidgetHostImpl.
jamesr 2013/10/01 23:42:13 so if I understand correctly, what's going on here
2745 return GetRoutingID() | (static_cast<int64>(
2746 RenderThreadImpl::current()->renderer_process_id()) << 32);
2747 }
2748
2724 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { 2749 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
2725 // No need to update state if no page has committed yet. 2750 // No need to update state if no page has committed yet.
2726 if (page_id_ == -1) 2751 if (page_id_ == -1)
2727 return; 2752 return;
2728 2753
2729 int delay; 2754 int delay;
2730 if (send_content_state_immediately_) 2755 if (send_content_state_immediately_)
2731 delay = 0; 2756 delay = 0;
2732 else if (is_hidden()) 2757 else if (is_hidden())
2733 delay = kDelaySecondsForContentStateSyncHidden; 2758 delay = kDelaySecondsForContentStateSyncHidden;
(...skipping 3770 matching lines...) Expand 10 before | Expand all | Expand 10 after
6504 for (size_t i = 0; i < icon_urls.size(); i++) { 6529 for (size_t i = 0; i < icon_urls.size(); i++) {
6505 WebURL url = icon_urls[i].iconURL(); 6530 WebURL url = icon_urls[i].iconURL();
6506 if (!url.isEmpty()) 6531 if (!url.isEmpty())
6507 urls.push_back(FaviconURL(url, 6532 urls.push_back(FaviconURL(url,
6508 ToFaviconType(icon_urls[i].iconType()))); 6533 ToFaviconType(icon_urls[i].iconType())));
6509 } 6534 }
6510 SendUpdateFaviconURL(urls); 6535 SendUpdateFaviconURL(urls);
6511 } 6536 }
6512 6537
6513 } // namespace content 6538 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698