| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import org.chromium.base.ObserverList; | 7 import org.chromium.base.ObserverList; |
| 8 import org.chromium.base.ThreadUtils; | 8 import org.chromium.base.ThreadUtils; |
| 9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
| 10 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /** | 21 /** |
| 22 * Observer interface to be implemented by deriving webview lifecycle observ
ers. | 22 * Observer interface to be implemented by deriving webview lifecycle observ
ers. |
| 23 */ | 23 */ |
| 24 public static interface Observer { | 24 public static interface Observer { |
| 25 public void onFirstWebViewCreated(); | 25 public void onFirstWebViewCreated(); |
| 26 public void onLastWebViewDestroyed(); | 26 public void onLastWebViewDestroyed(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 private static final ObserverList<Observer> sLifecycleObservers = | 29 private static final ObserverList<Observer> sLifecycleObservers = |
| 30 new ObserverList<Observer>(); | 30 new ObserverList<Observer>(); |
| 31 private static int sNumWebViews = 0; | 31 private static int sNumWebViews; |
| 32 | 32 |
| 33 private AwContentsLifecycleNotifier() {} | 33 private AwContentsLifecycleNotifier() {} |
| 34 | 34 |
| 35 public static void addObserver(Observer observer) { | 35 public static void addObserver(Observer observer) { |
| 36 sLifecycleObservers.addObserver(observer); | 36 sLifecycleObservers.addObserver(observer); |
| 37 } | 37 } |
| 38 | 38 |
| 39 public static void removeObserver(Observer observer) { | 39 public static void removeObserver(Observer observer) { |
| 40 sLifecycleObservers.removeObserver(observer); | 40 sLifecycleObservers.removeObserver(observer); |
| 41 } | 41 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 65 assert sNumWebViews > 0; | 65 assert sNumWebViews > 0; |
| 66 sNumWebViews--; | 66 sNumWebViews--; |
| 67 if (sNumWebViews == 0) { | 67 if (sNumWebViews == 0) { |
| 68 // last webview destroyed, notify observers. | 68 // last webview destroyed, notify observers. |
| 69 for (Observer observer : sLifecycleObservers) { | 69 for (Observer observer : sLifecycleObservers) { |
| 70 observer.onLastWebViewDestroyed(); | 70 observer.onLastWebViewDestroyed(); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| OLD | NEW |