Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / chromecast / crash / app_state_tracker.cc
blobb563ece66cdb1c5993fe6ca720881ab07d98eda9
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.
5 #include "chromecast/crash/app_state_tracker.h"
7 #include "base/lazy_instance.h"
8 #include "chromecast/crash/cast_crash_keys.h"
10 namespace {
12 struct CurrentAppState {
13 std::string previous_app;
14 std::string current_app;
15 std::string last_launched_app;
18 base::LazyInstance<CurrentAppState> g_app_state = LAZY_INSTANCE_INITIALIZER;
20 CurrentAppState* GetAppState() {
21 return g_app_state.Pointer();
24 } // namespace
26 namespace chromecast {
28 // static
29 std::string AppStateTracker::GetLastLaunchedApp() {
30 return GetAppState()->last_launched_app;
33 // static
34 std::string AppStateTracker::GetCurrentApp() {
35 return GetAppState()->current_app;
38 // static
39 std::string AppStateTracker::GetPreviousApp() {
40 return GetAppState()->previous_app;
43 // static
44 void AppStateTracker::SetLastLaunchedApp(const std::string& app_id) {
45 GetAppState()->last_launched_app = app_id;
47 // TODO(slan): Currently SetCrashKeyValue is a no-op on chromecast until
48 // we add call to InitCrashKeys
49 base::debug::SetCrashKeyValue(crash_keys::kLastApp, app_id);
52 // static
53 void AppStateTracker::SetCurrentApp(const std::string& app_id) {
54 CurrentAppState* app_state = GetAppState();
55 app_state->previous_app = app_state->current_app;
56 app_state->current_app = app_id;
58 base::debug::SetCrashKeyValue(crash_keys::kCurrentApp, app_id);
59 base::debug::SetCrashKeyValue(crash_keys::kPreviousApp,
60 app_state->previous_app);
63 } // namespace chromecast