| 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/json/json_string_value_serializer.h" | 5 #include "base/json/json_string_value_serializer.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "chrome/browser/net/predictor.h" | 7 #include "chrome/browser/net/predictor.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 public: | 26 public: |
| 27 HostResolutionRequestRecorder() | 27 HostResolutionRequestRecorder() |
| 28 : HostResolverProc(NULL), | 28 : HostResolverProc(NULL), |
| 29 is_waiting_for_hostname_(false) { | 29 is_waiting_for_hostname_(false) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual int Resolve(const std::string& host, | 32 virtual int Resolve(const std::string& host, |
| 33 net::AddressFamily address_family, | 33 net::AddressFamily address_family, |
| 34 net::HostResolverFlags host_resolver_flags, | 34 net::HostResolverFlags host_resolver_flags, |
| 35 net::AddressList* addrlist, | 35 net::AddressList* addrlist, |
| 36 int* os_error) OVERRIDE { | 36 int* os_error) override { |
| 37 BrowserThread::PostTask( | 37 BrowserThread::PostTask( |
| 38 BrowserThread::UI, | 38 BrowserThread::UI, |
| 39 FROM_HERE, | 39 FROM_HERE, |
| 40 base::Bind(&HostResolutionRequestRecorder::AddToHistory, | 40 base::Bind(&HostResolutionRequestRecorder::AddToHistory, |
| 41 base::Unretained(this), | 41 base::Unretained(this), |
| 42 host)); | 42 host)); |
| 43 return net::ERR_NAME_NOT_RESOLVED; | 43 return net::ERR_NAME_NOT_RESOLVED; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool HasHostBeenRequested(const std::string& hostname) { | 46 bool HasHostBeenRequested(const std::string& hostname) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 class PredictorBrowserTest : public InProcessBrowserTest { | 95 class PredictorBrowserTest : public InProcessBrowserTest { |
| 96 public: | 96 public: |
| 97 PredictorBrowserTest() | 97 PredictorBrowserTest() |
| 98 : startup_url_("http://host1:1"), | 98 : startup_url_("http://host1:1"), |
| 99 referring_url_("http://host2:1"), | 99 referring_url_("http://host2:1"), |
| 100 target_url_("http://host3:1"), | 100 target_url_("http://host3:1"), |
| 101 host_resolution_request_recorder_(new HostResolutionRequestRecorder) { | 101 host_resolution_request_recorder_(new HostResolutionRequestRecorder) { |
| 102 } | 102 } |
| 103 | 103 |
| 104 protected: | 104 protected: |
| 105 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 105 virtual void SetUpInProcessBrowserTestFixture() override { |
| 106 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc( | 106 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc( |
| 107 host_resolution_request_recorder_.get())); | 107 host_resolution_request_recorder_.get())); |
| 108 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 108 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 111 virtual void TearDownInProcessBrowserTestFixture() override { |
| 112 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 112 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 113 scoped_host_resolver_proc_.reset(); | 113 scoped_host_resolver_proc_.reset(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void LearnAboutInitialNavigation(const GURL& url) { | 116 void LearnAboutInitialNavigation(const GURL& url) { |
| 117 Predictor* predictor = browser()->profile()->GetNetworkPredictor(); | 117 Predictor* predictor = browser()->profile()->GetNetworkPredictor(); |
| 118 BrowserThread::PostTask(BrowserThread::IO, | 118 BrowserThread::PostTask(BrowserThread::IO, |
| 119 FROM_HERE, | 119 FROM_HERE, |
| 120 base::Bind(&Predictor::LearnAboutInitialNavigation, | 120 base::Bind(&Predictor::LearnAboutInitialNavigation, |
| 121 base::Unretained(predictor), | 121 base::Unretained(predictor), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 // But also make sure this data has been first loaded into the Predictor, by | 185 // But also make sure this data has been first loaded into the Predictor, by |
| 186 // inspecting that the Predictor starts making the expected hostname requests. | 186 // inspecting that the Predictor starts making the expected hostname requests. |
| 187 PrepareFrameSubresources(referring_url_); | 187 PrepareFrameSubresources(referring_url_); |
| 188 WaitUntilHostHasBeenRequested(startup_url_.host()); | 188 WaitUntilHostHasBeenRequested(startup_url_.host()); |
| 189 WaitUntilHostHasBeenRequested(target_url_.host()); | 189 WaitUntilHostHasBeenRequested(target_url_.host()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace chrome_browser_net | 192 } // namespace chrome_browser_net |
| 193 | 193 |
| OLD | NEW |