Skip to content

Commit f9580d5

Browse files
Ben MurdochAndroid (Google) Code Review
authored andcommitted
Merge "Cleanup for bug 5278763"
2 parents c70f6af + 87af731 commit f9580d5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

core/java/android/webkit/CookieSyncManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public static synchronized CookieSyncManager getInstance() {
8888
*/
8989
public static synchronized CookieSyncManager createInstance(
9090
Context context) {
91+
if (context == null) {
92+
throw new IllegalArgumentException("Invalid context argument");
93+
}
94+
9195
JniUtil.setContext(context);
9296
Context appContext = context.getApplicationContext();
9397
if (sRef == null) {

core/java/android/webkit/JniUtil.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,21 @@ private JniUtil() {} // Utility class, do not instantiate.
3939
private static Boolean sUseChromiumHttpStack;
4040
private static Context sContext;
4141

42-
private static boolean initialized = false;
43-
4442
private static void checkInitialized() {
45-
if (!initialized) {
43+
if (sContext == null) {
4644
throw new IllegalStateException("Call CookieSyncManager::createInstance() or create a webview before using this class");
4745
}
4846
}
4947

5048
protected static synchronized void setContext(Context context) {
51-
if (initialized)
49+
if (sContext != null) {
5250
return;
51+
}
5352

5453
sContext = context.getApplicationContext();
55-
initialized = true;
5654
}
5755

5856
protected static synchronized Context getContext() {
59-
if (!initialized)
60-
return null;
6157
return sContext;
6258
}
6359

@@ -68,8 +64,9 @@ protected static synchronized Context getContext() {
6864
private static synchronized String getDatabaseDirectory() {
6965
checkInitialized();
7066

71-
if (sDatabaseDirectory == null)
67+
if (sDatabaseDirectory == null) {
7268
sDatabaseDirectory = sContext.getDatabasePath("dummy").getParent();
69+
}
7370

7471
return sDatabaseDirectory;
7572
}
@@ -81,8 +78,9 @@ private static synchronized String getDatabaseDirectory() {
8178
private static synchronized String getCacheDirectory() {
8279
checkInitialized();
8380

84-
if (sCacheDirectory == null)
81+
if (sCacheDirectory == null) {
8582
sCacheDirectory = sContext.getCacheDir().getAbsolutePath();
83+
}
8684

8785
return sCacheDirectory;
8886
}

core/java/android/webkit/WebView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,10 @@ protected WebView(Context context, AttributeSet attrs, int defStyle,
10551055
super(context, attrs, defStyle);
10561056
checkThread();
10571057

1058+
if (context == null) {
1059+
throw new IllegalArgumentException("Invalid context argument");
1060+
}
1061+
10581062
// Used by the chrome stack to find application paths
10591063
JniUtil.setContext(context);
10601064

0 commit comments

Comments
 (0)