| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
| 9 import android.os.Environment; | 9 import android.os.Environment; |
| 10 | 10 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // Start collecting metrics. | 143 // Start collecting metrics. |
| 144 mCronetEngine.getGlobalMetricsDeltas(); | 144 mCronetEngine.getGlobalMetricsDeltas(); |
| 145 break; | 145 break; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * Prepares the path for the test storage (http cache, QUIC server info). | 150 * Prepares the path for the test storage (http cache, QUIC server info). |
| 151 */ | 151 */ |
| 152 public static void prepareTestStorage(Context context) { | 152 public static void prepareTestStorage(Context context) { |
| 153 File storage = new File(getTestStorageDirectory(context)); | 153 File storage = new File(getTestStorageDirectory()); |
| 154 if (storage.exists()) { | 154 if (storage.exists()) { |
| 155 assertTrue(recursiveDelete(storage)); | 155 assertTrue(recursiveDelete(storage)); |
| 156 } | 156 } |
| 157 ensureTestStorageExists(context); | 157 ensureTestStorageExists(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Returns the path for the test storage (http cache, QUIC server info). | 161 * Returns the path for the test storage (http cache, QUIC server info). |
| 162 * NOTE: Does not ensure it exists; tests should use {@link #getTestStorage}
. | 162 * NOTE: Does not ensure it exists; tests should use {@link #getTestStorage}
. |
| 163 */ | 163 */ |
| 164 private static String getTestStorageDirectory(Context context) { | 164 private static String getTestStorageDirectory() { |
| 165 return PathUtils.getDataDirectory(context) + "/test_storage"; | 165 return PathUtils.getDataDirectory() + "/test_storage"; |
| 166 } | 166 } |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Ensures test storage directory exists, i.e. creates one if it does not ex
ist. | 169 * Ensures test storage directory exists, i.e. creates one if it does not ex
ist. |
| 170 */ | 170 */ |
| 171 private static void ensureTestStorageExists(Context context) { | 171 private static void ensureTestStorageExists() { |
| 172 File storage = new File(getTestStorageDirectory(context)); | 172 File storage = new File(getTestStorageDirectory()); |
| 173 if (!storage.exists()) { | 173 if (!storage.exists()) { |
| 174 assertTrue(storage.mkdir()); | 174 assertTrue(storage.mkdir()); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * Returns the path for the test storage (http cache, QUIC server info). | 179 * Returns the path for the test storage (http cache, QUIC server info). |
| 180 * Also ensures it exists. | 180 * Also ensures it exists. |
| 181 */ | 181 */ |
| 182 static String getTestStorage(Context context) { | 182 static String getTestStorage(Context context) { |
| 183 ensureTestStorageExists(context); | 183 ensureTestStorageExists(); |
| 184 return getTestStorageDirectory(context); | 184 return getTestStorageDirectory(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | 187 @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") |
| 188 private static boolean recursiveDelete(File path) { | 188 private static boolean recursiveDelete(File path) { |
| 189 if (path.isDirectory()) { | 189 if (path.isDirectory()) { |
| 190 for (File c : path.listFiles()) { | 190 for (File c : path.listFiles()) { |
| 191 if (!recursiveDelete(c)) { | 191 if (!recursiveDelete(c)) { |
| 192 return false; | 192 return false; |
| 193 } | 193 } |
| 194 } | 194 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 public void stopNetLog() { | 310 public void stopNetLog() { |
| 311 if (mRequestFactory != null) { | 311 if (mRequestFactory != null) { |
| 312 mRequestFactory.stopNetLog(); | 312 mRequestFactory.stopNetLog(); |
| 313 } | 313 } |
| 314 if (mCronetEngine != null) { | 314 if (mCronetEngine != null) { |
| 315 mCronetEngine.stopNetLog(); | 315 mCronetEngine.stopNetLog(); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 } | 318 } |
| OLD | NEW |