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 is no navigation entry yet. |
dominich
2012/07/31 23:08:50
nit: the -> there
Shishir
2012/07/31 23:29:35
Done.
| |
412 if (!navigation_id.main_frame_url.is_empty()) | |
dominich
2012/07/31 23:08:50
Also, expand the comment to explain 1) when this m
Shishir
2012/07/31 23:29:35
Its the way the GetUrl() function call in webconte
| |
413 OnNavigationComplete(navigation_id); | |
dominich
2012/07/31 23:08:50
When do we erase this from inflight navigations if
Shishir
2012/07/31 23:29:35
In CleanupOldNavigations.
| |
420 break; | 414 break; |
421 } | 415 } |
422 | 416 |
423 case content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE: { | 417 case content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE: { |
424 const content::LoadFromMemoryCacheDetails* load_details = | 418 const content::LoadFromMemoryCacheDetails* load_details = |
425 content::Details<content::LoadFromMemoryCacheDetails>(details).ptr(); | 419 content::Details<content::LoadFromMemoryCacheDetails>(details).ptr(); |
426 const content::WebContents* web_contents = | 420 const content::WebContents* web_contents = |
427 content::Source<content::NavigationController>( | 421 content::Source<content::NavigationController>( |
428 source).ptr()->GetWebContents(); | 422 source).ptr()->GetWebContents(); |
429 | 423 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 tables_, | 756 tables_, |
763 urls_to_delete)); | 757 urls_to_delete)); |
764 } | 758 } |
765 | 759 |
766 void ResourcePrefetchPredictor::SetTablesForTesting( | 760 void ResourcePrefetchPredictor::SetTablesForTesting( |
767 scoped_refptr<ResourcePrefetchPredictorTables> tables) { | 761 scoped_refptr<ResourcePrefetchPredictorTables> tables) { |
768 tables_ = tables; | 762 tables_ = tables; |
769 } | 763 } |
770 | 764 |
771 } // namespace predictors | 765 } // namespace predictors |
OLD | NEW |