OLD | NEW |
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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 CHECK_EQ(response.resource_type, ResourceType::MAIN_FRAME); | 320 CHECK_EQ(response.resource_type, ResourceType::MAIN_FRAME); |
321 OnMainFrameRedirect(response); | 321 OnMainFrameRedirect(response); |
322 } | 322 } |
323 | 323 |
324 void ResourcePrefetchPredictor::OnMainFrameRequest( | 324 void ResourcePrefetchPredictor::OnMainFrameRequest( |
325 const URLRequestSummary& request) { | 325 const URLRequestSummary& request) { |
326 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
327 DCHECK_EQ(INITIALIZED, initialization_state_); | 327 DCHECK_EQ(INITIALIZED, initialization_state_); |
328 | 328 |
329 // TODO(shishir): Remove this code after verifying that the same navigation is | |
330 // not seen multiple times. | |
331 NavigationMap::const_iterator it = | |
332 inflight_navigations_.find(request.navigation_id); | |
333 if (it != inflight_navigations_.end()) { | |
334 DCHECK(it->first.creation_time != request.navigation_id.creation_time); | |
335 } | |
336 | |
337 // Cleanup older navigations. | 329 // Cleanup older navigations. |
338 CleanupAbandonedNavigations(request.navigation_id); | 330 CleanupAbandonedNavigations(request.navigation_id); |
339 | 331 |
340 // New empty navigation entry. | 332 // New empty navigation entry. |
341 inflight_navigations_.insert(std::make_pair( | 333 inflight_navigations_.insert(std::make_pair( |
342 request.navigation_id, std::vector<URLRequestSummary>())); | 334 request.navigation_id, std::vector<URLRequestSummary>())); |
343 } | 335 } |
344 | 336 |
345 void ResourcePrefetchPredictor::OnMainFrameResponse( | 337 void ResourcePrefetchPredictor::OnMainFrameResponse( |
346 const URLRequestSummary& response) { | 338 const URLRequestSummary& response) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 int type, | 401 int type, |
410 const content::NotificationSource& source, | 402 const content::NotificationSource& source, |
411 const content::NotificationDetails& details) { | 403 const content::NotificationDetails& details) { |
412 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 404 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
413 | 405 |
414 switch (type) { | 406 switch (type) { |
415 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 407 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
416 const content::WebContents* web_contents = | 408 const content::WebContents* web_contents = |
417 content::Source<content::WebContents>(source).ptr(); | 409 content::Source<content::WebContents>(source).ptr(); |
418 NavigationID navigation_id(*web_contents); | 410 NavigationID navigation_id(*web_contents); |
419 OnNavigationComplete(navigation_id); | 411 // WebContents can return an empty URL if the navigation entry |
| 412 // corresponding to the navigation has not been created yet. |
| 413 if (!navigation_id.main_frame_url.is_empty()) |
| 414 OnNavigationComplete(navigation_id); |
420 break; | 415 break; |
421 } | 416 } |
422 | 417 |
423 case content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE: { | 418 case content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE: { |
424 const content::LoadFromMemoryCacheDetails* load_details = | 419 const content::LoadFromMemoryCacheDetails* load_details = |
425 content::Details<content::LoadFromMemoryCacheDetails>(details).ptr(); | 420 content::Details<content::LoadFromMemoryCacheDetails>(details).ptr(); |
426 const content::WebContents* web_contents = | 421 const content::WebContents* web_contents = |
427 content::Source<content::NavigationController>( | 422 content::Source<content::NavigationController>( |
428 source).ptr()->GetWebContents(); | 423 source).ptr()->GetWebContents(); |
429 | 424 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 tables_, | 757 tables_, |
763 urls_to_delete)); | 758 urls_to_delete)); |
764 } | 759 } |
765 | 760 |
766 void ResourcePrefetchPredictor::SetTablesForTesting( | 761 void ResourcePrefetchPredictor::SetTablesForTesting( |
767 scoped_refptr<ResourcePrefetchPredictorTables> tables) { | 762 scoped_refptr<ResourcePrefetchPredictorTables> tables) { |
768 tables_ = tables; | 763 tables_ = tables; |
769 } | 764 } |
770 | 765 |
771 } // namespace predictors | 766 } // namespace predictors |
OLD | NEW |