Closed Bug 691534 Opened 8 years ago Closed 8 years ago

Use asyncFetch when loading files in aboutHome.xhtml

Categories

(Firefox for Android Graveyard :: General, defect)

defect
Not set

Tracking

(firefox9 fixed, firefox10 fixed)

RESOLVED FIXED
Firefox 10
Tracking Status
firefox9 --- fixed
firefox10 --- fixed

People

(Reporter: mfinkle, Assigned: mfinkle)

References

Details

(Keywords: perf, Whiteboard: [mobilestartupshrink][QA?])

Attachments

(1 file)

Attached patch patchSplinter Review
We are actually using sync file loading in aboutHome.xhtml - CRAZY!

This patch switches us to use asyncFetch to load the JSON data files. The patch also refactors the code to use a single _readFile method.

This should make trying to interact with Fennec easier _right_ after the home page is loaded.
Attachment #564345 - Flags: review?(mbrubeck)
Comment on attachment 564345 [details] [diff] [review]
patch

r=mbrubeck with some minor nits:

>+    function _readFile(aFile, aCallback) {
>       try {

You can probably remove the try/catch

>+        let channel = NetUtil.newChannel(aFile);
>+        channel.contentType = "application/json";
>+        NetUtil.asyncFetch(channel, function(aStream, aResult) {
>+          if (!Components.isSuccessCode(aResult)) {
>+            Cu.reportError("AboutHome: Could not read from " + aFile.leafName);
>+            aCallback(null);
>+            return;
>+          }
> 
>+          let content = NetUtil.readInputStreamToString(aStream, aStream.available()) || "";
>+          aStream.close();
>+
>+          aCallback(content.replace(/\r\n?/g, "\n"));
>+          return;

No need for explicit "return" here.

>+        });
>       }
>       catch (ex) { Cu.reportError(ex); }
> 
>-      return null;
>+      aCallback(null);
>     }

Remove the aCallback(null) here.

>       loadFromCacheOrScheduleUpdate: function(aDelay) {
>+        let self = this;
>         let file = this._getFile();
>         if (file.exists()) {
>+          _readFile(file, function(aContent) {
>+            let json = JSON.parse(aContent);
>+            if (!json || json.addons.length == 0) {
>+              //noRecentTabs();

Remember to remove the commented-out line above.
Attachment #564345 - Flags: review?(mbrubeck) → review+
https://hg.mozilla.org/mozilla-central/rev/26d62a2d24cb
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 10
Comment on attachment 564345 [details] [diff] [review]
patch

Cheap, local fix for reading two data files using async methods. Should reduce the "stall" that can occur after loading the phone page on phones with slow file systems (still looking at you Galaxy S)
Attachment #564345 - Flags: approval-mozilla-aurora?
Assignee: nobody → mark.finkle
Attachment #564345 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Depends on: 692767
We should hold off pushing this to Aurora unless bug 692767 is also fixed and approved for Aurora.
Keywords: perf
OS: Linux → All
Hardware: x86 → All
Whiteboard: [mobilestartupshrink]
Whiteboard: [mobilestartupshrink] → [mobilestartupshrink][QA?]
Target Milestone: Firefox 9 → Firefox 10
You need to log in before you can comment on or make changes to this bug.