OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/swap_metrics.h" | 5 #include "chrome/browser/chromeos/swap_metrics.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 | 342 |
343 /////////////////////////////////////////////////////////////////////////////// | 343 /////////////////////////////////////////////////////////////////////////////// |
344 | 344 |
345 SwapMetrics::SwapMetrics() : browser_(NULL) { | 345 SwapMetrics::SwapMetrics() : browser_(NULL) { |
346 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 346 ash::Shell::GetInstance()->AddPreTargetHandler(this); |
347 BrowserList::AddObserver(this); | 347 BrowserList::AddObserver(this); |
348 } | 348 } |
349 | 349 |
350 SwapMetrics::~SwapMetrics() { | 350 SwapMetrics::~SwapMetrics() { |
351 if (backend_) | 351 if (backend_.get()) |
352 backend_->CancelOnUIThread(); | 352 backend_->CancelOnUIThread(); |
353 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 353 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
354 BrowserList::RemoveObserver(this); | 354 BrowserList::RemoveObserver(this); |
355 SetBrowser(NULL); | 355 SetBrowser(NULL); |
356 } | 356 } |
357 | 357 |
358 void SwapMetrics::OnBrowserRemoved(Browser* browser) { | 358 void SwapMetrics::OnBrowserRemoved(Browser* browser) { |
359 if (browser_ == browser) | 359 if (browser_ == browser) |
360 SetBrowser(NULL); | 360 SetBrowser(NULL); |
361 } | 361 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 runner->PostDelayedTask( | 406 runner->PostDelayedTask( |
407 FROM_HERE, | 407 FROM_HERE, |
408 base::Bind(&SwapMetrics::Backend::RecordMetricsOnBlockingPool, | 408 base::Bind(&SwapMetrics::Backend::RecordMetricsOnBlockingPool, |
409 backend, | 409 backend, |
410 time_index), | 410 time_index), |
411 base::TimeDelta::FromMilliseconds(delay_ms)); | 411 base::TimeDelta::FromMilliseconds(delay_ms)); |
412 } | 412 } |
413 | 413 |
414 void SwapMetrics::StartMetricsCollection(const std::string& reason) { | 414 void SwapMetrics::StartMetricsCollection(const std::string& reason) { |
415 // Cancel any existing metrics run. | 415 // Cancel any existing metrics run. |
416 if (backend_) | 416 if (backend_.get()) |
417 backend_->CancelOnUIThread(); | 417 backend_->CancelOnUIThread(); |
418 backend_ = new Backend(reason); | 418 backend_ = new Backend(reason); |
419 PostTaskRecordMetrics(backend_, 0, kMetricsDelayMs[0]); | 419 PostTaskRecordMetrics(backend_, 0, kMetricsDelayMs[0]); |
420 } | 420 } |
421 | 421 |
422 void SwapMetrics::SetBrowser(Browser* browser) { | 422 void SwapMetrics::SetBrowser(Browser* browser) { |
423 if (browser_ == browser) | 423 if (browser_ == browser) |
424 return; | 424 return; |
425 if (browser_) | 425 if (browser_) |
426 browser_->tab_strip_model()->RemoveObserver(this); | 426 browser_->tab_strip_model()->RemoveObserver(this); |
427 browser_ = browser; | 427 browser_ = browser; |
428 if (browser_) | 428 if (browser_) |
429 browser_->tab_strip_model()->AddObserver(this); | 429 browser_->tab_strip_model()->AddObserver(this); |
430 } | 430 } |
431 | 431 |
432 } // namespace chromeos | 432 } // namespace chromeos |
OLD | NEW |