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 (auto it = prefetcher_->request_queue_.begin(); | 109 for (auto* request : prefetcher_->request_queue_) { |
110 it != prefetcher_->request_queue_.end(); ++it) { | 110 EXPECT_NE(request->resource_url, url); |
111 EXPECT_NE((*it)->resource_url, url); | |
112 } | 111 } |
113 for (auto it = prefetcher_->inflight_requests_.begin(); | 112 for (const auto& it : prefetcher_->inflight_requests_) { |
Benoit L
2016/09/02 10:44:12
nit: "it" is a bit misleading here, I usually use
pasko
2016/09/02 10:51:10
Agreed. Changed to key_value, still lgty?
| |
114 it != prefetcher_->inflight_requests_.end(); ++it) { | 113 if (it.first->original_url() == url) |
115 if (it->first->original_url() == url) | 114 return it.first; |
116 return it->first; | |
117 } | 115 } |
118 EXPECT_TRUE(false) << "Inflight request not found: " << url_str; | 116 EXPECT_TRUE(false) << "In flight request not found: " << url_str; |
119 return NULL; | 117 return NULL; |
120 } | 118 } |
121 | 119 |
122 | 120 |
123 void OnReceivedRedirect(const std::string& url) { | 121 void OnReceivedRedirect(const std::string& url) { |
124 prefetcher_->OnReceivedRedirect( | 122 prefetcher_->OnReceivedRedirect( |
125 GetInFlightRequest(url), net::RedirectInfo(), NULL); | 123 GetInFlightRequest(url), net::RedirectInfo(), NULL); |
126 } | 124 } |
127 void OnAuthRequired(const std::string& url) { | 125 void OnAuthRequired(const std::string& url) { |
128 prefetcher_->OnAuthRequired(GetInFlightRequest(url), NULL); | 126 prefetcher_->OnAuthRequired(GetInFlightRequest(url), NULL); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 // We need to delete requests_ptr here, though it looks to be managed by the | 347 // We need to delete requests_ptr here, though it looks to be managed by the |
350 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw | 348 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw |
351 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the | 349 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the |
352 // test, ResourcePrefetcherFinished() is a mock function and does not handle | 350 // test, ResourcePrefetcherFinished() is a mock function and does not handle |
353 // the raw pointer properly. In the real code, requests_ptr will eventually be | 351 // the raw pointer properly. In the real code, requests_ptr will eventually be |
354 // passed to and managed by ResourcePrefetchPredictor::Result::Result. | 352 // passed to and managed by ResourcePrefetchPredictor::Result::Result. |
355 delete requests_ptr; | 353 delete requests_ptr; |
356 } | 354 } |
357 | 355 |
358 } // namespace predictors | 356 } // namespace predictors |
OLD | NEW |