Chromium Code Reviews| 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/predictors/resource_prefetcher.h" | 5 #include "chrome/browser/predictors/resource_prefetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 99 |
| 100 void CheckPrefetcherState(size_t inflight, size_t queue, size_t host) { | 100 void CheckPrefetcherState(size_t inflight, size_t queue, size_t host) { |
| 101 EXPECT_EQ(prefetcher_->inflight_requests_.size(), inflight); | 101 EXPECT_EQ(prefetcher_->inflight_requests_.size(), inflight); |
| 102 EXPECT_EQ(prefetcher_->request_queue_.size(), queue); | 102 EXPECT_EQ(prefetcher_->request_queue_.size(), queue); |
| 103 EXPECT_EQ(prefetcher_->host_inflight_counts_.size(), host); | 103 EXPECT_EQ(prefetcher_->host_inflight_counts_.size(), host); |
| 104 } | 104 } |
| 105 | 105 |
| 106 net::URLRequest* GetInFlightRequest(const std::string& url_str) { | 106 net::URLRequest* GetInFlightRequest(const std::string& url_str) { |
| 107 GURL url(url_str); | 107 GURL url(url_str); |
| 108 | 108 |
| 109 for (std::list<Request*>::const_iterator it = | 109 for (auto it = prefetcher_->request_queue_.begin(); |
|
pasko
2016/09/01 12:30:45
nit: while we are here, can you please also conver
| |
| 110 prefetcher_->request_queue_.begin(); | |
| 111 it != prefetcher_->request_queue_.end(); ++it) { | 110 it != prefetcher_->request_queue_.end(); ++it) { |
| 112 EXPECT_NE((*it)->resource_url, url); | 111 EXPECT_NE((*it)->resource_url, url); |
| 113 } | 112 } |
| 114 for (std::map<net::URLRequest*, Request*>::const_iterator it = | 113 for (auto it = prefetcher_->inflight_requests_.begin(); |
|
pasko
2016/09/01 12:30:45
ditto
| |
| 115 prefetcher_->inflight_requests_.begin(); | |
| 116 it != prefetcher_->inflight_requests_.end(); ++it) { | 114 it != prefetcher_->inflight_requests_.end(); ++it) { |
| 117 if (it->first->original_url() == url) | 115 if (it->first->original_url() == url) |
| 118 return it->first; | 116 return it->first; |
| 119 } | 117 } |
| 120 EXPECT_TRUE(false) << "Infligh request not found: " << url_str; | 118 EXPECT_TRUE(false) << "Inflight request not found: " << url_str; |
|
pasko
2016/09/01 12:30:45
nit: s/Inflight/In flight/
| |
| 121 return NULL; | 119 return NULL; |
| 122 } | 120 } |
| 123 | 121 |
| 124 | 122 |
| 125 void OnReceivedRedirect(const std::string& url) { | 123 void OnReceivedRedirect(const std::string& url) { |
| 126 prefetcher_->OnReceivedRedirect( | 124 prefetcher_->OnReceivedRedirect( |
| 127 GetInFlightRequest(url), net::RedirectInfo(), NULL); | 125 GetInFlightRequest(url), net::RedirectInfo(), NULL); |
| 128 } | 126 } |
| 129 void OnAuthRequired(const std::string& url) { | 127 void OnAuthRequired(const std::string& url) { |
| 130 prefetcher_->OnAuthRequired(GetInFlightRequest(url), NULL); | 128 prefetcher_->OnAuthRequired(GetInFlightRequest(url), NULL); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 // We need to delete requests_ptr here, though it looks to be managed by the | 349 // We need to delete requests_ptr here, though it looks to be managed by the |
| 352 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw | 350 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw |
| 353 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the | 351 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the |
| 354 // test, ResourcePrefetcherFinished() is a mock function and does not handle | 352 // test, ResourcePrefetcherFinished() is a mock function and does not handle |
| 355 // the raw pointer properly. In the real code, requests_ptr will eventually be | 353 // the raw pointer properly. In the real code, requests_ptr will eventually be |
| 356 // passed to and managed by ResourcePrefetchPredictor::Result::Result. | 354 // passed to and managed by ResourcePrefetchPredictor::Result::Result. |
| 357 delete requests_ptr; | 355 delete requests_ptr; |
| 358 } | 356 } |
| 359 | 357 |
| 360 } // namespace predictors | 358 } // namespace predictors |
| OLD | NEW |