OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 android.content.Context; | 7 import android.content.Context; |
8 import android.os.StrictMode; | 8 import android.os.StrictMode; |
9 | 9 |
10 import org.chromium.android_webview.policy.AwPolicyProvider; | 10 import org.chromium.android_webview.policy.AwPolicyProvider; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 throw new RuntimeException("Cannot initialize WebView", e); | 92 throw new RuntimeException("Cannot initialize WebView", e); |
93 } | 93 } |
94 } | 94 } |
95 }); | 95 }); |
96 } | 96 } |
97 | 97 |
98 private static void tryObtainingDataDirLockOrDie() { | 98 private static void tryObtainingDataDirLockOrDie() { |
99 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 99 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
100 StrictMode.allowThreadDiskWrites(); | 100 StrictMode.allowThreadDiskWrites(); |
101 try { | 101 try { |
102 String dataPath = PathUtils.getDataDirectory(ContextUtils.getApplica
tionContext()); | 102 String dataPath = PathUtils.getDataDirectory(); |
103 File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE); | 103 File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE); |
104 boolean success = false; | 104 boolean success = false; |
105 try { | 105 try { |
106 // Note that the file is not closed intentionally. | 106 // Note that the file is not closed intentionally. |
107 RandomAccessFile file = new RandomAccessFile(lockFile, "rw"); | 107 RandomAccessFile file = new RandomAccessFile(lockFile, "rw"); |
108 sExclusiveFileLock = file.getChannel().tryLock(); | 108 sExclusiveFileLock = file.getChannel().tryLock(); |
109 success = sExclusiveFileLock != null; | 109 success = sExclusiveFileLock != null; |
110 } catch (IOException e) { | 110 } catch (IOException e) { |
111 Log.w(TAG, "Failed to create lock file " + lockFile, e); | 111 Log.w(TAG, "Failed to create lock file " + lockFile, e); |
112 } | 112 } |
113 if (!success) { | 113 if (!success) { |
114 Log.w(TAG, "The app may have another WebView opened in a separat
e process. " | 114 Log.w(TAG, "The app may have another WebView opened in a separat
e process. " |
115 + "This is not recommended and may stop working in futur
e versions."); | 115 + "This is not recommended and may stop working in futur
e versions."); |
116 } | 116 } |
117 } finally { | 117 } finally { |
118 StrictMode.setThreadPolicy(oldPolicy); | 118 StrictMode.setThreadPolicy(oldPolicy); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
OLD | NEW |