OLD | NEW |
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 Loading... |
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 |
44 } // namespace | 47 } // namespace |
45 | 48 |
46 DriveSystemService::DriveSystemService(Profile* profile) | 49 DriveSystemService::DriveSystemService(Profile* profile) |
47 : profile_(profile), | 50 : profile_(profile), |
48 cache_(NULL), | 51 cache_(NULL), |
49 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 52 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
51 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 54 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
52 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 55 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
53 blocking_pool->GetSequenceToken()); | 56 blocking_pool->GetSequenceToken()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 stale_cache_files_remover_.reset(); | 100 stale_cache_files_remover_.reset(); |
98 sync_client_.reset(); | 101 sync_client_.reset(); |
99 download_observer_.reset(); | 102 download_observer_.reset(); |
100 file_write_helper_.reset(); | 103 file_write_helper_.reset(); |
101 file_system_.reset(); | 104 file_system_.reset(); |
102 webapps_registry_.reset(); | 105 webapps_registry_.reset(); |
103 uploader_.reset(); | 106 uploader_.reset(); |
104 drive_service_.reset(); | 107 drive_service_.reset(); |
105 } | 108 } |
106 | 109 |
| 110 // static |
| 111 bool DriveSystemService::IsDriveEnabled(Profile* profile) { |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 113 |
| 114 if (!AuthService::CanAuthenticate(profile)) |
| 115 return false; |
| 116 |
| 117 // Disable gdata if preference is set. This can happen with commandline flag |
| 118 // --disable-gdata or enterprise policy, or probably with user settings too |
| 119 // in the future. |
| 120 if (profile->GetPrefs()->GetBoolean(prefs::kDisableGData)) |
| 121 return false; |
| 122 |
| 123 if (g_drive_disabled_map && g_drive_disabled_map->count(profile) > 0) |
| 124 return false; |
| 125 |
| 126 return true; |
| 127 } |
| 128 |
107 void DriveSystemService::ClearCacheAndRemountFileSystem( | 129 void DriveSystemService::ClearCacheAndRemountFileSystem( |
108 const base::Callback<void(bool)>& callback) { | 130 const base::Callback<void(bool)>& callback) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 | 132 |
111 RemoveDriveMountPoint(); | 133 RemoveDriveMountPoint(); |
112 drive_service()->CancelAll(); | 134 drive_service()->CancelAll(); |
113 cache_->ClearAllOnUIThread( | 135 cache_->ClearAllOnUIThread( |
114 base::Bind(&DriveSystemService::AddBackDriveMountPoint, | 136 base::Bind(&DriveSystemService::AddBackDriveMountPoint, |
115 weak_ptr_factory_.GetWeakPtr(), | 137 weak_ptr_factory_.GetWeakPtr(), |
116 callback)); | 138 callback)); |
117 } | 139 } |
118 | 140 |
119 void DriveSystemService::AddBackDriveMountPoint( | 141 void DriveSystemService::AddBackDriveMountPoint( |
120 const base::Callback<void(bool)>& callback, | 142 const base::Callback<void(bool)>& callback, |
121 DriveFileError error, | 143 DriveFileError error, |
122 const FilePath& file_path) { | 144 const FilePath& file_path) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
124 | 146 |
125 file_system_->Initialize(); | 147 file_system_->Initialize(); |
126 AddDriveMountPoint(); | 148 AddDriveMountPoint(); |
127 | 149 |
128 if (!callback.is_null()) | 150 if (!callback.is_null()) |
129 callback.Run(error == DRIVE_FILE_OK); | 151 callback.Run(error == DRIVE_FILE_OK); |
130 } | 152 } |
131 | 153 |
132 void DriveSystemService::AddDriveMountPoint() { | 154 void DriveSystemService::AddDriveMountPoint() { |
133 if (!gdata::util::IsDriveEnabled(profile_)) | 155 if (!IsDriveEnabled(profile_)) |
134 return; | 156 return; |
135 | 157 |
136 const FilePath mount_point = gdata::util::GetDriveMountPointPath(); | 158 const FilePath mount_point = gdata::util::GetDriveMountPointPath(); |
137 fileapi::ExternalFileSystemMountPointProvider* provider = | 159 fileapi::ExternalFileSystemMountPointProvider* provider = |
138 BrowserContext::GetDefaultStoragePartition(profile_)-> | 160 BrowserContext::GetDefaultStoragePartition(profile_)-> |
139 GetFileSystemContext()->external_provider(); | 161 GetFileSystemContext()->external_provider(); |
140 if (provider && !provider->HasMountPoint(mount_point)) { | 162 if (provider && !provider->HasMountPoint(mount_point)) { |
141 provider->AddRemoteMountPoint( | 163 provider->AddRemoteMountPoint( |
142 mount_point, | 164 mount_point, |
143 new DriveFileSystemProxy(file_system_.get())); | 165 new DriveFileSystemProxy(file_system_.get())); |
(...skipping 12 matching lines...) Expand all Loading... |
156 GetFileSystemContext()->external_provider(); | 178 GetFileSystemContext()->external_provider(); |
157 if (provider && provider->HasMountPoint(mount_point)) | 179 if (provider && provider->HasMountPoint(mount_point)) |
158 provider->RemoveMountPoint(mount_point); | 180 provider->RemoveMountPoint(mount_point); |
159 } | 181 } |
160 | 182 |
161 void DriveSystemService::OnCacheInitialized(bool success) { | 183 void DriveSystemService::OnCacheInitialized(bool success) { |
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
163 | 185 |
164 if (!success) { | 186 if (!success) { |
165 LOG(WARNING) << "Failed to initialize the cache. Disabling Drive"; | 187 LOG(WARNING) << "Failed to initialize the cache. Disabling Drive"; |
166 gdata::util::DisableDrive(profile_); | 188 DisableDrive(profile_); |
167 // Change the download directory to the default value if the download | 189 // Change the download directory to the default value if the download |
168 // destination is set to under Drive mount point. | 190 // destination is set to under Drive mount point. |
169 // | 191 // |
170 // TODO(satorux): This cannot be done in DisableDrive(), as there is a | 192 // TODO(satorux): This cannot be done in DisableDrive(), as there is a |
171 // dependency problem. We should move this code to DisableDrive() once | 193 // dependency problem. We should move this code to DisableDrive() once |
172 // the dependency problem is solved. crbug.com/153962 | 194 // the dependency problem is solved. crbug.com/153962 |
173 PrefService* pref_service = profile_->GetPrefs(); | 195 PrefService* pref_service = profile_->GetPrefs(); |
174 if (gdata::util::IsUnderDriveMountPoint( | 196 if (gdata::util::IsUnderDriveMountPoint( |
175 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { | 197 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { |
176 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, | 198 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, |
177 download_util::GetDefaultDownloadDirectory()); | 199 download_util::GetDefaultDownloadDirectory()); |
178 } | 200 } |
179 return; | 201 return; |
180 } | 202 } |
181 | 203 |
182 content::DownloadManager* download_manager = | 204 content::DownloadManager* download_manager = |
183 g_browser_process->download_status_updater() ? | 205 g_browser_process->download_status_updater() ? |
184 BrowserContext::GetDownloadManager(profile_) : NULL; | 206 BrowserContext::GetDownloadManager(profile_) : NULL; |
185 download_observer_->Initialize( | 207 download_observer_->Initialize( |
186 download_manager, | 208 download_manager, |
187 cache_->GetCacheDirectoryPath( | 209 cache_->GetCacheDirectoryPath( |
188 DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); | 210 DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); |
189 | 211 |
190 AddDriveMountPoint(); | 212 AddDriveMountPoint(); |
191 } | 213 } |
192 | 214 |
| 215 // static |
| 216 void DriveSystemService::DisableDrive(Profile* profile) { |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 218 |
| 219 // We don't change kDisableGData preference here. If we do, we'll end up |
| 220 // disabling Drive on other devices, as kDisableGData is a syncable |
| 221 // preference. Hence the map is used here. |
| 222 if (!g_drive_disabled_map) |
| 223 g_drive_disabled_map = new std::map<Profile*, bool>; |
| 224 |
| 225 g_drive_disabled_map->insert(std::make_pair(profile, true)); |
| 226 } |
| 227 |
193 //===================== DriveSystemServiceFactory ============================= | 228 //===================== DriveSystemServiceFactory ============================= |
194 | 229 |
195 // static | 230 // static |
196 DriveSystemService* DriveSystemServiceFactory::GetForProfile( | 231 DriveSystemService* DriveSystemServiceFactory::GetForProfile( |
197 Profile* profile) { | 232 Profile* profile) { |
198 return static_cast<DriveSystemService*>( | 233 return static_cast<DriveSystemService*>( |
199 GetInstance()->GetServiceForProfile(profile, true)); | 234 GetInstance()->GetServiceForProfile(profile, true)); |
200 } | 235 } |
201 | 236 |
202 // static | 237 // static |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 g_test_cache_root ? FilePath(*g_test_cache_root) : | 288 g_test_cache_root ? FilePath(*g_test_cache_root) : |
254 DriveCache::GetCacheRootPath(profile); | 289 DriveCache::GetCacheRootPath(profile); |
255 delete g_test_cache_root; | 290 delete g_test_cache_root; |
256 g_test_cache_root = NULL; | 291 g_test_cache_root = NULL; |
257 | 292 |
258 service->Initialize(drive_service, cache_root); | 293 service->Initialize(drive_service, cache_root); |
259 return service; | 294 return service; |
260 } | 295 } |
261 | 296 |
262 } // namespace gdata | 297 } // namespace gdata |
OLD | NEW |