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

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

Issue 10817004: Adds speculative prefetching of resources. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing Dominich's comment. Created 8 years, 3 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
7
8 #include <map>
9
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/predictors/resource_prefetcher.h"
12 #include "chrome/browser/predictors/resource_prefetch_common.h"
13
14 namespace net {
15 class URLRequestContextGetter;
16 }
17
18 namespace predictors {
19
20 struct NavigationID;
21 class ResourcePrefetchPredictor;
22
23 // Manages prefetches for multple navigations.
24 // - Created and owned by the resource prefetch predictor.
25 // - Needs to be refcounted as it is de-referenced on two different threads.
26 // - Created on the UI thread, but most functions are called in the IO thread.
27 // - Will only allow one inflight prefresh per main frame URL.
28 class ResourcePrefetcherManager
29 : public ResourcePrefetcher::Delegate,
30 public base::RefCountedThreadSafe<ResourcePrefetcherManager> {
31 public:
32 // The |predictor| should be alive till ShutdownOnIOThread is called.
33 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor,
34 const ResourcePrefetchPredictorConfig& config,
35 net::URLRequestContextGetter* getter);
36
37 // UI thread.
38 void ShutdownOnUIThread();
39
40 // --- IO Thread methods.
41
42 // The prefetchers need to be deleted on the IO thread.
43 void ShutdownOnIOThread();
44
45 // Will create a new ResourcePrefetcher for the main frame url of the input
46 // navigation if there isn't one already for the same URL.
47 void MaybeAddPrefetch(const NavigationID& navigation_id,
48 scoped_ptr<ResourcePrefetcher::RequestVector> requests);
49
50 // Stops the ResourcePrefetcher for the input navigation, if one was in
51 // progress.
52 void MaybeRemovePrefetch(const NavigationID& navigation_id);
53
54 // ResourcePrefetcher::Delegate methods.
55 virtual void ResourcePrefetcherFinished(
56 ResourcePrefetcher* prefetcher,
57 ResourcePrefetcher::RequestVector* requests) OVERRIDE;
58 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
59
60 private:
61 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>;
62 friend class MockResourcePrefetcherManager;
63
64 typedef std::map<GURL, ResourcePrefetcher*> PrefetcherMap;
65
66 virtual ~ResourcePrefetcherManager();
67
68 // UI Thread. |predictor_| needs to be called on the UI thread.
69 void ResourcePrefetcherFinishedOnUI(
70 const NavigationID& navigation_id,
71 scoped_ptr<ResourcePrefetcher::RequestVector> requests);
72
73 ResourcePrefetchPredictor* predictor_;
74 const ResourcePrefetchPredictorConfig config_;
75 net::URLRequestContextGetter* const context_getter_;
76
77 PrefetcherMap prefetcher_map_; // Owns the ResourcePrefetcher pointers.
78
79 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager);
80 };
81
82 } // namespace predictors
83
84 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698