Bug 1321119 - Allow to Sync more tabs and reduce tabs history to 5. r=markh
authorEdouard Oger <eoger@fastmail.com>
Wed, 01 Mar 2017 13:47:20 -0500
changeset 374891 909cf4b977736e76e35339f41aa4a529db0795ca
parent 374890 0bd17b868a31ce1e53b87f7a619974ad8c796f84
child 374892 55d9a513c90e37af3d2fe22de2f01c1797f97b35
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1321119
milestone54.0a1
Bug 1321119 - Allow to Sync more tabs and reduce tabs history to 5. r=markh MozReview-Commit-ID: 7kRg4XQeT4C
services/sync/modules/engines/tabs.js
services/sync/tests/unit/test_tab_store.js
--- a/services/sync/modules/engines/tabs.js
+++ b/services/sync/modules/engines/tabs.js
@@ -2,17 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 this.EXPORTED_SYMBOLS = ["TabEngine", "TabSetRecord"];
 
 var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 const TABS_TTL = 1814400;          // 21 days.
-const TAB_ENTRIES_LIMIT = 25;      // How many URLs to include in tab history.
+const TAB_ENTRIES_LIMIT = 5;      // How many URLs to include in tab history.
 
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/clients.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/constants.js");
@@ -204,21 +204,24 @@ TabStore.prototype = {
     let record = new TabSetRecord(collection, id);
     record.clientName = this.engine.service.clientsEngine.localName;
 
     // Sort tabs in descending-used order to grab the most recently used
     let tabs = this.getAllTabs(true).sort(function(a, b) {
       return b.lastUsed - a.lastUsed;
     });
 
-    // Figure out how many tabs we can pack into a payload. Starting with a 28KB
-    // payload, we can estimate various overheads from encryption/JSON/WBO.
+    // Figure out how many tabs we can pack into a payload.
+    // See bug 535326 comment 8 for an explanation of the estimation
+    // If the server configuration is absent, we use the old max payload size of 28K
     let size = JSON.stringify(tabs).length;
     let origLength = tabs.length;
-    const MAX_TAB_SIZE = 20000;
+    const MAX_TAB_SIZE = (this.engine.service.serverConfiguration ?
+                          this.engine.service.serverConfiguration.max_record_payload_bytes :
+                          28672) / 4 * 3 - 1500;
     if (size > MAX_TAB_SIZE) {
       // Estimate a little more than the direct fraction to maximize packing
       let cutoff = Math.ceil(tabs.length * MAX_TAB_SIZE / size);
       tabs = tabs.slice(0, cutoff + 1);
 
       // Keep dropping off the last entry until the data fits
       while (JSON.stringify(tabs).length > MAX_TAB_SIZE)
         tabs.pop();
--- a/services/sync/tests/unit/test_tab_store.js
+++ b/services/sync/tests/unit/test_tab_store.js
@@ -75,19 +75,19 @@ function test_getAllTabs() {
   }
   allURLs.splice(35, 0, "about:foo", "about:bar", "about:foobar");
 
   store.getWindowEnumerator = mockGetWindowEnumerator.bind(this, "http://bar.com", 1, 1, () => 45, () => allURLs);
   tabs = store.getAllTabs((url) => url.startsWith("about"));
 
   _("Sliced: " + JSON.stringify(tabs));
   equal(tabs.length, 1);
-  equal(tabs[0].urlHistory.length, 25);
+  equal(tabs[0].urlHistory.length, 5);
   equal(tabs[0].urlHistory[0], "http://foo40.bar");
-  equal(tabs[0].urlHistory[24], "http://foo16.bar");
+  equal(tabs[0].urlHistory[4], "http://foo36.bar");
 }
 
 function test_createRecord() {
   let store = getMockStore();
   let record;
 
   store.getTabState = mockGetTabState;
   store.shouldSkipWindow = mockShouldSkipWindow;