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 "chrome/browser/metrics/thread_watcher.h" | 10 #include "chrome/browser/metrics/thread_watcher.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 base::android::ApplicationState application_state) { | 26 base::android::ApplicationState application_state) { |
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
28 if (application_state == | 28 if (application_state == |
29 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) { | 29 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) { |
30 g_application_has_stopped = true; | 30 g_application_has_stopped = true; |
31 ThreadWatcherList::StopWatchingAll(); | 31 ThreadWatcherList::StopWatchingAll(); |
32 } else if (application_state == | 32 } else if (application_state == |
33 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && | 33 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && |
34 g_application_has_stopped) { | 34 g_application_has_stopped) { |
35 g_application_has_stopped = false; | 35 g_application_has_stopped = false; |
36 ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess()); | 36 ThreadWatcherList::StartWatchingAll( |
| 37 *base::CommandLine::ForCurrentProcess()); |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 struct LeakyApplicationStatusListenerTraits { | 41 struct LeakyApplicationStatusListenerTraits { |
41 static const bool kRegisterOnExit = false; | 42 static const bool kRegisterOnExit = false; |
42 #ifndef NDEBUG | 43 #ifndef NDEBUG |
43 static const bool kAllowedToAccessOnNonjoinableThread = true; | 44 static const bool kAllowedToAccessOnNonjoinableThread = true; |
44 #endif | 45 #endif |
45 | 46 |
46 static base::android::ApplicationStatusListener* New(void* instance) { | 47 static base::android::ApplicationStatusListener* New(void* instance) { |
47 ANNOTATE_SCOPED_MEMORY_LEAK; | 48 ANNOTATE_SCOPED_MEMORY_LEAK; |
48 return new (instance) base::android::ApplicationStatusListener( | 49 return new (instance) base::android::ApplicationStatusListener( |
49 base::Bind(&OnApplicationStateChange)); | 50 base::Bind(&OnApplicationStateChange)); |
50 } | 51 } |
51 | 52 |
52 static void Delete(base::android::ApplicationStatusListener* instance) { | 53 static void Delete(base::android::ApplicationStatusListener* instance) { |
53 } | 54 } |
54 }; | 55 }; |
55 | 56 |
56 base::LazyInstance<base::android::ApplicationStatusListener, | 57 base::LazyInstance<base::android::ApplicationStatusListener, |
57 LeakyApplicationStatusListenerTraits> | 58 LeakyApplicationStatusListenerTraits> |
58 g_application_status_listener = LAZY_INSTANCE_INITIALIZER; | 59 g_application_status_listener = LAZY_INSTANCE_INITIALIZER; |
59 | 60 |
60 } // namespace | 61 } // namespace |
61 | 62 |
62 void ThreadWatcherAndroid::RegisterApplicationStatusListener() { | 63 void ThreadWatcherAndroid::RegisterApplicationStatusListener() { |
63 // Leaky. | 64 // Leaky. |
64 g_application_status_listener.Get(); | 65 g_application_status_listener.Get(); |
65 } | 66 } |
OLD | NEW |