Commit 26defffa authored by fukino's avatar fukino Committed by Commit bot

Files app: Handle chrome.runtime.lastError for chrome.storage API calls.

BUG=671080,674434
TEST=manually tested by modifying chrome.storage API to return errors and
confirming that Files app works properly with default options.
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2578863003
Cr-Commit-Position: refs/heads/master@{#438806}
parent ce453d62
...@@ -387,7 +387,11 @@ util.saveAppState = function() { ...@@ -387,7 +387,11 @@ util.saveAppState = function() {
var items = {}; var items = {};
items[window.appID] = JSON.stringify(window.appState); items[window.appID] = JSON.stringify(window.appState);
chrome.storage.local.set(items); chrome.storage.local.set(items, function() {
if (chrome.runtime.lastError)
console.error('Failed to save app state: ' +
chrome.runtime.lastError.message);
});
}; };
/** /**
......
...@@ -35,8 +35,15 @@ function AppStateController(dialogType) { ...@@ -35,8 +35,15 @@ function AppStateController(dialogType) {
*/ */
AppStateController.prototype.loadInitialViewOptions = function() { AppStateController.prototype.loadInitialViewOptions = function() {
// Load initial view option. // Load initial view option.
return new Promise(function(fulfill) { return new Promise(function(fulfill, reject) {
chrome.storage.local.get(this.viewOptionStorageKey_, fulfill); chrome.storage.local.get(this.viewOptionStorageKey_, function(values) {
if (chrome.runtime.lastError) {
reject('Failed to load view options: ' +
chrome.runtime.lastError.message);
} else {
fulfill(values);
}
});
}.bind(this)).then(function(values) { }.bind(this)).then(function(values) {
this.viewOptions_ = {}; this.viewOptions_ = {};
var value = values[this.viewOptionStorageKey_]; var value = values[this.viewOptionStorageKey_];
...@@ -55,6 +62,9 @@ AppStateController.prototype.loadInitialViewOptions = function() { ...@@ -55,6 +62,9 @@ AppStateController.prototype.loadInitialViewOptions = function() {
this.viewOptions_[key] = window.appState.viewOptions[key]; this.viewOptions_[key] = window.appState.viewOptions[key];
} }
} }
}.bind(this)).catch(function(error) {
this.viewOptions_ = {};
console.error(error);
}.bind(this)); }.bind(this));
}; };
...@@ -104,7 +114,11 @@ AppStateController.prototype.saveViewOptions = function() { ...@@ -104,7 +114,11 @@ AppStateController.prototype.saveViewOptions = function() {
// Save the global default. // Save the global default.
var items = {}; var items = {};
items[this.viewOptionStorageKey_] = JSON.stringify(prefs); items[this.viewOptionStorageKey_] = JSON.stringify(prefs);
chrome.storage.local.set(items); chrome.storage.local.set(items, function() {
if (chrome.runtime.lastError)
console.error('Failed to save view options: ' +
chrome.runtime.lastError.message);
});
// Save the window-specific preference. // Save the window-specific preference.
if (window.appState) { if (window.appState) {
......
...@@ -191,6 +191,12 @@ FolderShortcutsDataModel.prototype = { ...@@ -191,6 +191,12 @@ FolderShortcutsDataModel.prototype = {
load_: function() { load_: function() {
this.queue_.run(function(callback) { this.queue_.run(function(callback) {
chrome.storage.sync.get(FolderShortcutsDataModel.NAME, function(value) { chrome.storage.sync.get(FolderShortcutsDataModel.NAME, function(value) {
if (chrome.runtime.lastError) {
console.error('Failed to load shortcut paths from chrome.storage: ' +
chrome.runtime.lastError.message);
callback();
return;
}
var shortcutPaths = value[FolderShortcutsDataModel.NAME] || []; var shortcutPaths = value[FolderShortcutsDataModel.NAME] || [];
// Record metrics. // Record metrics.
......
...@@ -52,6 +52,11 @@ function Banners( ...@@ -52,6 +52,11 @@ function Banners(
DOWNLOADS_WARNING_DISMISSED_KEY DOWNLOADS_WARNING_DISMISSED_KEY
], ],
function(values) { function(values) {
if (chrome.runtime.lastError) {
reject('Failed to load banner data from chrome.storage: ' +
chrome.runtime.lastError.message);
return;
}
this.welcomeHeaderCounter_ = this.welcomeHeaderCounter_ =
parseInt(values[WELCOME_HEADER_COUNTER_KEY], 10) || 0; parseInt(values[WELCOME_HEADER_COUNTER_KEY], 10) || 0;
this.warningDismissedCounter_ = this.warningDismissedCounter_ =
...@@ -75,7 +80,9 @@ function Banners( ...@@ -75,7 +80,9 @@ function Banners(
resolve(); resolve();
}.bind(this)); }.bind(this));
}.bind(this)) }.bind(this))
]); ]).catch(function(error) {
console.error(error);
});
// Authentication failed banner. // Authentication failed banner.
this.authFailedBanner_ = this.authFailedBanner_ =
......
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