- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / ApplicationLifetime.java
1 // Copyright (c) 2012 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.
4
5 package org.chromium.chrome.browser;
6
7 import org.chromium.base.CalledByNative;
8
9 /**
10  * Watches for when Chrome is told to restart itself.
11  */
12 public class ApplicationLifetime {
13     public interface Observer {
14         void onTerminate(boolean restart);
15     }
16     private static Observer sObserver = null;
17
18     /**
19      * Sets the observer that monitors for ApplicationLifecycle events.
20      * We only allow one observer to be set to avoid race conditions for shutdown events.
21      */
22     public static void setObserver(Observer observer) {
23         assert sObserver == null;
24         sObserver = observer;
25     }
26
27     /**
28      * Removes whatever observer is currently watching this class.
29      */
30     public static void removeObserver() {
31         sObserver = null;
32     }
33
34     @CalledByNative
35     public static void terminate(boolean restart) {
36         if (sObserver != null)
37             sObserver.onTerminate(restart);
38     }
39 }