OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ |
6 #define CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | 6 #define CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ |
7 | 7 |
8 #include <memory> | |
ahemery
2016/12/06 14:31:12
For unique_ptr
Benoit L
2016/12/06 14:58:18
Thanks for adding the comments in the review, but
| |
9 | |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 12 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
13 #include "content/public/browser/resource_request_info.h" | |
11 #include "content/public/common/resource_type.h" | 14 #include "content/public/common/resource_type.h" |
12 | 15 |
13 namespace net { | 16 namespace net { |
14 class URLRequest; | 17 class URLRequest; |
15 } | 18 } |
16 | 19 |
17 class GURL; | 20 class GURL; |
18 | 21 |
19 namespace chrome_browser_net { | 22 namespace chrome_browser_net { |
20 | 23 |
21 // Observes resource requests in the ResourceDispatcherHostDelegate and notifies | 24 // Observes resource requests in the ResourceDispatcherHostDelegate and notifies |
22 // the ResourcePrefetchPredictor about the ones it is interested in. | 25 // the ResourcePrefetchPredictor about the ones it is interested in. |
23 // - Has an instance per profile, and is owned by the corresponding | 26 // - Has an instance per profile, and is owned by the corresponding |
24 // ProfileIOData. | 27 // ProfileIOData. |
25 // - Needs to be constructed on UI thread. Rest of the functions can only be | 28 // - Needs to be constructed on UI thread. Can be destroyed on UI or IO thread. |
26 // called on the IO 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. | |
27 class ResourcePrefetchPredictorObserver { | 31 class ResourcePrefetchPredictorObserver { |
28 public: | 32 public: |
29 explicit ResourcePrefetchPredictorObserver( | 33 explicit ResourcePrefetchPredictorObserver( |
30 predictors::ResourcePrefetchPredictor* predictor); | 34 predictors::ResourcePrefetchPredictor* predictor); |
31 ~ResourcePrefetchPredictorObserver(); | 35 ~ResourcePrefetchPredictorObserver(); |
32 | 36 |
33 // Parts of the ResourceDispatcherHostDelegate that we want to observe. | 37 // Parts of the ResourceDispatcherHostDelegate that we want to observe. |
34 void OnRequestStarted(net::URLRequest* request, | 38 void OnRequestStarted( |
35 content::ResourceType resource_type, | 39 net::URLRequest* request, |
36 int child_id, | 40 content::ResourceType resource_type, |
37 int frame_id); | 41 const content::ResourceRequestInfo::WebContentsGetter& |
38 void OnRequestRedirected(const GURL& redirect_url, net::URLRequest* request); | 42 web_contents_getter); |
39 void OnResponseStarted(net::URLRequest* request); | 43 void OnRequestRedirected( |
44 net::URLRequest* request, | |
45 const GURL& redirect_url, | |
46 const content::ResourceRequestInfo::WebContentsGetter& | |
47 web_contents_getter); | |
48 void OnResponseStarted( | |
49 net::URLRequest* request, | |
50 const content::ResourceRequestInfo::WebContentsGetter& | |
51 web_contents_getter); | |
40 | 52 |
ahemery
2016/12/06 14:31:11
Comment about the additional parameters. WebConten
| |
41 private: | 53 private: |
54 void OnRequestStartedOnUIThread( | |
55 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
56 summary, | |
57 const content::ResourceRequestInfo::WebContentsGetter& | |
58 web_contents_getter, | |
59 const GURL& main_frame_url, | |
60 const base::TimeTicks& creation_time) const; | |
61 void OnRequestRedirectedOnUIThread( | |
62 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
63 summary, | |
64 const content::ResourceRequestInfo::WebContentsGetter& | |
65 web_contents_getter, | |
66 const GURL& main_frame_url, | |
67 const base::TimeTicks& creation_time) const; | |
68 void OnResponseStartedOnUIThread( | |
69 std::unique_ptr<predictors::ResourcePrefetchPredictor::URLRequestSummary> | |
70 summary, | |
71 const content::ResourceRequestInfo::WebContentsGetter& | |
72 web_contents_getter, | |
73 const GURL& main_frame_url, | |
74 const base::TimeTicks& creation_time) const; | |
75 | |
76 bool TryToFillNavigationID( | |
Benoit L
2016/12/06 14:58:18
This can be made static, right?
If so, please make
ahemery
2016/12/06 15:17:38
Now an implementation detail
| |
77 predictors::NavigationID* navigation_id, | |
78 const content::ResourceRequestInfo::WebContentsGetter& | |
79 web_contents_getter, | |
80 const GURL& main_frame_url, | |
81 const base::TimeTicks& creation_time) const; | |
82 | |
42 // Owned by profile. | 83 // Owned by profile. |
43 base::WeakPtr<predictors::ResourcePrefetchPredictor> predictor_; | 84 base::WeakPtr<predictors::ResourcePrefetchPredictor> predictor_; |
44 | 85 |
45 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorObserver); | 86 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorObserver); |
46 }; | 87 }; |
47 | 88 |
48 } // namespace chrome_browser_net | 89 } // namespace chrome_browser_net |
49 | 90 |
50 #endif // CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ | 91 #endif // CHROME_BROWSER_NET_RESOURCE_PREFETCH_PREDICTOR_OBSERVER_H_ |
OLD | NEW |