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/net/cache_stats.h" | 5 #include "chrome/browser/net/cache_stats.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void CacheStats::ScheduleTimer(TabLoadStats* stats) { | 277 void CacheStats::ScheduleTimer(TabLoadStats* stats) { |
278 int timer_index = stats->next_timer_index; | 278 int timer_index = stats->next_timer_index; |
279 DCHECK(timer_index >= 0 && | 279 DCHECK(timer_index >= 0 && |
280 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); | 280 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); |
281 base::TimeDelta delta = | 281 base::TimeDelta delta = |
282 base::TimeDelta::FromMilliseconds(kStatsCollectionTimesMs[timer_index]); | 282 base::TimeDelta::FromMilliseconds(kStatsCollectionTimesMs[timer_index]); |
283 delta -= base::TimeTicks::Now() - stats->load_start_time; | 283 delta -= base::TimeTicks::Now() - stats->load_start_time; |
| 284 |
| 285 // If the ScheduleTimer call was delayed significantly, like when one's using |
| 286 // a debugger, don't try to start the timer with a negative time. |
| 287 if (delta < base::TimeDelta()) { |
| 288 RemoveTabLoadStats(stats->render_view_id); |
| 289 return; |
| 290 } |
| 291 |
284 stats->timer.Start(FROM_HERE, | 292 stats->timer.Start(FROM_HERE, |
285 delta, | 293 delta, |
286 base::Bind(&CacheStats::TimerCallback, | 294 base::Bind(&CacheStats::TimerCallback, |
287 base::Unretained(this), | 295 base::Unretained(this), |
288 base::Unretained(stats))); | 296 base::Unretained(stats))); |
289 } | 297 } |
290 | 298 |
291 void CacheStats::TimerCallback(TabLoadStats* stats) { | 299 void CacheStats::TimerCallback(TabLoadStats* stats) { |
292 DCHECK(stats->spinner_started); | 300 DCHECK(stats->spinner_started); |
293 base::TimeDelta load_time = base::TimeTicks::Now() - stats->load_start_time; | 301 base::TimeDelta load_time = base::TimeTicks::Now() - stats->load_start_time; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 if (type == ChromeURLRequestContext::CONTEXT_TYPE_MAIN) | 341 if (type == ChromeURLRequestContext::CONTEXT_TYPE_MAIN) |
334 main_request_contexts_.insert(context); | 342 main_request_contexts_.insert(context); |
335 } | 343 } |
336 | 344 |
337 void CacheStats::UnregisterURLRequestContext( | 345 void CacheStats::UnregisterURLRequestContext( |
338 const net::URLRequestContext* context) { | 346 const net::URLRequestContext* context) { |
339 main_request_contexts_.erase(context); | 347 main_request_contexts_.erase(context); |
340 } | 348 } |
341 | 349 |
342 } // namespace chrome_browser_net | 350 } // namespace chrome_browser_net |
OLD | NEW |