| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | |
| 6 #define CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | |
| 13 #include "content/public/browser/resource_request_info.h" | |
| 14 #include "content/public/common/resource_type.h" | |
| 15 | |
| 16 namespace net { | |
| 17 class URLRequest; | |
| 18 } | |
| 19 | |
| 20 class GURL; | |
| 21 | |
| 22 namespace chrome_browser_net { | |
| 23 | |
| 24 // Observes resource requests in the ResourceDispatcherHostDelegate and notifies | |
| 25 // the ResourcePrefetchPredictor about the ones it is interested in. | |
| 26 // - Has an instance per profile, and is owned by the corresponding | |
| 27 // ProfileIOData. | |
| 28 // - Needs to be constructed on UI thread. Can be destroyed on UI or IO thread. | |
| 29 // As for member functions, public members are meant to be called on the IO | |
| 30 // thread and private members from the UI thread. | |
| 31 class ResourcePrefetchPredictorObserver { | |
| 32 public: | |
| 33 explicit ResourcePrefetchPredictorObserver( | |
| 34 predictors::ResourcePrefetchPredictor* predictor); | |
| 35 ~ResourcePrefetchPredictorObserver(); | |
| 36 | |
| 37 // Parts of the ResourceDispatcherHostDelegate that we want to observe. | |
| 38 void OnRequestStarted(net::URLRequest* request, | |
| 39 content::ResourceType resource_type, | |
| 40 const content::ResourceRequestInfo::WebContentsGetter& | |
| 41 web_contents_getter); | |
| 42 void OnRequestRedirected( | |
| 43 net::URLRequest* request, | |
| 44 const GURL& redirect_url, | |
| 45 const content::ResourceRequestInfo::WebContentsGetter& | |
| 46 web_contents_getter); | |
| 47 void OnResponseStarted(net::URLRequest* request, | |
| 48 const content::ResourceRequestInfo::WebContentsGetter& | |
| 49 web_contents_getter); | |
| 50 | |
| 51 private: | |
| 52 void OnRequestStartedOnUIThread( | |
| 53 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
| 54 summary, | |
| 55 const content::ResourceRequestInfo::WebContentsGetter& | |
| 56 web_contents_getter, | |
| 57 const GURL& main_frame_url, | |
| 58 const base::TimeTicks& creation_time) const; | |
| 59 void OnRequestRedirectedOnUIThread( | |
| 60 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
| 61 summary, | |
| 62 const content::ResourceRequestInfo::WebContentsGetter& | |
| 63 web_contents_getter, | |
| 64 const GURL& main_frame_url, | |
| 65 const base::TimeTicks& creation_time) const; | |
| 66 void OnResponseStartedOnUIThread( | |
| 67 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
| 68 summary, | |
| 69 const content::ResourceRequestInfo::WebContentsGetter& | |
| 70 web_contents_getter, | |
| 71 const GURL& main_frame_url, | |
| 72 const base::TimeTicks& creation_time) const; | |
| 73 | |
| 74 // Owned by profile. | |
| 75 base::WeakPtr<predictors::ResourcePrefetchPredictor> predictor_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorObserver); | |
| 78 }; | |
| 79 | |
| 80 } // namespace chrome_browser_net | |
| 81 | |
| 82 #endif // CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | |
| OLD | NEW |