| 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 <iterator> | 7 #include <iterator> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 12 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 13 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "url/origin.h" | 16 #include "url/origin.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // The size of the buffer used to read the resource. | 20 // The size of the buffer used to read the resource. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 config_(config), | 34 config_(config), |
| 34 main_frame_url_(main_frame_url) { | 35 main_frame_url_(main_frame_url) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 36 | 37 |
| 37 std::copy(urls.begin(), urls.end(), std::back_inserter(request_queue_)); | 38 std::copy(urls.begin(), urls.end(), std::back_inserter(request_queue_)); |
| 38 } | 39 } |
| 39 | 40 |
| 40 ResourcePrefetcher::~ResourcePrefetcher() {} | 41 ResourcePrefetcher::~ResourcePrefetcher() {} |
| 41 | 42 |
| 42 void ResourcePrefetcher::Start() { | 43 void ResourcePrefetcher::Start() { |
| 44 TRACE_EVENT_ASYNC_BEGIN0("browser", "ResourcePrefetcher::Prefetch", this); |
| 43 DCHECK(thread_checker_.CalledOnValidThread()); | 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 | 46 |
| 45 CHECK_EQ(state_, INITIALIZED); | 47 CHECK_EQ(state_, INITIALIZED); |
| 46 state_ = RUNNING; | 48 state_ = RUNNING; |
| 47 | 49 |
| 48 TryToLaunchPrefetchRequests(); | 50 TryToLaunchPrefetchRequests(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void ResourcePrefetcher::Stop() { | 53 void ResourcePrefetcher::Stop() { |
| 54 TRACE_EVENT_ASYNC_END0("browser", "ResourcePrefetcher::Prefetch", this); |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 | 56 |
| 54 if (state_ == FINISHED) | 57 if (state_ == FINISHED) |
| 55 return; | 58 return; |
| 56 | 59 |
| 57 state_ = STOPPED; | 60 state_ = STOPPED; |
| 58 } | 61 } |
| 59 | 62 |
| 60 void ResourcePrefetcher::TryToLaunchPrefetchRequests() { | 63 void ResourcePrefetcher::TryToLaunchPrefetchRequests() { |
| 61 CHECK(state_ == RUNNING || state_ == STOPPED); | 64 CHECK(state_ == RUNNING || state_ == STOPPED); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (bytes_read <= 0) { | 200 if (bytes_read <= 0) { |
| 198 FinishRequest(request); | 201 FinishRequest(request); |
| 199 return; | 202 return; |
| 200 } | 203 } |
| 201 | 204 |
| 202 if (bytes_read > 0) | 205 if (bytes_read > 0) |
| 203 ReadFullResponse(request); | 206 ReadFullResponse(request); |
| 204 } | 207 } |
| 205 | 208 |
| 206 } // namespace predictors | 209 } // namespace predictors |
| OLD | NEW |