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

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

Issue 10817004: Adds speculative prefetching of resources. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/predictors/resource_prefetcher_manager.h"
6
7 #include "base/bind.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "net/url_request/url_request.h"
10 #include "net/url_request/url_request_context_getter.h"
11
12 using content::BrowserThread;
13
14 namespace predictors {
15
16 ResourcePrefetcherManager::ResourcePrefetcherManager(
17 Delegate* delegate,
18 const ResourcePrefetchPredictorConfig& config,
19 net::URLRequestContextGetter* context_getter)
20 : delegate_(delegate),
21 config_(config),
22 context_getter_(context_getter) {
23 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
24 CHECK(delegate_);
25 CHECK(context_getter_);
26 }
27
28 ResourcePrefetcherManager::~ResourcePrefetcherManager() {
29 }
30
31 void ResourcePrefetcherManager::ShutdownOnUIThread() {
32 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33
34 delegate_ = NULL;
35 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
36 base::Bind(&ResourcePrefetcherManager::ShutdownOnIOThread,
37 this));
38 }
39
40 void ResourcePrefetcherManager::ShutdownOnIOThread() {
41 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42
43 prefetchers_.clear();
dominich 2012/07/23 16:04:41 you're relying on linked_ptr to delete these? Is t
Shishir 2012/08/01 22:35:24 Nope, no ScopedMap in codebase. Using a ElementDel
44 }
45
46 void ResourcePrefetcherManager::MaybeAddPrefetch(
47 const NavigationID& navigation_id,
48 scoped_ptr<ResourcePrefetcher::RequestVector> requests) {
49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50
51 const GURL& main_frame_url = navigation_id.main_frame_url;
52 if (prefetchers_.find(main_frame_url) != prefetchers_.end())
53 return;
54
55 ResourcePrefetcher* prefetcher = new ResourcePrefetcher(
56 this, config_, navigation_id, requests.Pass());
57 prefetchers_[main_frame_url] = make_linked_ptr(prefetcher);
dominich 2012/07/23 16:04:41 double lookup.
Shishir 2012/08/01 22:35:24 I can't combine them unless I create the prefetche
58 prefetcher->Start();
59 }
60
61 void ResourcePrefetcherManager::MaybeRemovePrefetch(
62 const NavigationID& navigation_id) {
63 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
64
65 const GURL& main_frame_url = navigation_id.main_frame_url;
66 if (prefetchers_.find(main_frame_url) != prefetchers_.end()) {
67 ResourcePrefetcher* prefetcher = prefetchers_[main_frame_url].get();
dominich 2012/07/23 16:04:41 double lookup.
Shishir 2012/08/01 22:35:24 Done.
68 if (prefetcher->navigation_id() == navigation_id)
69 prefetcher->Stop();
70 }
71 }
72
73 void ResourcePrefetcherManager::ResourcePrefetcherFinished(
74 ResourcePrefetcher* resource_prefetcher,
75 scoped_ptr<ResourcePrefetcher::RequestVector> requests) {
76 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77
78 const GURL& main_frame_url =
79 resource_prefetcher->navigation_id().main_frame_url;
80 DCHECK(prefetchers_.find(main_frame_url) != prefetchers_.end());
81
82 // Our delegate can only be accessed from the UI thread.
83 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
84 base::Bind(&ResourcePrefetcherManager::ResourcePrefetcherFinishedOnUI,
85 this,
86 resource_prefetcher->navigation_id(),
87 base::Passed(requests.Pass())));
88
89 prefetchers_.erase(main_frame_url);
dominich 2012/07/23 16:04:41 i think an explicit delete here is better than lin
Shishir 2012/08/01 22:35:24 Done. Although I should point out we are looking a
90 }
91
92 void ResourcePrefetcherManager::ResourcePrefetcherFinishedOnUI(
93 const NavigationID& navigation_id,
94 scoped_ptr<ResourcePrefetcher::RequestVector> requests) {
95 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96
97 // Notify our delegate.
98 if (delegate_)
dominich 2012/07/23 16:04:41 you CHECK(delegate_) in the ctor. this is unnecess
Shishir 2012/08/01 22:35:24 Its required because the predictor_ is set to null
99 delegate_->FinishedPrefetchForNavigation(navigation_id,
100 requests.Pass());
101 }
102
103 net::URLRequestContext* ResourcePrefetcherManager::GetURLRequestContext() {
104 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
105
106 return context_getter_->GetURLRequestContext();
107 }
108
109 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698