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

Side by Side 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: address comments 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/drive_system_service.h" 5 #include "chrome/browser/chromeos/gdata/drive_system_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/gdata/drive_api_service.h" 9 #include "chrome/browser/chromeos/gdata/drive_api_service.h"
10 #include "chrome/browser/chromeos/gdata/drive_download_observer.h" 10 #include "chrome/browser/chromeos/gdata/drive_download_observer.h"
(...skipping 23 matching lines...) Expand all
34 using content::BrowserContext; 34 using content::BrowserContext;
35 using content::BrowserThread; 35 using content::BrowserThread;
36 36
37 namespace gdata { 37 namespace gdata {
38 namespace { 38 namespace {
39 39
40 // Used in test to setup system service. 40 // Used in test to setup system service.
41 DriveServiceInterface* g_test_drive_service = NULL; 41 DriveServiceInterface* g_test_drive_service = NULL;
42 const std::string* g_test_cache_root = NULL; 42 const std::string* g_test_cache_root = NULL;
43 43
44 // Map to collect profiles with Drive disabled.
45 std::map<Profile*, bool>* g_drive_disabled_map = NULL;
46
47 // Disables Drive for the specified profile. Used to disable Drive when
48 // needed (ex. initialization of the Drive cache failed).
49 // Must be called on UI thread.
50 void DisableDrive(Profile* profile) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52
53 // We don't change kDisableGData preference here. If we do, we'll end up
54 // disabling Drive on other devices, as kDisableGData is a syncable
55 // preference. Hence the map is used here.
56 if (!g_drive_disabled_map)
57 g_drive_disabled_map = new std::map<Profile*, bool>;
58
59 g_drive_disabled_map->insert(std::make_pair(profile, true));
60 }
61
44 } // namespace 62 } // namespace
45 63
46 DriveSystemService::DriveSystemService(Profile* profile) 64 DriveSystemService::DriveSystemService(Profile* profile)
47 : profile_(profile), 65 : profile_(profile),
48 cache_(NULL), 66 cache_(NULL),
49 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); 69 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
52 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( 70 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
53 blocking_pool->GetSequenceToken()); 71 blocking_pool->GetSequenceToken());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 stale_cache_files_remover_.reset(); 115 stale_cache_files_remover_.reset();
98 sync_client_.reset(); 116 sync_client_.reset();
99 download_observer_.reset(); 117 download_observer_.reset();
100 file_write_helper_.reset(); 118 file_write_helper_.reset();
101 file_system_.reset(); 119 file_system_.reset();
102 webapps_registry_.reset(); 120 webapps_registry_.reset();
103 uploader_.reset(); 121 uploader_.reset();
104 drive_service_.reset(); 122 drive_service_.reset();
105 } 123 }
106 124
125 // static
126 bool DriveSystemService::IsDriveEnabled(Profile* profile) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128
129 if (!AuthService::CanAuthenticate(profile))
130 return false;
131
132 // Disable gdata if preference is set. This can happen with commandline flag
133 // --disable-gdata or enterprise policy, or probably with user settings too
134 // in the future.
135 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData))
136 return false;
137
138 if (g_drive_disabled_map && g_drive_disabled_map->count(profile) > 0)
139 return false;
140
141 return true;
142 }
143
107 void DriveSystemService::ClearCacheAndRemountFileSystem( 144 void DriveSystemService::ClearCacheAndRemountFileSystem(
108 const base::Callback<void(bool)>& callback) { 145 const base::Callback<void(bool)>& callback) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 147
111 RemoveDriveMountPoint(); 148 RemoveDriveMountPoint();
112 drive_service()->CancelAll(); 149 drive_service()->CancelAll();
113 cache_->ClearAllOnUIThread( 150 cache_->ClearAllOnUIThread(
114 base::Bind(&DriveSystemService::AddBackDriveMountPoint, 151 base::Bind(&DriveSystemService::AddBackDriveMountPoint,
115 weak_ptr_factory_.GetWeakPtr(), 152 weak_ptr_factory_.GetWeakPtr(),
116 callback)); 153 callback));
117 } 154 }
118 155
119 void DriveSystemService::AddBackDriveMountPoint( 156 void DriveSystemService::AddBackDriveMountPoint(
120 const base::Callback<void(bool)>& callback, 157 const base::Callback<void(bool)>& callback,
121 DriveFileError error, 158 DriveFileError error,
122 const FilePath& file_path) { 159 const FilePath& file_path) {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
124 161
125 file_system_->Initialize(); 162 file_system_->Initialize();
126 AddDriveMountPoint(); 163 AddDriveMountPoint();
127 164
128 if (!callback.is_null()) 165 if (!callback.is_null())
129 callback.Run(error == DRIVE_FILE_OK); 166 callback.Run(error == DRIVE_FILE_OK);
130 } 167 }
131 168
132 void DriveSystemService::AddDriveMountPoint() { 169 void DriveSystemService::AddDriveMountPoint() {
133 if (!gdata::util::IsDriveEnabled(profile_)) 170 if (!IsDriveEnabled(profile_))
134 return; 171 return;
135 172
136 const FilePath mount_point = gdata::util::GetDriveMountPointPath(); 173 const FilePath mount_point = gdata::util::GetDriveMountPointPath();
137 fileapi::ExternalFileSystemMountPointProvider* provider = 174 fileapi::ExternalFileSystemMountPointProvider* provider =
138 BrowserContext::GetDefaultStoragePartition(profile_)-> 175 BrowserContext::GetDefaultStoragePartition(profile_)->
139 GetFileSystemContext()->external_provider(); 176 GetFileSystemContext()->external_provider();
140 if (provider && !provider->HasMountPoint(mount_point)) { 177 if (provider && !provider->HasMountPoint(mount_point)) {
141 provider->AddRemoteMountPoint( 178 provider->AddRemoteMountPoint(
142 mount_point, 179 mount_point,
143 new DriveFileSystemProxy(file_system_.get())); 180 new DriveFileSystemProxy(file_system_.get()));
(...skipping 12 matching lines...) Expand all
156 GetFileSystemContext()->external_provider(); 193 GetFileSystemContext()->external_provider();
157 if (provider && provider->HasMountPoint(mount_point)) 194 if (provider && provider->HasMountPoint(mount_point))
158 provider->RemoveMountPoint(mount_point); 195 provider->RemoveMountPoint(mount_point);
159 } 196 }
160 197
161 void DriveSystemService::OnCacheInitialized(bool success) { 198 void DriveSystemService::OnCacheInitialized(bool success) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
163 200
164 if (!success) { 201 if (!success) {
165 LOG(WARNING) << "Failed to initialize the cache. Disabling Drive"; 202 LOG(WARNING) << "Failed to initialize the cache. Disabling Drive";
166 gdata::util::DisableDrive(profile_); 203 DisableDrive(profile_);
167 // Change the download directory to the default value if the download 204 // Change the download directory to the default value if the download
168 // destination is set to under Drive mount point. 205 // destination is set to under Drive mount point.
169 // 206 //
170 // TODO(satorux): This cannot be done in DisableDrive(), as there is a 207 // TODO(satorux): This cannot be done in DisableDrive(), as there is a
171 // dependency problem. We should move this code to DisableDrive() once 208 // dependency problem. We should move this code to DisableDrive() once
172 // the dependency problem is solved. crbug.com/153962 209 // the dependency problem is solved. crbug.com/153962
173 PrefService* pref_service = profile_->GetPrefs(); 210 PrefService* pref_service = profile_->GetPrefs();
174 if (gdata::util::IsUnderDriveMountPoint( 211 if (gdata::util::IsUnderDriveMountPoint(
175 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { 212 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) {
176 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, 213 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 g_test_cache_root ? FilePath(*g_test_cache_root) : 290 g_test_cache_root ? FilePath(*g_test_cache_root) :
254 DriveCache::GetCacheRootPath(profile); 291 DriveCache::GetCacheRootPath(profile);
255 delete g_test_cache_root; 292 delete g_test_cache_root;
256 g_test_cache_root = NULL; 293 g_test_cache_root = NULL;
257 294
258 service->Initialize(drive_service, cache_root); 295 service->Initialize(drive_service, cache_root);
259 return service; 296 return service;
260 } 297 }
261 298
262 } // namespace gdata 299 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_system_service.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698