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 #include "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/net/chrome_net_log.h" | 10 #include "chrome/browser/net/chrome_net_log.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 base::Unretained(this), | 57 base::Unretained(this), |
58 host)); | 58 host)); |
59 return net::ERR_NAME_NOT_RESOLVED; | 59 return net::ERR_NAME_NOT_RESOLVED; |
60 } | 60 } |
61 | 61 |
62 int RequestedHostnameCount() const { | 62 int RequestedHostnameCount() const { |
63 return requested_hostnames_.size(); | 63 return requested_hostnames_.size(); |
64 } | 64 } |
65 | 65 |
66 bool HasHostBeenRequested(const std::string& hostname) const { | 66 bool HasHostBeenRequested(const std::string& hostname) const { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
68 return std::find(requested_hostnames_.begin(), | 68 return std::find(requested_hostnames_.begin(), |
69 requested_hostnames_.end(), | 69 requested_hostnames_.end(), |
70 hostname) != requested_hostnames_.end(); | 70 hostname) != requested_hostnames_.end(); |
71 } | 71 } |
72 | 72 |
73 void WaitUntilHostHasBeenRequested(const std::string& hostname) { | 73 void WaitUntilHostHasBeenRequested(const std::string& hostname) { |
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
75 DCHECK(!is_waiting_for_hostname_); | 75 DCHECK(!is_waiting_for_hostname_); |
76 if (HasHostBeenRequested(hostname)) | 76 if (HasHostBeenRequested(hostname)) |
77 return; | 77 return; |
78 waiting_for_hostname_ = hostname; | 78 waiting_for_hostname_ = hostname; |
79 is_waiting_for_hostname_ = true; | 79 is_waiting_for_hostname_ = true; |
80 content::RunMessageLoop(); | 80 content::RunMessageLoop(); |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 ~HostResolutionRequestRecorder() override {} | 84 ~HostResolutionRequestRecorder() override {} |
85 | 85 |
86 void AddToHistory(const std::string& hostname) { | 86 void AddToHistory(const std::string& hostname) { |
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
88 requested_hostnames_.push_back(hostname); | 88 requested_hostnames_.push_back(hostname); |
89 if (is_waiting_for_hostname_ && waiting_for_hostname_ == hostname) { | 89 if (is_waiting_for_hostname_ && waiting_for_hostname_ == hostname) { |
90 is_waiting_for_hostname_ = false; | 90 is_waiting_for_hostname_ = false; |
91 waiting_for_hostname_.clear(); | 91 waiting_for_hostname_.clear(); |
92 base::MessageLoop::current()->Quit(); | 92 base::MessageLoop::current()->Quit(); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 // The hostname which WaitUntilHostHasBeenRequested is currently waiting for | 96 // The hostname which WaitUntilHostHasBeenRequested is currently waiting for |
97 // to be requested. | 97 // to be requested. |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 net_log_observer.Attach(); | 304 net_log_observer.Attach(); |
305 | 305 |
306 ui_test_utils::NavigateToURL(browser(), GURL(data_uri)); | 306 ui_test_utils::NavigateToURL(browser(), GURL(data_uri)); |
307 | 307 |
308 net_log_observer.WaitForConnect(); | 308 net_log_observer.WaitForConnect(); |
309 net_log_observer.Detach(); | 309 net_log_observer.Detach(); |
310 } | 310 } |
311 | 311 |
312 } // namespace chrome_browser_net | 312 } // namespace chrome_browser_net |
313 | 313 |
OLD | NEW |