Chromium Code Reviews| 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..1b94fd1cc330a47b6962042d45dc67e32cfb3af5 |
| --- /dev/null |
| +++ b/chrome/browser/predictors/resource_prefetcher_manager.h |
| @@ -0,0 +1,91 @@ |
| +// 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/linked_ptr.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "chrome/browser/predictors/resource_prefetcher.h" |
| +#include "chrome/browser/predictors/resource_prefetch_common.h" |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace predictors { |
| + |
| +struct NavigationID; |
| + |
| +// Manages prefetches for multple navigations. |
| +// - Created and owned by the resource prefetch predictor. |
| +// - 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 ResourcePrefetcher::Delegate, |
| + public base::RefCountedThreadSafe<ResourcePrefetcherManager> { |
|
dominich
2012/07/23 16:04:41
If this is created and owned by the resource prefe
Shishir
2012/08/01 22:35:24
Because this needs to be de-referenced on two diff
|
| + public: |
| + // Used to notify when prefetching is done for a single navigation. |
| + // The Delegate will be called on the UI Thread and should be alive till |
| + // ShutdownOnUIThread is called. |
| + // manager. |
|
dominich
2012/07/23 16:04:41
nit: extra word.
Shishir
2012/08/01 22:35:24
Done.
|
| + class Delegate { |
|
dominich
2012/07/23 16:04:41
I think this is such a tightly bound system that u
Shishir
2012/08/01 22:35:24
Removed.
|
| + public: |
| + virtual ~Delegate() { } |
| + virtual void FinishedPrefetchForNavigation( |
| + const NavigationID& navigation_id, |
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests) = 0; |
| + }; |
| + |
| + ResourcePrefetcherManager(Delegate* delegate, |
| + 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); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; |
| + |
| + virtual ~ResourcePrefetcherManager(); |
| + |
| + // ResourcePrefetcher::Delegate methods OVERRIDE. |
| + virtual void ResourcePrefetcherFinished( |
| + ResourcePrefetcher* prefetcher, |
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests) OVERRIDE; |
| + virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| + |
| + // UI Thread. |
| + // The delegate needs to be called on the UI thread. |
| + void ResourcePrefetcherFinishedOnUI( |
| + const NavigationID& navigation_id, |
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests); |
| + |
| + Delegate* delegate_; // Can only be called on the UI thread. |
| + ResourcePrefetchPredictorConfig config_; |
| + net::URLRequestContextGetter* context_getter_; |
| + std::map<GURL, linked_ptr<ResourcePrefetcher> > prefetchers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); |
| +}; |
| + |
| +} // namespace predictors |
| + |
| +#endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ |