diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 07:38:30 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 07:38:30 +0000 |
commit | 79a66c5e94b8930a52d90ef7904c9486e9048687 (patch) | |
tree | 1a88120782f1ceec690339c7001f24f7e7d6b470 | |
parent | 3c53f86574789c7c7518f4213d210e6d2b87e566 (diff) | |
download | chromium_src-79a66c5e94b8930a52d90ef7904c9486e9048687.zip chromium_src-79a66c5e94b8930a52d90ef7904c9486e9048687.tar.gz chromium_src-79a66c5e94b8930a52d90ef7904c9486e9048687.tar.bz2 |
Simplify fileBrowserPrivate.getDriveConnectionStatus().
The "reasons" field had been a subset of {NO_SERVICE, NO_NETWORK, NOT_READY},
but it is now used only for signaling errors when it has NOT_READY
without other reasons. This can more simply be represented
by a single "reason" field whose value is set in the order:
NO_SERVICE > NO_NETWORK > NOT_READY, i.e., NOT_READY is set
only when other two states are not set.
BUG=237427
R=benwells@chromium.org, yoshiki@chromium.org
Review URL: https://codereview.chromium.org/98493003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238318 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 70 insertions, 37 deletions
diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc index f22fccb..29ee8ac 100644 --- a/chrome/browser/chromeos/drive/file_system_util.cc +++ b/chrome/browser/chromeos/drive/file_system_util.cc @@ -389,5 +389,27 @@ bool IsDriveEnabledForProfile(Profile* profile) { return true; } +ConnectionStatusType GetDriveConnectionStatus(Profile* profile) { + drive::DriveServiceInterface* const drive_service = + drive::util::GetDriveServiceByProfile(profile); + + if (!drive_service) + return DRIVE_DISCONNECTED_NOSERVICE; + if (net::NetworkChangeNotifier::IsOffline()) + return DRIVE_DISCONNECTED_NONETWORK; + if (!drive_service->CanSendRequest()) + return DRIVE_DISCONNECTED_NOTREADY; + + const bool is_connection_cellular = + net::NetworkChangeNotifier::IsConnectionCellular( + net::NetworkChangeNotifier::GetConnectionType()); + const bool disable_sync_over_celluar = + profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); + + if (is_connection_cellular && disable_sync_over_celluar) + return DRIVE_CONNECTED_METERED; + return DRIVE_CONNECTED; +} + } // namespace util } // namespace drive diff --git a/chrome/browser/chromeos/drive/file_system_util.h b/chrome/browser/chromeos/drive/file_system_util.h index 96029f8..7766f0c 100644 --- a/chrome/browser/chromeos/drive/file_system_util.h +++ b/chrome/browser/chromeos/drive/file_system_util.h @@ -204,6 +204,25 @@ std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path); // Returns true if Drive is enabled for the given Profile. bool IsDriveEnabledForProfile(Profile* profile); +// Enum type for describing the current connection status to Drive. +enum ConnectionStatusType { + // Disconnected because Drive service is unavailable for this account (either + // disabled by a flag or the account has no Google account (e.g., guests)). + DRIVE_DISCONNECTED_NOSERVICE, + // Disconnected because no network is available. + DRIVE_DISCONNECTED_NONETWORK, + // Disconnected because authentication is not ready. + DRIVE_DISCONNECTED_NOTREADY, + // Connected by cellular network. Background sync is disabled. + DRIVE_CONNECTED_METERED, + // Connected without condition (WiFi, Ethernet, or cellular with the + // disable-sync preference turned off.) + DRIVE_CONNECTED, +}; + +// Returns the Drive connection status for the |profile|. +ConnectionStatusType GetDriveConnectionStatus(Profile* profile); + } // namespace util } // namespace drive diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc index 690d761..8d24e13 100644 --- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc @@ -28,13 +28,13 @@ namespace extensions { namespace { // List of connection types of drive. -// Keep this in sync with the DriveConnectionType in volume_manager.js. +// Keep this in sync with the DriveConnectionType in common/js/util.js. const char kDriveConnectionTypeOffline[] = "offline"; const char kDriveConnectionTypeMetered[] = "metered"; const char kDriveConnectionTypeOnline[] = "online"; // List of reasons of kDriveConnectionType*. -// Keep this in sync with the DriveConnectionReason in volume_manager.js. +// Keep this in sync with the DriveConnectionReason in common/js/util.js. const char kDriveConnectionReasonNotReady[] = "not_ready"; const char kDriveConnectionReasonNoNetwork[] = "no_network"; const char kDriveConnectionReasonNoService[] = "no_service"; @@ -510,31 +510,27 @@ void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( } bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { - drive::DriveServiceInterface* const drive_service = - drive::util::GetDriveServiceByProfile(GetProfile()); - api::file_browser_private::GetDriveConnectionState::Results::Result result; - const bool ready = drive_service && drive_service->CanSendRequest(); - const bool is_connection_cellular = - net::NetworkChangeNotifier::IsConnectionCellular( - net::NetworkChangeNotifier::GetConnectionType()); - - if (net::NetworkChangeNotifier::IsOffline() || !ready) { - result.type = kDriveConnectionTypeOffline; - if (net::NetworkChangeNotifier::IsOffline()) - result.reasons.push_back(kDriveConnectionReasonNoNetwork); - if (!ready) - result.reasons.push_back(kDriveConnectionReasonNotReady); - if (!drive_service) - result.reasons.push_back(kDriveConnectionReasonNoService); - } else if ( - is_connection_cellular && - GetProfile()->GetPrefs()->GetBoolean( - prefs::kDisableDriveOverCellular)) { - result.type = kDriveConnectionTypeMetered; - } else { - result.type = kDriveConnectionTypeOnline; + switch (drive::util::GetDriveConnectionStatus(GetProfile())) { + case drive::util::DRIVE_DISCONNECTED_NOSERVICE: + result.type = kDriveConnectionTypeOffline; + result.reason.reset(new std::string(kDriveConnectionReasonNoService)); + break; + case drive::util::DRIVE_DISCONNECTED_NONETWORK: + result.type = kDriveConnectionTypeOffline; + result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork)); + break; + case drive::util::DRIVE_DISCONNECTED_NOTREADY: + result.type = kDriveConnectionTypeOffline; + result.reason.reset(new std::string(kDriveConnectionReasonNotReady)); + break; + case drive::util::DRIVE_CONNECTED_METERED: + result.type = kDriveConnectionTypeMetered; + break; + case drive::util::DRIVE_CONNECTED: + result.type = kDriveConnectionTypeOnline; + break; } results_ = api::file_browser_private::GetDriveConnectionState::Results:: diff --git a/chrome/browser/resources/file_manager/background/js/volume_manager.js b/chrome/browser/resources/file_manager/background/js/volume_manager.js index 25aa44e..8ad56ae 100644 --- a/chrome/browser/resources/file_manager/background/js/volume_manager.js +++ b/chrome/browser/resources/file_manager/background/js/volume_manager.js @@ -333,7 +333,7 @@ function VolumeManager() { // TODO(hidehiko): Remove them after the migration. this.driveConnectionState_ = { type: util.DriveConnectionType.OFFLINE, - reasons: [util.DriveConnectionReason.NO_SERVICE] + reason: util.DriveConnectionReason.NO_SERVICE }; chrome.fileBrowserPrivate.onDriveConnectionStatusChanged.addListener( diff --git a/chrome/browser/resources/file_manager/common/js/util.js b/chrome/browser/resources/file_manager/common/js/util.js index 5679a5a..93808ee 100644 --- a/chrome/browser/resources/file_manager/common/js/util.js +++ b/chrome/browser/resources/file_manager/common/js/util.js @@ -1186,7 +1186,7 @@ util.VolumeError = Object.freeze({ * List of connection types of drive. * * Keep this in sync with the kDriveConnectionType* constants in - * file_browser_private_api.cc. + * private_api_dirve.cc. * * @enum {string} * @const @@ -1201,7 +1201,7 @@ util.DriveConnectionType = Object.freeze({ * List of reasons of DriveConnectionType. * * Keep this in sync with the kDriveConnectionReason constants in - * file_browser_private_api.cc. + * private_api_drive.cc. * * @enum {string} * @const diff --git a/chrome/browser/resources/file_manager/foreground/js/drive_banners.js b/chrome/browser/resources/file_manager/foreground/js/drive_banners.js index 9149bef..25692c8 100644 --- a/chrome/browser/resources/file_manager/foreground/js/drive_banners.js +++ b/chrome/browser/resources/file_manager/foreground/js/drive_banners.js @@ -653,13 +653,9 @@ FileListBannerController.prototype.updateDriveUnmountedPanel_ = function() { */ FileListBannerController.prototype.maybeShowAuthFailBanner_ = function() { var connection = this.volumeManager_.getDriveConnectionState(); - var reasons = connection.reasons; var showDriveNotReachedMessage = this.isOnCurrentProfileDrive() && connection.type == util.DriveConnectionType.OFFLINE && - // Show the banner only when authentication fails. Don't show it when the - // drive service is disabled. - reasons.indexOf(util.DriveConnectionReason.NOT_READY) != -1 && - reasons.indexOf(util.DriveConnectionReason.NO_SERVICE) == -1; + connection.reason == util.DriveConnectionReason.NOT_READY; this.authFailedBanner_.hidden = !showDriveNotReachedMessage; }; diff --git a/chrome/browser/resources/file_manager/foreground/js/volume_manager_wrapper.js b/chrome/browser/resources/file_manager/foreground/js/volume_manager_wrapper.js index 41dfe11..411723d 100644 --- a/chrome/browser/resources/file_manager/foreground/js/volume_manager_wrapper.js +++ b/chrome/browser/resources/file_manager/foreground/js/volume_manager_wrapper.js @@ -205,7 +205,7 @@ VolumeManagerWrapper.prototype.getDriveConnectionState = function() { if (!this.driveEnabled_ || !this.volumeManager_) { return { type: util.DriveConnectionType.OFFLINE, - reasons: [util.DriveConnectionReason.NO_SERVICE] + reason: util.DriveConnectionReason.NO_SERVICE }; } diff --git a/chrome/common/extensions/api/file_browser_private.json b/chrome/common/extensions/api/file_browser_private.json index 19875e8..f548c06 100644 --- a/chrome/common/extensions/api/file_browser_private.json +++ b/chrome/common/extensions/api/file_browser_private.json @@ -947,10 +947,10 @@ "type": "object", "properties": { "type": {"type": "string"}, - "reasons": { - "type": "array", + "reason": { + "type": "string", "description": "Reasons of offline.", - "items": { "type": "string" } + "optional": true } } } |