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

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

Issue 10416002: Seculative resource prefetching for URLs CL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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_PREFETCH_PREDICTOR_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h"
15 #include "chrome/browser/predictors/resource_prefetch_common.h"
16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
17 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "googleurl/src/gurl.h"
21 #include "webkit/glue/resource_type.h"
22
23 class PredictorsHandler;
24 class Profile;
25
26 namespace content {
27 class WebContents;
28 }
29
30 namespace history {
31 class URLrowsDatabase;
32 }
33
34 namespace net {
35 class URLRequest;
36 }
37
38 namespace predictors {
39
40 // Contains logic for learning what can be prefetched and for kicking off
41 // speculative prefetching.
42 // - All functions apart form constructor/destructor needs to be called on
dominich 2012/05/21 16:16:53 nit: form-> from, needs -> need
dominich 2012/05/21 16:16:53 this isn't accurate - the static methods are not t
Shishir 2012/05/23 01:46:46 removed comment.
Shishir 2012/05/23 01:46:46 removed comment.
43 // the UI thread.
44 class ResourcePrefetchPredictor : public content::NotificationObserver,
45 public RefcountedProfileKeyedService {
willchan no longer on Chromium 2012/05/21 20:20:18 You need way more documentation. How is this class
Shishir 2012/05/23 01:46:46 Added documentation.
46 public:
47 explicit ResourcePrefetchPredictor(Profile* profile);
48 virtual ~ResourcePrefetchPredictor();
49
50 // Stores the data that we need to get from the URLRequest.
51 struct URLRequestSummary {
52 URLRequestSummary();
53 URLRequestSummary(const URLRequestSummary& other);
dominich 2012/05/21 16:16:53 Try explicit here - I don't know if STL is using d
Shishir 2012/05/23 01:46:46 Doesnt work with STL.
54 ~URLRequestSummary();
55 bool InitFromURLRequest(net::URLRequest* request, bool is_response);
56
57 NavigationID navigation_id_;
dominich 2012/05/21 16:16:53 is there any need for these members to be public?
Shishir 2012/05/23 01:46:46 Not sure I understand. Are you suggesting making t
58 GURL resource_url_;
59 ResourceType::Type resource_type_;
60
61 // Only for responses.
62 std::string mime_type_;
63 bool was_cached_;
64 };
65
66 // Thread safe.
67 static bool IsEnabled();
68 static bool ShouldInterceptRequest(net::URLRequest* request);
69 static bool ShouldInterceptResponse(net::URLRequest* response);
70 static bool ShouldInterceptRedirect(net::URLRequest* response);
71
72 // UI thread.
73 void RecordURLRequest(const URLRequestSummary& request);
74 void RecordUrlResponse(const URLRequestSummary& response);
75 void RecordUrlRedirect(const URLRequestSummary& response);
76
77 private:
78 friend class ::PredictorsHandler;
79
80 // TODO(shishir): Maybe use pointers to make the sort cheaper.
81 typedef ResourcePrefetchPredictorTables::UrlTableRow UrlTableRow;
82 typedef std::vector<UrlTableRow> UrlTableRowVector;
83
84 struct UrlTableCacheValue {
85 UrlTableRowVector rows_;
86 base::Time last_visit_;
87 };
88
89 typedef std::map<NavigationID, std::vector<URLRequestSummary> > NavigationMap;
90 typedef std::map<GURL, UrlTableCacheValue> UrlTableCacheMap;
91
92 // RefcountedProfileKeyedService methods OVERRIDE.
93 virtual void ShutdownOnUIThread() OVERRIDE;
94
95 // content::NotificationObserver methods OVERRIDE.
96 virtual void Observe(int type,
97 const content::NotificationSource& source,
98 const content::NotificationDetails& details) OVERRIDE;
99
100 static bool IsHandledMainPage(net::URLRequest* request);
101 static bool IsHandledSubresource(net::URLRequest* response);
102 static bool IsCacheable(net::URLRequest* response);
103
104 // Deal with different kinds of requests.
105 void OnMainFrameRequest(const URLRequestSummary& request);
106 void OnMainFrameResponse(const URLRequestSummary& response);
107 void OnMainFrameRedirect(const URLRequestSummary& response);
108 void OnSubresourceResponse(const URLRequestSummary& response);
109 void OnSubresourceLoadedFromMemory(const NavigationID& navigation_id,
110 const GURL& resource_url);
111
112 void OnHistoryAndCacheLoaded();
113 void CreateCaches(std::vector<UrlTableRow>* url_rows);
114 bool ShouldTrackUrl(const GURL& url);
115 void CleanupAbandonedNavigations(const NavigationID& navigation_id);
116 void OnNavigationComplete(const NavigationID& navigation_id);
117 void LearnUrlNavigation(const GURL& main_frame_url,
118 const std::vector<URLRequestSummary>& new_value);
119 void RemoveAnEntryFromUrlDB();
120 void MaybeReportAccuracyStats(const NavigationID& navigation_id);
121
122 Profile* profile_;
123 bool initialized_;
124 scoped_refptr<ResourcePrefetchPredictorTables> tables_;
125 scoped_ptr<content::NotificationRegistrar> notification_registrar_;
126
127 NavigationMap inflight_navigations_;
128 UrlTableCacheMap url_table_cache_;
129
130 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor);
131 };
132
133 } // namespace predictors
134
135 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698