OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_NET_ERROR_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/prefs/pref_member.h" | 12 #include "base/prefs/pref_member.h" |
12 #include "chrome/browser/net/dns_probe_service.h" | 13 #include "chrome/browser/net/dns_probe_service.h" |
13 #include "chrome/common/net/net_error_info.h" | 14 #include "chrome/common/net/net_error_info.h" |
14 #include "chrome/common/net/net_error_tracker.h" | |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
17 | 17 |
18 namespace chrome_browser_net { | 18 namespace chrome_browser_net { |
19 | 19 |
20 // A TabHelper that monitors loads for certain types of network errors and | 20 // A TabHelper that monitors loads for certain types of network errors and |
21 // does interesting things with them. Currently, starts DNS probes using the | 21 // does interesting things with them. Currently, starts DNS probes using the |
22 // DnsProbeService whenever a page fails to load with a DNS-related error. | 22 // DnsProbeService whenever a page fails to load with a DNS-related error. |
23 class NetErrorTabHelper | 23 class NetErrorTabHelper |
24 : public content::WebContentsObserver, | 24 : public content::WebContentsObserver, |
25 public content::WebContentsUserData<NetErrorTabHelper> { | 25 public content::WebContentsUserData<NetErrorTabHelper> { |
26 public: | 26 public: |
27 enum TestingState { | 27 enum TestingState { |
28 TESTING_DEFAULT, | 28 TESTING_DEFAULT, |
29 TESTING_FORCE_DISABLED, | 29 TESTING_FORCE_DISABLED, |
30 TESTING_FORCE_ENABLED | 30 TESTING_FORCE_ENABLED |
31 }; | 31 }; |
32 | 32 |
33 typedef base::Callback<void(chrome_common_net::DnsProbeStatus)> | |
34 NetErrorInfoSnoopCallback; | |
mmenke
2013/06/24 16:20:00
Since this takes a DnsProbeStatus rather than a Ne
Deprecated (see juliatuttle)
2013/06/25 16:45:04
There is no such type as a NetErrorInfo; I'll rena
mmenke
2013/06/25 17:40:26
There is actually a "ChromeViewMsg_NetErrorInfo",
| |
35 | |
33 virtual ~NetErrorTabHelper(); | 36 virtual ~NetErrorTabHelper(); |
34 | 37 |
35 static void set_state_for_testing(TestingState testing_state); | 38 static void set_state_for_testing(TestingState testing_state); |
36 | 39 |
40 // Sets a callback that will be called immediately after the helper sends | |
41 // a NetErrorHelper IPC. (Used by the DNS probe browser test to know when to | |
42 // check the error page for updates, instead of polling.) | |
43 void set_net_error_info_snoop_callback_for_testing( | |
44 const NetErrorInfoSnoopCallback& net_error_snoop_callback); | |
mmenke
2013/06/24 16:20:00
Per Google style guide, functions that use this na
Deprecated (see juliatuttle)
2013/06/25 16:45:04
Done.
| |
45 | |
37 // content::WebContentsObserver implementation. | 46 // content::WebContentsObserver implementation. |
38 virtual void DidStartProvisionalLoadForFrame( | 47 virtual void DidStartProvisionalLoadForFrame( |
39 int64 frame_id, | 48 int64 frame_id, |
40 int64 parent_frame_id, | 49 int64 parent_frame_id, |
41 bool is_main_frame, | 50 bool is_main_frame, |
42 const GURL& validated_url, | 51 const GURL& validated_url, |
43 bool is_error_page, | 52 bool is_error_page, |
44 bool is_iframe_srcdoc, | 53 bool is_iframe_srcdoc, |
45 content::RenderViewHost* render_view_host) OVERRIDE; | 54 content::RenderViewHost* render_view_host) OVERRIDE; |
46 | 55 |
47 virtual void DidCommitProvisionalLoadForFrame( | 56 virtual void DidCommitProvisionalLoadForFrame( |
48 int64 frame_id, | 57 int64 frame_id, |
49 bool is_main_frame, | 58 bool is_main_frame, |
50 const GURL& url, | 59 const GURL& url, |
51 content::PageTransition transition_type, | 60 content::PageTransition transition_type, |
52 content::RenderViewHost* render_view_host) OVERRIDE; | 61 content::RenderViewHost* render_view_host) OVERRIDE; |
53 | 62 |
54 virtual void DidFailProvisionalLoad( | 63 virtual void DidFailProvisionalLoad( |
55 int64 frame_id, | 64 int64 frame_id, |
56 bool is_main_frame, | 65 bool is_main_frame, |
57 const GURL& validated_url, | 66 const GURL& validated_url, |
58 int error_code, | 67 int error_code, |
59 const string16& error_description, | 68 const string16& error_description, |
60 content::RenderViewHost* render_view_host) OVERRIDE; | 69 content::RenderViewHost* render_view_host) OVERRIDE; |
61 | 70 |
62 virtual void DidFinishLoad( | 71 protected: |
63 int64 frame_id, | 72 // |contents| is the WebContents of the tab this NetErrorTabHelper is |
64 const GURL& validated_url, | 73 // attached to. |
65 bool is_main_frame, | 74 explicit NetErrorTabHelper(content::WebContents* contents); |
66 content::RenderViewHost* render_view_host) OVERRIDE; | 75 virtual void StartDnsProbe(); |
76 virtual void SendInfo(); | |
77 void OnDnsProbeFinished(chrome_common_net::DnsProbeStatus result); | |
78 | |
79 // The status of a DNS probe that may or may not have started or finished. | |
80 // Since the renderer can change out from under the helper (in cross-process | |
81 // navigations), it re-sends the status whenever an error page commits. | |
82 chrome_common_net::DnsProbeStatus dns_probe_status_; | |
67 | 83 |
68 private: | 84 private: |
69 friend class content::WebContentsUserData<NetErrorTabHelper>; | 85 friend class content::WebContentsUserData<NetErrorTabHelper>; |
70 | 86 |
71 enum DnsProbeState { | 87 void OnMainFrameDnsError(); |
72 DNS_PROBE_NONE, | |
73 DNS_PROBE_STARTED, | |
74 DNS_PROBE_FINISHED | |
75 }; | |
76 | |
77 // |contents| is the WebContents of the tab this NetErrorTabHelper is | |
78 // attached to. | |
79 explicit NetErrorTabHelper(content::WebContents* contents); | |
80 | |
81 void TrackerCallback(NetErrorTracker::DnsErrorPageState state); | |
82 void MaybePostStartDnsProbeTask(); | |
83 void OnDnsProbeFinished(chrome_common_net::DnsProbeResult result); | |
84 void MaybeSendInfo(); | |
85 | 88 |
86 void InitializePref(content::WebContents* contents); | 89 void InitializePref(content::WebContents* contents); |
87 bool ProbesAllowed() const; | 90 bool ProbesAllowed() const; |
88 | 91 |
89 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; | 92 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; |
90 | 93 |
91 NetErrorTracker tracker_; | 94 // True if the last provisional load that started was for an error page. |
92 NetErrorTracker::DnsErrorPageState dns_error_page_state_; | 95 bool is_error_page_; |
93 | 96 |
94 DnsProbeState dns_probe_state_; | 97 // True if the helper has seen a main frame page load fail with a DNS error, |
95 chrome_common_net::DnsProbeResult dns_probe_result_; | 98 // but has not yet seen a new page load successfully afterwards. |
99 bool dns_error_active_; | |
96 | 100 |
97 // Whether we are enabled to run by the DnsProbe-Enable field trial. | 101 // Whether we are enabled to run by the DnsProbe-Enable field trial. |
98 const bool enabled_by_trial_; | 102 const bool enabled_by_trial_; |
103 | |
104 // Optional callback for browser test to snoop on outgoing NetErrorInfo IPCs. | |
105 NetErrorInfoSnoopCallback net_error_info_snoop_callback_; | |
106 | |
99 // "Use a web service to resolve navigation errors" preference is required | 107 // "Use a web service to resolve navigation errors" preference is required |
100 // to allow probes. | 108 // to allow probes. |
101 BooleanPrefMember resolve_errors_with_web_service_; | 109 BooleanPrefMember resolve_errors_with_web_service_; |
102 | 110 |
103 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); | 111 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); |
104 }; | 112 }; |
105 | 113 |
106 } // namespace chrome_browser_net | 114 } // namespace chrome_browser_net |
107 | 115 |
108 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 116 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
OLD | NEW |