OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/crash/app_state_tracker.h" |
| 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "chromecast/crash/cast_crash_keys.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 struct CurrentAppState { |
| 13 std::string previous_app; |
| 14 std::string current_app; |
| 15 std::string last_launched_app; |
| 16 }; |
| 17 |
| 18 base::LazyInstance<CurrentAppState> g_app_state = LAZY_INSTANCE_INITIALIZER; |
| 19 |
| 20 CurrentAppState* GetAppState() { |
| 21 return g_app_state.Pointer(); |
| 22 } |
| 23 } |
| 24 |
| 25 namespace chromecast { |
| 26 |
| 27 // static |
| 28 std::string AppStateTracker::GetLastLaunchedApp() { |
| 29 return GetAppState()->last_launched_app; |
| 30 } |
| 31 |
| 32 // static |
| 33 std::string AppStateTracker::GetCurrentApp() { |
| 34 return GetAppState()->current_app; |
| 35 } |
| 36 |
| 37 // static |
| 38 std::string AppStateTracker::GetPreviousApp() { |
| 39 return GetAppState()->previous_app; |
| 40 } |
| 41 |
| 42 // static |
| 43 void AppStateTracker::SetLastLaunchedApp(const std::string& app_id) { |
| 44 GetAppState()->last_launched_app = app_id; |
| 45 |
| 46 // TODO(slan): Currently SetCrashKeyValue is a no-op on chromecast until |
| 47 // we add call to InitCrashKeys |
| 48 base::debug::SetCrashKeyValue(crash_keys::kLastApp, app_id); |
| 49 } |
| 50 |
| 51 // static |
| 52 void AppStateTracker::SetCurrentApp(const std::string& app_id) { |
| 53 CurrentAppState* app_state = GetAppState(); |
| 54 app_state->previous_app = app_state->current_app; |
| 55 app_state->current_app = app_id; |
| 56 |
| 57 base::debug::SetCrashKeyValue(crash_keys::kCurrentApp, app_id); |
| 58 base::debug::SetCrashKeyValue(crash_keys::kPreviousApp, |
| 59 app_state->previous_app); |
| 60 } |
| 61 |
| 62 } // namespace chromecast |
OLD | NEW |