Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: base/android/java/src/org/chromium/base/ResourceExtractor.java

Issue 548023002: Migrate ResourceExtractor.java inside org.chromium.base package. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved call site changes in this patch. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.content.browser; 5 package org.chromium.base;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
9 import android.content.pm.PackageInfo; 9 import android.content.pm.PackageInfo;
10 import android.content.pm.PackageManager; 10 import android.content.pm.PackageManager;
11 import android.content.res.AssetManager; 11 import android.content.res.AssetManager;
12 import android.os.AsyncTask; 12 import android.os.AsyncTask;
13 import android.preference.PreferenceManager; 13 import android.preference.PreferenceManager;
14 import android.util.Log; 14 import android.util.Log;
15 15
16 import org.chromium.base.PathUtils;
17 import org.chromium.ui.base.LocalizationUtils;
18
19 import java.io.File; 16 import java.io.File;
20 import java.io.FileOutputStream; 17 import java.io.FileOutputStream;
21 import java.io.FilenameFilter; 18 import java.io.FilenameFilter;
22 import java.io.IOException; 19 import java.io.IOException;
23 import java.io.InputStream; 20 import java.io.InputStream;
24 import java.io.OutputStream; 21 import java.io.OutputStream;
22 import java.util.ArrayList;
25 import java.util.HashSet; 23 import java.util.HashSet;
24 import java.util.List;
26 import java.util.concurrent.CancellationException; 25 import java.util.concurrent.CancellationException;
27 import java.util.concurrent.ExecutionException; 26 import java.util.concurrent.ExecutionException;
28 import java.util.regex.Pattern; 27 import java.util.regex.Pattern;
29 28
30 /** 29 /**
31 * Handles extracting the necessary resources bundled in an APK and moving them to a location on 30 * Handles extracting the necessary resources bundled in an APK and moving them to a location on
32 * the file system accessible from the native code. 31 * the file system accessible from the native code.
33 */ 32 */
34 public class ResourceExtractor { 33 public class ResourceExtractor {
35 34
(...skipping 24 matching lines...) Expand all
60 } 59 }
61 60
62 String timestampFile = checkPakTimestamp(outputDir); 61 String timestampFile = checkPakTimestamp(outputDir);
63 if (timestampFile != null) { 62 if (timestampFile != null) {
64 deleteFiles(); 63 deleteFiles();
65 } 64 }
66 65
67 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(mContext); 66 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(mContext);
68 HashSet<String> filenames = (HashSet<String>) prefs.getStringSet( 67 HashSet<String> filenames = (HashSet<String>) prefs.getStringSet(
69 PAK_FILENAMES, new HashSet<String>()); 68 PAK_FILENAMES, new HashSet<String>());
70 String currentLocale = LocalizationUtils.getDefaultLocale(); 69 String currentLocale = LocaleUtils.getDefaultLocale();
71 String currentLanguage = currentLocale.split("-", 2)[0]; 70 String currentLanguage = currentLocale.split("-", 2)[0];
72 71
73 if (prefs.getString(LAST_LANGUAGE, "").equals(currentLanguage) 72 if (prefs.getString(LAST_LANGUAGE, "").equals(currentLanguage)
74 && filenames.size() >= sMandatoryPaks.length) { 73 && filenames.size() >= sMandatoryPaks.length) {
75 boolean filesPresent = true; 74 boolean filesPresent = true;
76 for (String file : filenames) { 75 for (String file : filenames) {
77 if (!new File(outputDir, file).exists()) { 76 if (!new File(outputDir, file).exists()) {
78 filesPresent = false; 77 filesPresent = false;
79 break; 78 break;
80 } 79 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 255 }
257 256
258 /** 257 /**
259 * By default the ResourceExtractor will attempt to extract a pak resource f or the users 258 * By default the ResourceExtractor will attempt to extract a pak resource f or the users
260 * currently specified locale. This behavior can be changed with this functi on and is 259 * currently specified locale. This behavior can be changed with this functi on and is
261 * only needed by tests. 260 * only needed by tests.
262 * @param extract False if we should not attempt to extract a pak file for 261 * @param extract False if we should not attempt to extract a pak file for
263 * the users currently selected locale and try to extract only the 262 * the users currently selected locale and try to extract only the
264 * pak files specified in sMandatoryPaks. 263 * pak files specified in sMandatoryPaks.
265 */ 264 */
265 @VisibleForTesting
266 public static void setExtractImplicitLocaleForTesting(boolean extract) { 266 public static void setExtractImplicitLocaleForTesting(boolean extract) {
267 assert (sInstance == null || sInstance.mExtractTask == null) 267 assert (sInstance == null || sInstance.mExtractTask == null)
268 : "Must be called before startExtractingResources is called"; 268 : "Must be called before startExtractingResources is called";
269 sExtractImplicitLocalePak = extract; 269 sExtractImplicitLocalePak = extract;
270 } 270 }
271 271
272 /**
273 * Collect all the 'pak' resources, packaged as assets, for extraction durin g
274 * running the tests.
275 */
276 @VisibleForTesting
277 public void collectAllPackagedPakAssets() {
Ted C 2014/09/09 17:51:00 I think calling this as: setExtractAllPaksForTest
vivekg 2014/09/09 18:01:31 Sure, how about just having extractAllPaksForTesti
Ted C 2014/09/09 18:36:19 It is not actually extracting anything though, so
vivekg 2014/09/09 18:46:32 Your initial proposal of having the name as 'setEx
278 List<String> pakFileAssets = new ArrayList<String>();
279 AssetManager manager = mContext.getResources().getAssets();
280 try {
281 String[] files = manager.list("");
282 for (String file : files) {
283 if (file.endsWith(".pak"))
284 pakFileAssets.add(file);
Ted C 2014/09/09 17:51:00 braces are always required in java. You can put s
vivekg 2014/09/09 18:01:31 Sure, will change. Thank you.
285 }
286 } catch (IOException e) {
287 Log.w(LOGTAG, "Exception while accessing assets: " + e.getMessage()) ;
Ted C 2014/09/09 17:51:00 Use this version instead that takes the exception
vivekg 2014/09/09 18:01:31 Sure.
288 }
289 setMandatoryPaksToExtract(pakFileAssets.toArray(new String[pakFileAssets .size()]));
290 }
291
272 private ResourceExtractor(Context context) { 292 private ResourceExtractor(Context context) {
273 mContext = context.getApplicationContext(); 293 mContext = context.getApplicationContext();
274 } 294 }
275 295
276 public void waitForCompletion() { 296 public void waitForCompletion() {
277 if (shouldSkipPakExtraction()) { 297 if (shouldSkipPakExtraction()) {
278 return; 298 return;
279 } 299 }
280 300
281 assert mExtractTask != null; 301 assert mExtractTask != null;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 /** 364 /**
345 * Pak extraction not necessarily required by the embedder; we allow them to skip 365 * Pak extraction not necessarily required by the embedder; we allow them to skip
346 * this process if they call setMandatoryPaksToExtract with a single empty S tring. 366 * this process if they call setMandatoryPaksToExtract with a single empty S tring.
347 */ 367 */
348 private static boolean shouldSkipPakExtraction() { 368 private static boolean shouldSkipPakExtraction() {
349 // Must call setMandatoryPaksToExtract before beginning resource extract ion. 369 // Must call setMandatoryPaksToExtract before beginning resource extract ion.
350 assert sMandatoryPaks != null; 370 assert sMandatoryPaks != null;
351 return sMandatoryPaks.length == 1 && "".equals(sMandatoryPaks[0]); 371 return sMandatoryPaks.length == 1 && "".equals(sMandatoryPaks[0]);
352 } 372 }
353 } 373 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698