OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.net; | |
6 | |
7 import org.chromium.base.ApplicationState; | |
8 import org.chromium.base.ApplicationStatus; | |
9 import org.chromium.base.VisibleForTesting; | |
10 | |
11 /** | |
12 * Regsitration policy which depends on the ApplicationState. | |
13 */ | |
14 public class RegistrationPolicyApplicationStatus | |
15 extends RegistrationPolicy implements ApplicationStatus.ApplicationState Listener { | |
16 private boolean mDestroyed = false; | |
17 | |
18 public RegistrationPolicyApplicationStatus() {} | |
pauljensen
2015/10/01 12:06:37
why do we need a constructor?
timvolodine
2015/10/05 17:26:45
no need, done.
| |
19 | |
20 protected void init(Listener listener) { | |
21 super.init(listener); | |
22 onApplicationStateChange(getApplicationState()); | |
23 ApplicationStatus.registerApplicationStateListener(this); | |
24 } | |
25 | |
26 protected void destroy() { | |
27 if (mDestroyed) return; | |
28 ApplicationStatus.unregisterApplicationStateListener(this); | |
29 mDestroyed = true; | |
30 } | |
31 | |
32 // ApplicationStatus.ApplicationStateListener | |
33 @Override | |
34 public void onApplicationStateChange(int newState) { | |
35 if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) { | |
36 notifyRegister(); | |
37 } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) { | |
38 notifyUnregister(); | |
39 } | |
40 } | |
41 | |
42 /** | |
43 * Returns the activity's status. | |
44 * @return an {@code int} that is one of {@code ApplicationState.HAS_*_ACTIV ITIES}. | |
45 */ | |
46 @VisibleForTesting | |
47 int getApplicationState() { | |
48 return ApplicationStatus.getStateForApplication(); | |
49 } | |
50 } | |
OLD | NEW |