Commit d01b8399 authored by wajahat.s@samsung.com's avatar wajahat.s@samsung.com

Make DownloadController singleton instance thread safe.

As the cost of creating download controller instance is not
too heavy its better to switch to eager initialization which
creates a ready to use instance and ensures thread safety

This method has a number of advantages:
* The instance is not constructed until the class is used.
* There is no need to synchronize the getInstance() method,
  meaning all threads will see the same instance and no (expensive)
  locking is required.
* The final keyword means that the instance cannot be redefined,
  ensuring that one (and only one) instance ever exists.
(source: http://en.wikipedia.org/wiki/Singleton_pattern#Eager_initialization)

BUG=None.

Review URL: https://codereview.chromium.org/387333002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283430 0039d316-1c4b-4281-b951-d872f2087c98
parent 4c3508f8
......@@ -17,7 +17,7 @@ import org.chromium.base.JNINamespace;
@JNINamespace("content")
public class DownloadController {
private static final String LOGTAG = "DownloadController";
private static DownloadController sInstance;
private static final DownloadController sInstance = new DownloadController();
/**
* Class for notifying the application that download has completed.
......@@ -40,9 +40,6 @@ public class DownloadController {
@CalledByNative
public static DownloadController getInstance() {
if (sInstance == null) {
sInstance = new DownloadController();
}
return sInstance;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment