OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.chrome.browser.ntp.snippets; | 5 package org.chromium.chrome.browser.ntp.snippets; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
| 10 import org.chromium.base.VisibleForTesting; |
10 import org.chromium.chrome.browser.profiles.Profile; | 11 import org.chromium.chrome.browser.profiles.Profile; |
11 import org.chromium.chrome.browser.signin.SigninManager; | 12 import org.chromium.chrome.browser.signin.SigninManager; |
12 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 13 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
13 | 14 |
14 /** | 15 /** |
15 * The main controller for calling into the native snippets component to fetch s
nippets | 16 * The main controller for calling into the native snippets component to fetch s
nippets |
16 */ | 17 */ |
17 public class SnippetsController implements SignInStateObserver { | 18 public class SnippetsController implements SignInStateObserver { |
18 private static SnippetsController sInstance; | 19 private static SnippetsController sInstance; |
19 | 20 |
20 private long mNativeSnippetsController; | 21 private long mNativeSnippetsController; |
21 | 22 |
22 public SnippetsController(Context applicationContext) { | 23 public SnippetsController(Context applicationContext) { |
23 SigninManager.get(applicationContext).addSignInStateObserver(this); | 24 // |applicationContext| can be null in tests. |
| 25 if (applicationContext != null) { |
| 26 SigninManager.get(applicationContext).addSignInStateObserver(this); |
| 27 } |
24 } | 28 } |
25 | 29 |
26 /** | 30 /** |
27 * Fetches new snippets | 31 * Fetches new snippets |
28 * | 32 * |
29 * @param overwrite true if an update to the current snippets should be forc
ed, and false if | 33 * @param overwrite true if an update to the current snippets should be forc
ed, and false if |
30 * snippets should be downloaded only if there are no existing ones. | 34 * snippets should be downloaded only if there are no existing ones. |
31 */ | 35 */ |
32 public void fetchSnippets(boolean overwrite) { | 36 public void fetchSnippets(boolean overwrite) { |
33 nativeFetchSnippets(Profile.getLastUsedProfile(), overwrite); | 37 nativeFetchSnippets(Profile.getLastUsedProfile(), overwrite); |
(...skipping 14 matching lines...) Expand all Loading... |
48 } | 52 } |
49 | 53 |
50 @Override | 54 @Override |
51 public void onSignedIn() { | 55 public void onSignedIn() { |
52 fetchSnippets(true); | 56 fetchSnippets(true); |
53 } | 57 } |
54 | 58 |
55 @Override | 59 @Override |
56 public void onSignedOut() {} | 60 public void onSignedOut() {} |
57 | 61 |
| 62 @VisibleForTesting |
| 63 public static void setInstanceForTesting(SnippetsController instance) { |
| 64 sInstance = instance; |
| 65 } |
| 66 |
58 private native void nativeFetchSnippets(Profile profile, boolean overwrite); | 67 private native void nativeFetchSnippets(Profile profile, boolean overwrite); |
59 } | 68 } |
OLD | NEW |