Use asyncFetch when loading files in aboutHome.xhtml

RESOLVED FIXED in Firefox 10

Status

Fennec Graveyard
General
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: mfinkle, Assigned: mfinkle)

Tracking

({perf})

Trunk
Firefox 10

Details

(Whiteboard: [mobilestartupshrink][QA?])

Attachments

(1 attachment)

Created attachment 564345 [details] [diff] [review]
patch

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+
Made changes

https://hg.mozilla.org/integration/mozilla-inbound/rev/26d62a2d24cb
https://hg.mozilla.org/mozilla-central/rev/26d62a2d24cb
Status: NEW → RESOLVED
Last Resolved: 6 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)

Updated

6 years ago
Assignee: nobody → mark.finkle

Updated

6 years ago
Attachment #564345 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+

Updated

6 years ago
Depends on: 692767
We should hold off pushing this to Aurora unless bug 692767 is also fixed and approved for Aurora.
status-firefox10: --- → fixed
status-firefox9: --- → affected
Keywords: perf
OS: Linux → All
Hardware: x86 → All
Whiteboard: [mobilestartupshrink]
https://hg.mozilla.org/releases/mozilla-aurora/rev/8b1171944849
status-firefox9: affected → fixed
Target Milestone: Firefox 10 → Firefox 9

Updated

6 years ago
Whiteboard: [mobilestartupshrink] → [mobilestartupshrink][QA?]

Updated

6 years ago
Target Milestone: Firefox 9 → Firefox 10
You need to log in before you can comment on or make changes to this bug.