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_manager.h" | 5 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
40 | 40 |
41 predictor_ = NULL; | 41 predictor_ = NULL; |
42 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 42 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
43 base::Bind(&ResourcePrefetcherManager::ShutdownOnIOThread, | 43 base::Bind(&ResourcePrefetcherManager::ShutdownOnIOThread, |
44 this)); | 44 this)); |
45 } | 45 } |
46 | 46 |
47 void ResourcePrefetcherManager::ShutdownOnIOThread() { | 47 void ResourcePrefetcherManager::ShutdownOnIOThread() { |
48 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
49 STLDeleteContainerPairSecondPointers(prefetcher_map_.begin(), | 49 base::STLDeleteContainerPairSecondPointers(prefetcher_map_.begin(), |
50 prefetcher_map_.end()); | 50 prefetcher_map_.end()); |
51 } | 51 } |
52 | 52 |
53 void ResourcePrefetcherManager::MaybeAddPrefetch( | 53 void ResourcePrefetcherManager::MaybeAddPrefetch( |
54 const NavigationID& navigation_id, | 54 const NavigationID& navigation_id, |
55 PrefetchKeyType key_type, | 55 PrefetchKeyType key_type, |
56 std::unique_ptr<ResourcePrefetcher::RequestVector> requests) { | 56 std::unique_ptr<ResourcePrefetcher::RequestVector> requests) { |
57 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 57 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
58 | 58 |
59 // Don't add a duplicate prefetch for the same host or URL. | 59 // Don't add a duplicate prefetch for the same host or URL. |
60 std::string key = key_type == PREFETCH_KEY_TYPE_HOST ? | 60 std::string key = key_type == PREFETCH_KEY_TYPE_HOST ? |
61 navigation_id.main_frame_url.host() : navigation_id.main_frame_url.spec(); | 61 navigation_id.main_frame_url.host() : navigation_id.main_frame_url.spec(); |
62 if (ContainsKey(prefetcher_map_, key)) | 62 if (base::ContainsKey(prefetcher_map_, key)) |
63 return; | 63 return; |
64 | 64 |
65 ResourcePrefetcher* prefetcher = new ResourcePrefetcher( | 65 ResourcePrefetcher* prefetcher = new ResourcePrefetcher( |
66 this, config_, navigation_id, key_type, std::move(requests)); | 66 this, config_, navigation_id, key_type, std::move(requests)); |
67 prefetcher_map_.insert(std::make_pair(key, prefetcher)); | 67 prefetcher_map_.insert(std::make_pair(key, prefetcher)); |
68 prefetcher->Start(); | 68 prefetcher->Start(); |
69 } | 69 } |
70 | 70 |
71 void ResourcePrefetcherManager::MaybeRemovePrefetch( | 71 void ResourcePrefetcherManager::MaybeRemovePrefetch( |
72 const NavigationID& navigation_id) { | 72 const NavigationID& navigation_id) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 net::URLRequestContext* ResourcePrefetcherManager::GetURLRequestContext() { | 131 net::URLRequestContext* ResourcePrefetcherManager::GetURLRequestContext() { |
132 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 132 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
133 | 133 |
134 return context_getter_->GetURLRequestContext(); | 134 return context_getter_->GetURLRequestContext(); |
135 } | 135 } |
136 | 136 |
137 } // namespace predictors | 137 } // namespace predictors |
OLD | NEW |