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 "chrome/browser/intranet_redirect_detector.h" | 5 #include "chrome/browser/intranet_redirect_detector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 std::string()); | 59 std::string()); |
60 } | 60 } |
61 | 61 |
62 void IntranetRedirectDetector::FinishSleep() { | 62 void IntranetRedirectDetector::FinishSleep() { |
63 in_sleep_ = false; | 63 in_sleep_ = false; |
64 | 64 |
65 // If another fetch operation is still running, cancel it. | 65 // If another fetch operation is still running, cancel it. |
66 STLDeleteElements(&fetchers_); | 66 STLDeleteElements(&fetchers_); |
67 resulting_origins_.clear(); | 67 resulting_origins_.clear(); |
68 | 68 |
69 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 69 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
70 if (cmd_line->HasSwitch(switches::kDisableBackgroundNetworking)) | 70 if (cmd_line->HasSwitch(switches::kDisableBackgroundNetworking)) |
71 return; | 71 return; |
72 | 72 |
73 DCHECK(fetchers_.empty() && resulting_origins_.empty()); | 73 DCHECK(fetchers_.empty() && resulting_origins_.empty()); |
74 | 74 |
75 // Start three fetchers on random hostnames. | 75 // Start three fetchers on random hostnames. |
76 for (size_t i = 0; i < 3; ++i) { | 76 for (size_t i = 0; i < 3; ++i) { |
77 std::string url_string("http://"); | 77 std::string url_string("http://"); |
78 // We generate a random hostname with between 7 and 15 characters. | 78 // We generate a random hostname with between 7 and 15 characters. |
79 const int num_chars = base::RandInt(7, 15); | 79 const int num_chars = base::RandInt(7, 15); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 // Since presumably many programs open connections after network changes, | 156 // Since presumably many programs open connections after network changes, |
157 // delay this a little bit. | 157 // delay this a little bit. |
158 in_sleep_ = true; | 158 in_sleep_ = true; |
159 static const int kNetworkSwitchDelayMS = 1000; | 159 static const int kNetworkSwitchDelayMS = 1000; |
160 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 160 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
161 base::Bind(&IntranetRedirectDetector::FinishSleep, | 161 base::Bind(&IntranetRedirectDetector::FinishSleep, |
162 weak_ptr_factory_.GetWeakPtr()), | 162 weak_ptr_factory_.GetWeakPtr()), |
163 base::TimeDelta::FromMilliseconds(kNetworkSwitchDelayMS)); | 163 base::TimeDelta::FromMilliseconds(kNetworkSwitchDelayMS)); |
164 } | 164 } |
OLD | NEW |