Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc

Issue 98493003: Simplify fileBrowserPrivate.getDriveConnectionStatus(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the util function name. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc
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 690d7619bc3ec11bf753bf5407ad0358a94d137e..8d24e137cc04852d5984df4e757cf09b6be0bca5 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::

Powered by Google App Engine
This is Rietveld 408576698