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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/prefs/pref_member.h" | 11 #include "base/prefs/pref_member.h" |
12 #include "chrome/browser/net/dns_probe_service.h" | 12 #include "chrome/browser/net/dns_probe_service.h" |
13 #include "chrome/common/net/net_error_info.h" | 13 #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" | 14 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
17 | 16 |
18 namespace chrome_browser_net { | 17 namespace chrome_browser_net { |
19 | 18 |
20 // A TabHelper that monitors loads for certain types of network errors and | 19 // A TabHelper that monitors loads for certain types of network errors and |
21 // does interesting things with them. Currently, starts DNS probes using the | 20 // does interesting things with them. Currently, starts DNS probes using the |
22 // DnsProbeService whenever a page fails to load with a DNS-related error. | 21 // DnsProbeService whenever a page fails to load with a DNS-related error. |
23 class NetErrorTabHelper | 22 class NetErrorTabHelper |
24 : public content::WebContentsObserver, | 23 : public content::WebContentsObserver, |
(...skipping 27 matching lines...) Expand all Loading... | |
52 content::RenderViewHost* render_view_host) OVERRIDE; | 51 content::RenderViewHost* render_view_host) OVERRIDE; |
53 | 52 |
54 virtual void DidFailProvisionalLoad( | 53 virtual void DidFailProvisionalLoad( |
55 int64 frame_id, | 54 int64 frame_id, |
56 bool is_main_frame, | 55 bool is_main_frame, |
57 const GURL& validated_url, | 56 const GURL& validated_url, |
58 int error_code, | 57 int error_code, |
59 const string16& error_description, | 58 const string16& error_description, |
60 content::RenderViewHost* render_view_host) OVERRIDE; | 59 content::RenderViewHost* render_view_host) OVERRIDE; |
61 | 60 |
62 virtual void DidFinishLoad( | 61 protected: |
63 int64 frame_id, | 62 // |contents| is the WebContents of the tab this NetErrorTabHelper is |
64 const GURL& validated_url, | 63 // attached to. |
65 bool is_main_frame, | 64 explicit NetErrorTabHelper(content::WebContents* contents); |
66 content::RenderViewHost* render_view_host) OVERRIDE; | 65 virtual void StartDnsProbe(); |
66 virtual void SendInfo(); | |
67 void OnDnsProbeFinished(chrome_common_net::DnsProbeStatus result); | |
68 | |
69 // The status of a DNS probe that may or may not have started or finished. | |
70 // (Resent whenever an error page commits, in case it is in a new renderer.) | |
mmenke
2013/06/12 19:17:12
I think this comment is hard to follow. What you
Deprecated (see juliatuttle)
2013/06/13 14:37:04
Done.
| |
71 chrome_common_net::DnsProbeStatus dns_probe_status_; | |
67 | 72 |
68 private: | 73 private: |
69 friend class content::WebContentsUserData<NetErrorTabHelper>; | 74 friend class content::WebContentsUserData<NetErrorTabHelper>; |
70 | 75 |
71 enum DnsProbeState { | 76 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 | 77 |
86 void InitializePref(content::WebContents* contents); | 78 void InitializePref(content::WebContents* contents); |
87 bool ProbesAllowed() const; | 79 bool ProbesAllowed() const; |
88 | 80 |
89 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; | 81 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; |
90 | 82 |
91 NetErrorTracker tracker_; | 83 // True if the last provisional load that started was for an error page. |
92 NetErrorTracker::DnsErrorPageState dns_error_page_state_; | 84 bool is_error_page_; |
93 | 85 |
94 DnsProbeState dns_probe_state_; | 86 // True if the helper has seen a main frame page load fail with a DNS error, |
95 chrome_common_net::DnsProbeResult dns_probe_result_; | 87 // but has not yet seen a new page load successfully afterwards. |
88 bool dns_error_active_; | |
96 | 89 |
97 // Whether we are enabled to run by the DnsProbe-Enable field trial. | 90 // Whether we are enabled to run by the DnsProbe-Enable field trial. |
98 const bool enabled_by_trial_; | 91 const bool enabled_by_trial_; |
92 | |
99 // "Use a web service to resolve navigation errors" preference is required | 93 // "Use a web service to resolve navigation errors" preference is required |
100 // to allow probes. | 94 // to allow probes. |
101 BooleanPrefMember resolve_errors_with_web_service_; | 95 BooleanPrefMember resolve_errors_with_web_service_; |
102 | 96 |
103 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); | 97 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); |
104 }; | 98 }; |
105 | 99 |
106 } // namespace chrome_browser_net | 100 } // namespace chrome_browser_net |
107 | 101 |
108 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 102 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
OLD | NEW |