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