Commit 156211a4 authored by haruki@chromium.org's avatar haruki@chromium.org

filemanager: Fix GetDriveConnectionStateFunctionChange to return "offline"...

filemanager: Fix GetDriveConnectionStateFunctionChange to return "offline" when DriveSystemService is unavailable.

Connection-type "offline" is returned with reason "no_service"
Also renamed related variables in JS.

BUG=175522
TEST=Verfify Files app (including "open file", "save file" dialogs) is working if Drive is disblaed, in Incognito window, in Guest mode.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182428 0039d316-1c4b-4281-b951-d872f2087c98
parent 55ae3366
......@@ -122,6 +122,7 @@ const char kDriveConnectionTypeOnline[] = "online";
*/
const char kDriveConnectionReasonNotReady[] = "not_ready";
const char kDriveConnectionReasonNoNetwork[] = "no_network";
const char kDriveConnectionReasonNoService[] = "no_service";
// Unescape rules used for parsing query parameters.
const net::UnescapeRule::Type kUnescapeRuleForQueryParameters =
......@@ -3082,16 +3083,20 @@ bool GetDriveConnectionStateFunction::RunImpl() {
drive::DriveSystemService* system_service =
drive::DriveSystemServiceFactory::GetForProfile(profile_);
bool ready = system_service->drive_service()->CanStartOperation();
bool ready = system_service &&
system_service->drive_service()->CanStartOperation();
bool is_connection_cellular =
net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType());
if (net::NetworkChangeNotifier::IsOffline() || !ready) {
type_string = kDriveConnectionTypeOffline;
if (net::NetworkChangeNotifier::IsOffline())
reasons->AppendString(kDriveConnectionReasonNoNetwork);
if (!ready)
reasons->AppendString(kDriveConnectionReasonNotReady);
if (!system_service)
reasons->AppendString(kDriveConnectionReasonNoService);
} else if (
is_connection_cellular &&
profile_->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular)) {
......
......@@ -126,8 +126,9 @@ var DriveConnectionType = {
* @enum {string}
*/
var DriveConnectionReason = {
NOT_READY: 'not_ready', // Drive is not ready or authentication is failed.
NOT_READY: 'not_ready', // Drive is not ready or authentication is failed.
NO_NETWORK: 'no_network', // Network connection is unavailable.
NO_SERVICE: 'no_service' // Drive service is unavailable.
};
/**
......@@ -1644,8 +1645,8 @@ DialogType.isModal = function(type) {
done();
});
chrome.fileBrowserPrivate.getDriveConnectionState(function(networkState) {
self.networkState_ = networkState;
chrome.fileBrowserPrivate.getDriveConnectionState(function(state) {
self.driveConnectionState_ = state;
done();
});
};
......@@ -1654,13 +1655,13 @@ DialogType.isModal = function(type) {
var self = this;
this.updateNetworkStateAndPreferences_(function() {
var drive = self.preferences_;
var network = self.networkState_;
var connection = self.driveConnectionState_;
self.initDateTimeFormatters_();
self.refreshCurrentDirectoryMetadata_();
self.directoryModel_.setDriveEnabled(self.isDriveEnabled());
self.directoryModel_.setDriveOffline(network.type == 'offline');
self.directoryModel_.setDriveOffline(connection.type == 'offline');
if (drive.cellularDisabled)
self.syncButton.setAttribute('checked', '');
......@@ -1677,7 +1678,7 @@ DialogType.isModal = function(type) {
else
self.hostedButton.removeAttribute('checked');
switch (network.type) {
switch (connection.type) {
case DriveConnectionType.ONLINE:
self.dialogContainer_.removeAttribute('connection');
break;
......@@ -1694,14 +1695,14 @@ DialogType.isModal = function(type) {
};
/**
* Get the metered status of network.
* Get the metered status of Drive connection.
*
* @return {boolean} Returns true if drive should limit the traffic because
* the connection is metered and the 'disable-sync-on-metered' setting is
* enabled. Otherwise, returns false.
*/
FileManager.prototype.isDriveOnMeteredConnection = function() {
return this.networkState_.type == DriveConnectionType.METERED;
return this.driveConnectionState_.type == DriveConnectionType.METERED;
};
/**
......@@ -1711,7 +1712,7 @@ DialogType.isModal = function(type) {
* returns false.
*/
FileManager.prototype.isDriveOffline = function() {
return this.networkState_.type == DriveConnectionType.OFFLINE;
return this.driveConnectionState_.type == DriveConnectionType.OFFLINE;
};
FileManager.prototype.isDriveEnabled = function() {
......
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