This source file includes following definitions.
- OnApplicationStateChange
- RegisterApplicationStatusListener
#include "chrome/browser/metrics/thread_watcher_android.h"
#include "base/android/application_status_listener.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "chrome/browser/metrics/thread_watcher.h"
namespace {
bool g_application_has_stopped = false;
void OnApplicationStateChange(
base::android::ApplicationState application_state) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (application_state ==
base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
g_application_has_stopped = true;
ThreadWatcherList::StopWatchingAll();
} else if (application_state ==
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES &&
g_application_has_stopped) {
g_application_has_stopped = false;
ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess());
}
}
struct LeakyApplicationStatusListenerTraits {
static const bool kRegisterOnExit = false;
#ifndef NDEBUG
static const bool kAllowedToAccessOnNonjoinableThread = true;
#endif
static base::android::ApplicationStatusListener* New(void* instance) {
ANNOTATE_SCOPED_MEMORY_LEAK;
return new (instance) base::android::ApplicationStatusListener(
base::Bind(&OnApplicationStateChange));
}
static void Delete(base::android::ApplicationStatusListener* instance) {
}
};
base::LazyInstance<base::android::ApplicationStatusListener,
LeakyApplicationStatusListenerTraits>
g_application_status_listener = LAZY_INSTANCE_INITIALIZER;
}
void ThreadWatcherAndroid::RegisterApplicationStatusListener() {
g_application_status_listener.Get();
}