Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/predictors/resource_prefetcher_manager.cc

Issue 2377643002: predictors: Make the resource_prefetch_predictor accessible from Java. (Closed)
Patch Set: Address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 base::Bind(&ResourcePrefetcherManager::ShutdownOnIOThread, 44 base::Bind(&ResourcePrefetcherManager::ShutdownOnIOThread,
45 this)); 45 this));
46 } 46 }
47 47
48 void ResourcePrefetcherManager::ShutdownOnIOThread() { 48 void ResourcePrefetcherManager::ShutdownOnIOThread() {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
50 prefetcher_map_.clear(); 50 prefetcher_map_.clear();
51 } 51 }
52 52
53 void ResourcePrefetcherManager::MaybeAddPrefetch( 53 void ResourcePrefetcherManager::MaybeAddPrefetch(
54 const NavigationID& navigation_id, 54 const GURL& main_frame_url,
55 const std::vector<GURL>& urls) { 55 const std::vector<GURL>& urls) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
57 57
58 // Don't add a duplicate prefetch for the same host. 58 // Don't add a duplicate prefetch for the same host.
59 const GURL& main_frame_url = navigation_id.main_frame_url;
60 std::string key = main_frame_url.host(); 59 std::string key = main_frame_url.host();
61 if (base::ContainsKey(prefetcher_map_, key)) 60 if (base::ContainsKey(prefetcher_map_, key))
62 return; 61 return;
63 62
64 auto prefetcher = 63 auto prefetcher =
65 base::MakeUnique<ResourcePrefetcher>(this, config_, main_frame_url, urls); 64 base::MakeUnique<ResourcePrefetcher>(this, config_, main_frame_url, urls);
66 prefetcher->Start(); 65 prefetcher->Start();
67 prefetcher_map_[key] = std::move(prefetcher); 66 prefetcher_map_[key] = std::move(prefetcher);
68 } 67 }
69 68
70 void ResourcePrefetcherManager::MaybeRemovePrefetch( 69 void ResourcePrefetcherManager::MaybeRemovePrefetch(
71 const NavigationID& navigation_id) { 70 const GURL& main_frame_url) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 71 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
73 72
74 const GURL& main_frame_url = navigation_id.main_frame_url;
75 std::string key = main_frame_url.host(); 73 std::string key = main_frame_url.host();
76
77 auto it = prefetcher_map_.find(key); 74 auto it = prefetcher_map_.find(key);
78 if (it != prefetcher_map_.end() && 75 if (it != prefetcher_map_.end() &&
79 it->second->main_frame_url() == navigation_id.main_frame_url) { 76 it->second->main_frame_url() == main_frame_url) {
80 it->second->Stop(); 77 it->second->Stop();
81 return;
82 } 78 }
83 } 79 }
84 80
85 void ResourcePrefetcherManager::ResourcePrefetcherFinished( 81 void ResourcePrefetcherManager::ResourcePrefetcherFinished(
86 ResourcePrefetcher* resource_prefetcher) { 82 ResourcePrefetcher* resource_prefetcher) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 83 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
88 84
89 const std::string key = resource_prefetcher->main_frame_url().host(); 85 const std::string key = resource_prefetcher->main_frame_url().host();
90 auto it = prefetcher_map_.find(key); 86 auto it = prefetcher_map_.find(key);
91 DCHECK(it != prefetcher_map_.end()); 87 DCHECK(it != prefetcher_map_.end());
92 prefetcher_map_.erase(it); 88 prefetcher_map_.erase(it);
93 } 89 }
94 90
95 net::URLRequestContext* ResourcePrefetcherManager::GetURLRequestContext() { 91 net::URLRequestContext* ResourcePrefetcherManager::GetURLRequestContext() {
96 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
97 93
98 return context_getter_->GetURLRequestContext(); 94 return context_getter_->GetURLRequestContext();
99 } 95 }
100 96
101 } // namespace predictors 97 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698