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

Unified 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 comments. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/predictors/resource_prefetcher_manager.h
diff --git a/chrome/browser/predictors/resource_prefetcher_manager.h b/chrome/browser/predictors/resource_prefetcher_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..04c7f85f6f77d0ce82efbe165b4bd07d8081c83a
--- /dev/null
+++ b/chrome/browser/predictors/resource_prefetcher_manager.h
@@ -0,0 +1,88 @@
+// 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_PREFETCHER_MANAGER_H_
+#define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
+
+#include <map>
+
+#include "base/memory/ref_counted.h"
+#include "base/stl_util.h"
+#include "chrome/browser/predictors/resource_prefetcher.h"
+#include "chrome/browser/predictors/resource_prefetch_common.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+namespace predictors {
+
+struct NavigationID;
+class ResourcePrefetchPredictor;
+
+// Manages prefetches for multple navigations.
+// - Created and owned by the resource prefetch predictor.
+// - Needs to be refcounted as it is de-referenced on two different threads.
+// - Created on the UI thread, but most functions are called in the IO thread.
+// - Will only allow one inflight prefresh per main frame URL.
+class ResourcePrefetcherManager
+ : public base::RefCountedThreadSafe<ResourcePrefetcherManager> {
+ public:
+ // The 'predictor' should be live till ShutdownOnIOThread is called.
dominich 2012/08/02 15:00:50 nit: variable name ||
Shishir 2012/08/02 22:06:54 Done.
+ ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor,
+ const ResourcePrefetchPredictorConfig& config,
+ net::URLRequestContextGetter* getter);
+
+ // UI thread.
+ void ShutdownOnUIThread();
+
+ // --- IO Thread methods.
+
+ // The prefetchers need to be deleted on the IO thread.
+ void ShutdownOnIOThread();
+
+ // Will create a new ResourcePrefetcher for the main frame url of the input
+ // navigation if there isn't one already for the same URL.
+ void MaybeAddPrefetch(const NavigationID& navigation_id,
+ scoped_ptr<ResourcePrefetcher::RequestVector> requests);
+
+ // Stops the ResourcePrefetcher for the input navigation, if one was in
+ // progress.
+ void MaybeRemovePrefetch(const NavigationID& navigation_id);
+
+ // Called by the ResourcePrefetcher when it finishes. Takes ownership of
+ // requests.
+ virtual void ResourcePrefetcherFinished(
+ ResourcePrefetcher* prefetcher,
+ ResourcePrefetcher::RequestVector* requests);
+
+ // Called by the ResourcePrefetcher.
+ virtual net::URLRequestContext* GetURLRequestContext();
+
+ private:
+ friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>;
+ friend class ResourcePrefetcherManagerTest;
+
+ typedef std::map<GURL, ResourcePrefetcher*> PrefetcherMap;
+
+ virtual ~ResourcePrefetcherManager();
+
+ // UI Thread. 'predictor_' needs to be called on the UI thread.
dominich 2012/08/02 15:00:50 nit: variable name ||
Shishir 2012/08/02 22:06:54 Done.
+ void ResourcePrefetcherFinishedOnUI(
+ const NavigationID& navigation_id,
+ scoped_ptr<ResourcePrefetcher::RequestVector> requests);
+
+ ResourcePrefetchPredictor* predictor_;
+ const ResourcePrefetchPredictorConfig const config_;
+ net::URLRequestContextGetter* const context_getter_;
+
+ PrefetcherMap prefetcher_map_; // Owns the pointers.
dominich 2012/08/02 15:00:50 nit: owns what pointers?
Shishir 2012/08/02 22:06:54 Done.
+ STLValueDeleter<PrefetcherMap> prefetcher_map_deleter_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager);
+};
+
+} // namespace predictors
+
+#endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698