Bug 1399039 - Don't initialize GlobalPageMetadata more than once r=sebastian
authorGrigory Kruglov <gkruglov@mozilla.com>
Tue, 12 Sep 2017 20:28:36 -0400
changeset 430116 34b7638b00c8f465b368b53901b1a4597becd653
parent 430115 6c8fd74d8dcf326d0f2c96d45847312ad2725ce6
child 430117 8b156b6abe6137e1d0e0c97f848a7b5d0058530f
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1399039
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1399039 - Don't initialize GlobalPageMetadata more than once r=sebastian MozReview-Commit-ID: 6VqkvDrEc5K
mobile/android/base/java/org/mozilla/gecko/GlobalPageMetadata.java
--- a/mobile/android/base/java/org/mozilla/gecko/GlobalPageMetadata.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GlobalPageMetadata.java
@@ -42,16 +42,18 @@ import java.util.Map;
     private static final String KEY_HAS_IMAGE = "hasImage";
     private static final String KEY_METADATA_JSON = "metadataJSON";
 
     private static final int MAX_METADATA_QUEUE_SIZE = 15;
 
     private final Map<String, GeckoBundle> queuedMetadata =
             Collections.synchronizedMap(new LimitedLinkedHashMap<String, GeckoBundle>());
 
+    private boolean initialized;
+
     public static GlobalPageMetadata getInstance() {
         return instance;
     }
 
     private static class LimitedLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
         private static final long serialVersionUID = 6359725112736360244L;
 
         @Override
@@ -62,19 +64,25 @@ import java.util.Map;
             }
             return false;
         }
     }
 
     private GlobalPageMetadata() {}
 
     public void init() {
+        if (initialized) {
+            return;
+        }
+
         EventDispatcher
                 .getInstance()
                 .registerBackgroundThreadListener(this, GlobalHistory.EVENT_URI_AVAILABLE_IN_HISTORY);
+
+        initialized = true;
     }
 
     public void add(BrowserDB db, ContentProviderClient contentProviderClient, String uri, boolean hasImage, @NonNull String metadataJSON) {
         ThreadUtils.assertOnBackgroundThread();
 
         // NB: Other than checking that JSON is valid and trimming it,
         // we do not process metadataJSON in any way, trusting our source.
         doAddOrQueue(db, contentProviderClient, uri, hasImage, metadataJSON);