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

Unified Diff: chrome/browser/chromeos/gdata/drive_system_service.cc

Issue 11094061: drive: Move IsDriveEnabled() and DisableDrive() to DriveSystemService (Closed) Base URL: http://git.chromium.org/chromium/src.git@drive_available
Patch Set: rebase Created 8 years, 2 months 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/gdata/drive_system_service.cc
diff --git a/chrome/browser/chromeos/gdata/drive_system_service.cc b/chrome/browser/chromeos/gdata/drive_system_service.cc
index 03bd41b01de898f0b054f83559bd6efd577402b6..033f8b897461a534c5e82649baedb57777349842 100644
--- a/chrome/browser/chromeos/gdata/drive_system_service.cc
+++ b/chrome/browser/chromeos/gdata/drive_system_service.cc
@@ -41,6 +41,9 @@ namespace {
DriveServiceInterface* g_test_drive_service = NULL;
const std::string* g_test_cache_root = NULL;
+// Map to collect profiles with Drive disabled.
+std::map<Profile*, bool>* g_drive_disabled_map = NULL;
+
} // namespace
DriveSystemService::DriveSystemService(Profile* profile)
@@ -104,6 +107,25 @@ void DriveSystemService::Shutdown() {
drive_service_.reset();
}
+// static
+bool DriveSystemService::IsDriveEnabled(Profile* profile) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (!AuthService::CanAuthenticate(profile))
+ return false;
+
+ // Disable gdata if preference is set. This can happen with commandline flag
+ // --disable-gdata or enterprise policy, or probably with user settings too
+ // in the future.
+ if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData))
+ return false;
+
+ if (g_drive_disabled_map && g_drive_disabled_map->count(profile) > 0)
+ return false;
+
+ return true;
+}
+
void DriveSystemService::ClearCacheAndRemountFileSystem(
const base::Callback<void(bool)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -130,7 +152,7 @@ void DriveSystemService::AddBackDriveMountPoint(
}
void DriveSystemService::AddDriveMountPoint() {
- if (!gdata::util::IsDriveEnabled(profile_))
+ if (!IsDriveEnabled(profile_))
return;
const FilePath mount_point = gdata::util::GetDriveMountPointPath();
@@ -163,7 +185,7 @@ void DriveSystemService::OnCacheInitialized(bool success) {
if (!success) {
LOG(WARNING) << "Failed to initialize the cache. Disabling Drive";
- gdata::util::DisableDrive(profile_);
+ DisableDrive(profile_);
// Change the download directory to the default value if the download
// destination is set to under Drive mount point.
//
@@ -190,6 +212,19 @@ void DriveSystemService::OnCacheInitialized(bool success) {
AddDriveMountPoint();
}
+// static
+void DriveSystemService::DisableDrive(Profile* profile) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // We don't change kDisableGData preference here. If we do, we'll end up
+ // disabling Drive on other devices, as kDisableGData is a syncable
+ // preference. Hence the map is used here.
+ if (!g_drive_disabled_map)
+ g_drive_disabled_map = new std::map<Profile*, bool>;
+
+ g_drive_disabled_map->insert(std::make_pair(profile, true));
+}
+
//===================== DriveSystemServiceFactory =============================
// static

Powered by Google App Engine
This is Rietveld 408576698