You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/04/03 08:36:51 UTC

git commit: Adding a safety check to prevent applications from calling init twice Changes to address thread safety concerns in Cordova plugin management

Repository: cordova-amazon-fireos
Updated Branches:
  refs/heads/master 9375b4103 -> 12e9567fe


Adding a safety check to prevent applications from calling init twice
Changes to address thread safety concerns in Cordova plugin management


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/12e9567f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/12e9567f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/12e9567f

Branch: refs/heads/master
Commit: 12e9567fe0412a0a3fb7ca8cea04c996f9f988f6
Parents: 9375b41
Author: Archana Naik <na...@lab126.com>
Authored: Mon Mar 17 15:30:40 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Wed Apr 2 23:36:36 2014 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java |  2 +-
 .../src/org/apache/cordova/PluginManager.java   | 37 +++++++++++---------
 2 files changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/12e9567f/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 6d9dae3..6e8b04a 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -367,7 +367,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      * Create and initialize web container with default web view objects.
      */
     public void init() {
-    	if (factory != null) {
+        if (factory != null && this.appView == null) {
     		CordovaWebView webView = makeWebView();
     		this.init(webView, makeWebViewClient(webView), makeChromeClient(webView));
     	}

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/12e9567f/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java
index a7489c1..69d005f 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -47,7 +47,7 @@ public class PluginManager {
     private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ? 60 : 16;
 
     // List of service entries, sorted by priority
-    private final HashMap<String, PluginEntry> entries = new LinkedHashMap<String, PluginEntry>();
+    private HashMap<String, PluginEntry> entries = new LinkedHashMap<String, PluginEntry>();
 
     private final CordovaInterface ctx;
     private final CordovaWebView app;
@@ -331,25 +331,28 @@ public class PluginManager {
 		List<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(entries.values());
 		pluginEntries.add(entry);
 
-		// clear list and recreate final set entries in priority order
-		entries.clear();
+		// recreate final set entries in priority order
 		this.addServices(pluginEntries);
 	}
 
-	/**
-	 * Takes a list of plugin entries which are first sorted by priority and
-	 * then individually added to the final ordered hashmap. This does not
-	 * create the plugin object instance.
-	 *
-	 * @param services
-	 *            the list of services to sort and add to final entry hash
-	 */
-	private void addServices(List<PluginEntry> services) {
-		Collections.sort(services);
-		for (PluginEntry pluginEntry : services) {
-			this.entries.put(pluginEntry.service, pluginEntry);
-		}
-	}
+    /**
+     * Takes a list of plugin entries which are first sorted by priority and then individually added to the final
+     * ordered hashmap. This does not create the plugin object instance.
+     * 
+     * @param services
+     *            the list of services to sort and add to final entry hash
+     */
+    private void addServices(List<PluginEntry> services) {
+        // sort the list of services by priority
+        Collections.sort(services);
+
+        // create a new map from the prioritized list, and use it as the primary set of entries
+        HashMap<String, PluginEntry> tmpEntries = new LinkedHashMap<String, PluginEntry>();
+        for (PluginEntry pluginEntry : services) {
+            tmpEntries.put(pluginEntry.service, pluginEntry);
+        }
+        this.entries = tmpEntries;
+    }
 
     /**
      * Called when the system is about to start resuming a previous activity.