| 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 "chrome/browser/net/resource_prefetch_predictor_observer.h" | 5 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 predictors::NavigationID* navigation_id, | 63 predictors::NavigationID* navigation_id, |
| 64 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 64 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 65 const GURL& main_frame_url, | 65 const GURL& main_frame_url, |
| 66 const base::TimeTicks& creation_time) { | 66 const base::TimeTicks& creation_time) { |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 68 content::WebContents* web_contents = web_contents_getter.Run(); | 68 content::WebContents* web_contents = web_contents_getter.Run(); |
| 69 if (!web_contents) | 69 if (!web_contents) |
| 70 return false; | 70 return false; |
| 71 *navigation_id = | 71 *navigation_id = |
| 72 predictors::NavigationID(web_contents, main_frame_url, creation_time); | 72 predictors::NavigationID(web_contents, main_frame_url, creation_time); |
| 73 return true; | 73 // A WebContents might be associated with something that is not a tab. |
| 74 // In this case tab_id will be -1 and is_valid() will return false. |
| 75 return navigation_id->is_valid(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace | 78 } // namespace |
| 77 | 79 |
| 78 namespace chrome_browser_net { | 80 namespace chrome_browser_net { |
| 79 | 81 |
| 80 ResourcePrefetchPredictorObserver::ResourcePrefetchPredictorObserver( | 82 ResourcePrefetchPredictorObserver::ResourcePrefetchPredictorObserver( |
| 81 ResourcePrefetchPredictor* predictor) | 83 ResourcePrefetchPredictor* predictor) |
| 82 : predictor_(predictor->AsWeakPtr()) { | 84 : predictor_(predictor->AsWeakPtr()) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const base::TimeTicks& creation_time) const { | 227 const base::TimeTicks& creation_time) const { |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 228 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 227 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, | 229 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, |
| 228 main_frame_url, creation_time)) { | 230 main_frame_url, creation_time)) { |
| 229 return; | 231 return; |
| 230 } | 232 } |
| 231 predictor_->RecordURLResponse(*summary); | 233 predictor_->RecordURLResponse(*summary); |
| 232 } | 234 } |
| 233 | 235 |
| 234 } // namespace chrome_browser_net | 236 } // namespace chrome_browser_net |
| OLD | NEW |