Index: chrome/browser/predictors/resource_prefetch_predictor.h |
diff --git a/chrome/browser/predictors/resource_prefetch_predictor.h b/chrome/browser/predictors/resource_prefetch_predictor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7fff36f0dbe263dd3a13eeb6744e396ef6ae4678 |
--- /dev/null |
+++ b/chrome/browser/predictors/resource_prefetch_predictor.h |
@@ -0,0 +1,135 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
+#define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
+#pragma once |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/time.h" |
+#include "chrome/browser/predictors/resource_prefetch_common.h" |
+#include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
+#include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+#include "googleurl/src/gurl.h" |
+#include "webkit/glue/resource_type.h" |
+ |
+class PredictorsHandler; |
+class Profile; |
+ |
+namespace content { |
+class WebContents; |
+} |
+ |
+namespace history { |
+class URLrowsDatabase; |
+} |
+ |
+namespace net { |
+class URLRequest; |
+} |
+ |
+namespace predictors { |
+ |
+// Contains logic for learning what can be prefetched and for kicking off |
+// speculative prefetching. |
+// - 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.
|
+// the UI thread. |
+class ResourcePrefetchPredictor : public content::NotificationObserver, |
+ 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.
|
+ public: |
+ explicit ResourcePrefetchPredictor(Profile* profile); |
+ virtual ~ResourcePrefetchPredictor(); |
+ |
+ // Stores the data that we need to get from the URLRequest. |
+ struct URLRequestSummary { |
+ URLRequestSummary(); |
+ 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.
|
+ ~URLRequestSummary(); |
+ bool InitFromURLRequest(net::URLRequest* request, bool is_response); |
+ |
+ 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
|
+ GURL resource_url_; |
+ ResourceType::Type resource_type_; |
+ |
+ // Only for responses. |
+ std::string mime_type_; |
+ bool was_cached_; |
+ }; |
+ |
+ // Thread safe. |
+ static bool IsEnabled(); |
+ static bool ShouldInterceptRequest(net::URLRequest* request); |
+ static bool ShouldInterceptResponse(net::URLRequest* response); |
+ static bool ShouldInterceptRedirect(net::URLRequest* response); |
+ |
+ // UI thread. |
+ void RecordURLRequest(const URLRequestSummary& request); |
+ void RecordUrlResponse(const URLRequestSummary& response); |
+ void RecordUrlRedirect(const URLRequestSummary& response); |
+ |
+ private: |
+ friend class ::PredictorsHandler; |
+ |
+ // TODO(shishir): Maybe use pointers to make the sort cheaper. |
+ typedef ResourcePrefetchPredictorTables::UrlTableRow UrlTableRow; |
+ typedef std::vector<UrlTableRow> UrlTableRowVector; |
+ |
+ struct UrlTableCacheValue { |
+ UrlTableRowVector rows_; |
+ base::Time last_visit_; |
+ }; |
+ |
+ typedef std::map<NavigationID, std::vector<URLRequestSummary> > NavigationMap; |
+ typedef std::map<GURL, UrlTableCacheValue> UrlTableCacheMap; |
+ |
+ // RefcountedProfileKeyedService methods OVERRIDE. |
+ virtual void ShutdownOnUIThread() OVERRIDE; |
+ |
+ // content::NotificationObserver methods OVERRIDE. |
+ virtual void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) OVERRIDE; |
+ |
+ static bool IsHandledMainPage(net::URLRequest* request); |
+ static bool IsHandledSubresource(net::URLRequest* response); |
+ static bool IsCacheable(net::URLRequest* response); |
+ |
+ // Deal with different kinds of requests. |
+ void OnMainFrameRequest(const URLRequestSummary& request); |
+ void OnMainFrameResponse(const URLRequestSummary& response); |
+ void OnMainFrameRedirect(const URLRequestSummary& response); |
+ void OnSubresourceResponse(const URLRequestSummary& response); |
+ void OnSubresourceLoadedFromMemory(const NavigationID& navigation_id, |
+ const GURL& resource_url); |
+ |
+ void OnHistoryAndCacheLoaded(); |
+ void CreateCaches(std::vector<UrlTableRow>* url_rows); |
+ bool ShouldTrackUrl(const GURL& url); |
+ void CleanupAbandonedNavigations(const NavigationID& navigation_id); |
+ void OnNavigationComplete(const NavigationID& navigation_id); |
+ void LearnUrlNavigation(const GURL& main_frame_url, |
+ const std::vector<URLRequestSummary>& new_value); |
+ void RemoveAnEntryFromUrlDB(); |
+ void MaybeReportAccuracyStats(const NavigationID& navigation_id); |
+ |
+ Profile* profile_; |
+ bool initialized_; |
+ scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
+ scoped_ptr<content::NotificationRegistrar> notification_registrar_; |
+ |
+ NavigationMap inflight_navigations_; |
+ UrlTableCacheMap url_table_cache_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
+}; |
+ |
+} // namespace predictors |
+ |
+#endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |