Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/ssl/ssl_error_classification.cc

Issue 1380483004: Make global variable g_testing_build_time lazily created (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <vector> 5 #include <vector>
6 6
7 #include "chrome/browser/ssl/ssl_error_classification.h" 7 #include "chrome/browser/ssl/ssl_error_classification.h"
8 8
9 #include "base/build_time.h" 9 #include "base/build_time.h"
10 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "components/ssl_errors/error_info.h" 18 #include "components/ssl_errors/error_info.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 kSecondRow[j+1] = std::min(std::min( 111 kSecondRow[j+1] = std::min(std::min(
111 kSecondRow[j] + 1, kFirstRow[j + 1] + 1), kFirstRow[j] + cost); 112 kSecondRow[j] + 1, kFirstRow[j + 1] + 1), kFirstRow[j] + cost);
112 } 113 }
113 for (size_t j = 0; j < kFirstRow.size(); j++) 114 for (size_t j = 0; j < kFirstRow.size(); j++)
114 kFirstRow[j] = kSecondRow[j]; 115 kFirstRow[j] = kSecondRow[j];
115 } 116 }
116 return kSecondRow[str2.size()]; 117 return kSecondRow[str2.size()];
117 } 118 }
118 119
119 // The time to use when doing build time operations in browser tests. 120 // The time to use when doing build time operations in browser tests.
120 base::Time g_testing_build_time; 121 base::LazyInstance<base::Time> g_testing_build_time = LAZY_INSTANCE_INITIALIZER;
Mustafa Acer 2015/09/29 15:44:25 This could also simply be the timestamp in seconds
121 122
122 } // namespace 123 } // namespace
123 124
124 SSLErrorClassification::SSLErrorClassification( 125 SSLErrorClassification::SSLErrorClassification(
125 content::WebContents* web_contents, 126 content::WebContents* web_contents,
126 const base::Time& current_time, 127 const base::Time& current_time,
127 const GURL& url, 128 const GURL& url,
128 int cert_error, 129 int cert_error,
129 const net::X509Certificate& cert) 130 const net::X509Certificate& cert)
130 : web_contents_(web_contents), 131 : web_contents_(web_contents),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 default: 235 default:
235 break; 236 break;
236 } 237 }
237 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type", 238 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type",
238 net::NetworkChangeNotifier::GetConnectionType(), 239 net::NetworkChangeNotifier::GetConnectionType(),
239 net::NetworkChangeNotifier::CONNECTION_LAST); 240 net::NetworkChangeNotifier::CONNECTION_LAST);
240 } 241 }
241 242
242 bool SSLErrorClassification::IsUserClockInThePast(const base::Time& time_now) { 243 bool SSLErrorClassification::IsUserClockInThePast(const base::Time& time_now) {
243 base::Time build_time; 244 base::Time build_time;
244 if (!g_testing_build_time.is_null()) { 245 if (!g_testing_build_time.Get().is_null()) {
245 build_time = g_testing_build_time; 246 build_time = g_testing_build_time.Get();
246 } else { 247 } else {
247 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) 248 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD)
248 return false; 249 return false;
249 #else 250 #else
250 build_time = base::GetBuildTime(); 251 build_time = base::GetBuildTime();
251 #endif 252 #endif
252 } 253 }
253 254
254 if (time_now < build_time - base::TimeDelta::FromDays(2)) 255 if (time_now < build_time - base::TimeDelta::FromDays(2))
255 return true; 256 return true;
256 return false; 257 return false;
257 } 258 }
258 259
259 bool SSLErrorClassification::IsUserClockInTheFuture( 260 bool SSLErrorClassification::IsUserClockInTheFuture(
260 const base::Time& time_now) { 261 const base::Time& time_now) {
261 base::Time build_time; 262 base::Time build_time;
262 if (!g_testing_build_time.is_null()) { 263 if (!g_testing_build_time.Get().is_null()) {
263 build_time = g_testing_build_time; 264 build_time = g_testing_build_time.Get();
264 } else { 265 } else {
265 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) 266 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD)
266 return false; 267 return false;
267 #else 268 #else
268 build_time = base::GetBuildTime(); 269 build_time = base::GetBuildTime();
269 #endif 270 #endif
270 } 271 }
271 272
272 if (time_now > build_time + base::TimeDelta::FromDays(365)) 273 if (time_now > build_time + base::TimeDelta::FromDays(365))
273 return true; 274 return true;
274 return false; 275 return false;
275 } 276 }
276 277
277 // static 278 // static
278 void SSLErrorClassification::SetBuildTimeForTesting( 279 void SSLErrorClassification::SetBuildTimeForTesting(
279 const base::Time& testing_time) { 280 const base::Time& testing_time) {
280 g_testing_build_time = testing_time; 281 g_testing_build_time.Get() = testing_time;
281 } 282 }
282 283
283 bool SSLErrorClassification::MaybeWindowsLacksSHA256Support() { 284 bool SSLErrorClassification::MaybeWindowsLacksSHA256Support() {
284 #if defined(OS_WIN) 285 #if defined(OS_WIN)
285 return !base::win::MaybeHasSHA256Support(); 286 return !base::win::MaybeHasSHA256Support();
286 #else 287 #else
287 return false; 288 return false;
288 #endif 289 #endif
289 } 290 }
290 291
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 // sure we don't clear the captive protal flag, since the interstitial was 546 // sure we don't clear the captive protal flag, since the interstitial was
546 // potentially caused by the captive portal. 547 // potentially caused by the captive portal.
547 captive_portal_detected_ = captive_portal_detected_ || 548 captive_portal_detected_ = captive_portal_detected_ ||
548 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); 549 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
549 // Also keep track of non-HTTP portals and error cases. 550 // Also keep track of non-HTTP portals and error cases.
550 captive_portal_no_response_ = captive_portal_no_response_ || 551 captive_portal_no_response_ = captive_portal_no_response_ ||
551 (results->result == captive_portal::RESULT_NO_RESPONSE); 552 (results->result == captive_portal::RESULT_NO_RESPONSE);
552 } 553 }
553 #endif 554 #endif
554 } 555 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698