1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_
6 #define CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
11 #include "content/public/common/resource_type.h"
19 namespace chrome_browser_net
{
21 // Observes resource requests in the ResourceDispatcherHostDelegate and notifies
22 // the ResourcePrefetchPredictor about the ones it is interested in.
23 // - Has an instance per profile, and is owned by the corresponding
25 // - Needs to be constructed on UI thread. Rest of the functions can only be
26 // called on the IO thread. Can be destroyed on UI or IO thread.
27 class ResourcePrefetchPredictorObserver
{
29 explicit ResourcePrefetchPredictorObserver(
30 predictors::ResourcePrefetchPredictor
* predictor
);
31 ~ResourcePrefetchPredictorObserver();
33 // Parts of the ResourceDispatcherHostDelegate that we want to observe.
34 void OnRequestStarted(net::URLRequest
* request
,
35 content::ResourceType resource_type
,
38 void OnRequestRedirected(const GURL
& redirect_url
, net::URLRequest
* request
);
39 void OnResponseStarted(net::URLRequest
* request
);
43 base::WeakPtr
<predictors::ResourcePrefetchPredictor
> predictor_
;
45 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorObserver
);
48 } // namespace chrome_browser_net
50 #endif // CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_