OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/metrics/execution_phase.h" | 5 #include "components/metrics/execution_phase.h" |
6 | 6 |
| 7 #include "build/build_config.h" |
7 #include "components/browser_watcher/stability_data_names.h" | 8 #include "components/browser_watcher/stability_data_names.h" |
8 #include "components/browser_watcher/stability_debugging.h" | 9 #include "components/browser_watcher/stability_debugging.h" |
9 #include "components/metrics/metrics_pref_names.h" | 10 #include "components/metrics/metrics_pref_names.h" |
10 #include "components/prefs/pref_registry_simple.h" | 11 #include "components/prefs/pref_registry_simple.h" |
11 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
12 | 13 |
13 namespace metrics { | 14 namespace metrics { |
14 | 15 |
15 ExecutionPhaseManager::ExecutionPhaseManager(PrefService* local_state) | 16 ExecutionPhaseManager::ExecutionPhaseManager(PrefService* local_state) |
16 : local_state_(local_state) {} | 17 : local_state_(local_state) {} |
(...skipping 10 matching lines...) Expand all Loading... |
27 // static | 28 // static |
28 ExecutionPhase ExecutionPhaseManager::execution_phase_ = | 29 ExecutionPhase ExecutionPhaseManager::execution_phase_ = |
29 ExecutionPhase::UNINITIALIZED_PHASE; | 30 ExecutionPhase::UNINITIALIZED_PHASE; |
30 | 31 |
31 void ExecutionPhaseManager::SetExecutionPhase(ExecutionPhase execution_phase) { | 32 void ExecutionPhaseManager::SetExecutionPhase(ExecutionPhase execution_phase) { |
32 DCHECK(execution_phase != ExecutionPhase::START_METRICS_RECORDING || | 33 DCHECK(execution_phase != ExecutionPhase::START_METRICS_RECORDING || |
33 execution_phase_ == ExecutionPhase::UNINITIALIZED_PHASE); | 34 execution_phase_ == ExecutionPhase::UNINITIALIZED_PHASE); |
34 execution_phase_ = execution_phase; | 35 execution_phase_ = execution_phase; |
35 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 36 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
36 static_cast<int>(execution_phase_)); | 37 static_cast<int>(execution_phase_)); |
| 38 #if defined(OS_WIN) |
37 browser_watcher::SetStabilityDataInt( | 39 browser_watcher::SetStabilityDataInt( |
38 browser_watcher::kStabilityExecutionPhase, | 40 browser_watcher::kStabilityExecutionPhase, |
39 static_cast<int>(execution_phase_)); | 41 static_cast<int>(execution_phase_)); |
| 42 #endif // defined(OS_WIN) |
40 } | 43 } |
41 | 44 |
42 ExecutionPhase ExecutionPhaseManager::GetExecutionPhase() { | 45 ExecutionPhase ExecutionPhaseManager::GetExecutionPhase() { |
43 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 46 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
44 // the registry. | 47 // the registry. |
45 return static_cast<ExecutionPhase>( | 48 return static_cast<ExecutionPhase>( |
46 local_state_->GetInteger(prefs::kStabilityExecutionPhase)); | 49 local_state_->GetInteger(prefs::kStabilityExecutionPhase)); |
47 } | 50 } |
48 | 51 |
49 #if defined(OS_ANDROID) || defined(OS_IOS) | 52 #if defined(OS_ANDROID) || defined(OS_IOS) |
50 void ExecutionPhaseManager::OnAppEnterBackground() { | 53 void ExecutionPhaseManager::OnAppEnterBackground() { |
51 // Note: the in-memory ExecutionPhaseManager::execution_phase_ is not updated. | 54 // Note: the in-memory ExecutionPhaseManager::execution_phase_ is not updated. |
52 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 55 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
53 static_cast<int>(ExecutionPhase::SHUTDOWN_COMPLETE)); | 56 static_cast<int>(ExecutionPhase::SHUTDOWN_COMPLETE)); |
54 } | 57 } |
55 | 58 |
56 void ExecutionPhaseManager::OnAppEnterForeground() { | 59 void ExecutionPhaseManager::OnAppEnterForeground() { |
57 // Restore prefs value altered by OnEnterBackground. | 60 // Restore prefs value altered by OnEnterBackground. |
58 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 61 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
59 static_cast<int>(execution_phase_)); | 62 static_cast<int>(execution_phase_)); |
60 } | 63 } |
61 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 64 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
62 | 65 |
63 } // namespace metrics | 66 } // namespace metrics |
OLD | NEW |