OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/web_contents_observer_sanity_checker.h" | 5 #include "content/test/web_contents_observer_sanity_checker.h" |
6 | 6 |
| 7 #include "base/debug/stack_trace.h" |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
9 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
10 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
11 #include "content/public/browser/navigation_handle.h" | 12 #include "content/public/browser/navigation_handle.h" |
12 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const char kWebContentsObserverSanityCheckerKey[] = | 24 const char kWebContentsObserverSanityCheckerKey[] = |
24 "WebContentsObserverSanityChecker"; | 25 "WebContentsObserverSanityChecker"; |
25 | 26 |
| 27 // Set this variable to true to collect stack traces on observer method calls |
| 28 // so duplicate ones can be easily debugged. |
| 29 static bool g_collect_stack_traces = true; |
| 30 |
26 GlobalRoutingID GetRoutingPair(RenderFrameHost* host) { | 31 GlobalRoutingID GetRoutingPair(RenderFrameHost* host) { |
27 if (!host) | 32 if (!host) |
28 return GlobalRoutingID(0, 0); | 33 return GlobalRoutingID(0, 0); |
29 return GlobalRoutingID(host->GetProcess()->GetID(), host->GetRoutingID()); | 34 return GlobalRoutingID(host->GetProcess()->GetID(), host->GetRoutingID()); |
30 } | 35 } |
31 | 36 |
32 } // namespace | 37 } // namespace |
33 | 38 |
34 // static | 39 // static |
35 void WebContentsObserverSanityChecker::Enable(WebContents* web_contents) { | 40 void WebContentsObserverSanityChecker::Enable(WebContents* web_contents) { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 280 } |
276 | 281 |
277 void WebContentsObserverSanityChecker::DidOpenRequestedURL( | 282 void WebContentsObserverSanityChecker::DidOpenRequestedURL( |
278 WebContents* new_contents, | 283 WebContents* new_contents, |
279 RenderFrameHost* source_render_frame_host, | 284 RenderFrameHost* source_render_frame_host, |
280 const GURL& url, | 285 const GURL& url, |
281 const Referrer& referrer, | 286 const Referrer& referrer, |
282 WindowOpenDisposition disposition, | 287 WindowOpenDisposition disposition, |
283 ui::PageTransition transition) { | 288 ui::PageTransition transition) { |
284 AssertRenderFrameExists(source_render_frame_host); | 289 AssertRenderFrameExists(source_render_frame_host); |
| 290 |
| 291 std::string trace; |
| 292 if (g_collect_stack_traces) { |
| 293 base::debug::StackTrace stack_trace; |
| 294 trace = stack_trace.ToString(); |
| 295 } |
| 296 |
| 297 bool did_not_exist = created_web_contents_.insert(std::make_pair(new_contents,
trace)).second; |
| 298 CHECK(did_not_exist) << "A WebContents was created for the same address as pre
viously " |
| 299 "created one. The original one was allocated by:\n" <<
trace; |
285 } | 300 } |
286 | 301 |
287 void WebContentsObserverSanityChecker::MediaStartedPlaying( | 302 void WebContentsObserverSanityChecker::MediaStartedPlaying( |
288 const MediaPlayerId& id) { | 303 const MediaPlayerId& id) { |
289 CHECK(!web_contents_destroyed_); | 304 CHECK(!web_contents_destroyed_); |
290 CHECK(std::find(active_media_players_.begin(), active_media_players_.end(), | 305 CHECK(std::find(active_media_players_.begin(), active_media_players_.end(), |
291 id) == active_media_players_.end()); | 306 id) == active_media_players_.end()); |
292 active_media_players_.push_back(id); | 307 active_media_players_.push_back(id); |
293 } | 308 } |
294 | 309 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 if (live_routes_.count(entry.first)) | 420 if (live_routes_.count(entry.first)) |
406 return true; | 421 return true; |
407 if (current_hosts_.count(entry.first)) | 422 if (current_hosts_.count(entry.first)) |
408 return true; | 423 return true; |
409 } | 424 } |
410 } | 425 } |
411 return false; | 426 return false; |
412 } | 427 } |
413 | 428 |
414 } // namespace content | 429 } // namespace content |
OLD | NEW |