| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/metrics/thread_watcher_android.h" | 5 #include "chrome/browser/metrics/thread_watcher_android.h" |
| 6 | 6 |
| 7 #include "base/android/application_status_listener.h" | 7 #include "base/android/application_status_listener.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" |
| 10 #include "chrome/browser/metrics/thread_watcher.h" | 11 #include "chrome/browser/metrics/thread_watcher.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 // For most of the activities, the C++ side is initialized asynchronously | 15 // For most of the activities, the C++ side is initialized asynchronously |
| 15 // and the very first APPLICATION_STATE_HAS_RUNNING_ACTIVITIES is never received | 16 // and the very first APPLICATION_STATE_HAS_RUNNING_ACTIVITIES is never received |
| 16 // whilst the ThreadWatcherList is initiated higher up in the stack. | 17 // whilst the ThreadWatcherList is initiated higher up in the stack. |
| 17 // However, some activities are initialized synchronously, and it'll receive | 18 // However, some activities are initialized synchronously, and it'll receive |
| 18 // an APPLICATION_STATE_HAS_RUNNING_ACTIVITIES here as well. | 19 // an APPLICATION_STATE_HAS_RUNNING_ACTIVITIES here as well. |
| 19 // Protect against this case, and only let | 20 // Protect against this case, and only let |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && | 34 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && |
| 34 g_application_has_stopped) { | 35 g_application_has_stopped) { |
| 35 g_application_has_stopped = false; | 36 g_application_has_stopped = false; |
| 36 ThreadWatcherList::StartWatchingAll( | 37 ThreadWatcherList::StartWatchingAll( |
| 37 *base::CommandLine::ForCurrentProcess()); | 38 *base::CommandLine::ForCurrentProcess()); |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 struct LeakyApplicationStatusListenerTraits { | 42 struct LeakyApplicationStatusListenerTraits { |
| 42 static const bool kRegisterOnExit = false; | 43 static const bool kRegisterOnExit = false; |
| 43 #ifndef NDEBUG | 44 #if DCHECK_IS_ON() |
| 44 static const bool kAllowedToAccessOnNonjoinableThread = true; | 45 static const bool kAllowedToAccessOnNonjoinableThread = true; |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 static base::android::ApplicationStatusListener* New(void* instance) { | 48 static base::android::ApplicationStatusListener* New(void* instance) { |
| 48 ANNOTATE_SCOPED_MEMORY_LEAK; | 49 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 49 return new (instance) base::android::ApplicationStatusListener( | 50 return new (instance) base::android::ApplicationStatusListener( |
| 50 base::Bind(&OnApplicationStateChange)); | 51 base::Bind(&OnApplicationStateChange)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 static void Delete(base::android::ApplicationStatusListener* instance) { | 54 static void Delete(base::android::ApplicationStatusListener* instance) { |
| 54 } | 55 } |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 base::LazyInstance<base::android::ApplicationStatusListener, | 58 base::LazyInstance<base::android::ApplicationStatusListener, |
| 58 LeakyApplicationStatusListenerTraits> | 59 LeakyApplicationStatusListenerTraits> |
| 59 g_application_status_listener = LAZY_INSTANCE_INITIALIZER; | 60 g_application_status_listener = LAZY_INSTANCE_INITIALIZER; |
| 60 | 61 |
| 61 } // namespace | 62 } // namespace |
| 62 | 63 |
| 63 void ThreadWatcherAndroid::RegisterApplicationStatusListener() { | 64 void ThreadWatcherAndroid::RegisterApplicationStatusListener() { |
| 64 // Leaky. | 65 // Leaky. |
| 65 g_application_status_listener.Get(); | 66 g_application_status_listener.Get(); |
| 66 } | 67 } |
| OLD | NEW |