| 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/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 | 37 |
| 38 namespace drive { | 38 namespace drive { |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 const char kMimeTypeJson[] = "application/json"; | 41 const char kMimeTypeJson[] = "application/json"; |
| 42 const char kEmptyFilePath[] = "/dev/null"; | 42 const char kEmptyFilePath[] = "/dev/null"; |
| 43 | 43 |
| 44 // Drive update polling interval for polling only mode (in seconds). | |
| 45 const int kFastPollingIntervalInSec = 60; | |
| 46 | |
| 47 // Drive update polling interval when update notification is available (in | |
| 48 // seconds). Ideally we don't need this, but we do polling in case update | |
| 49 // notification doesn't work. http://crbug.com/157080 | |
| 50 const int kSlowPollingIntervalInSec = 300; | |
| 51 | |
| 52 //================================ Helper functions ============================ | 44 //================================ Helper functions ============================ |
| 53 | 45 |
| 54 // The class to wait for the drive service to be ready to start operation. | 46 // The class to wait for the drive service to be ready to start operation. |
| 55 class OperationReadinessObserver : public google_apis::DriveServiceObserver { | 47 class OperationReadinessObserver : public google_apis::DriveServiceObserver { |
| 56 public: | 48 public: |
| 57 OperationReadinessObserver(google_apis::DriveServiceInterface* drive_service, | 49 OperationReadinessObserver(google_apis::DriveServiceInterface* drive_service, |
| 58 const base::Closure& callback) | 50 const base::Closure& callback) |
| 59 : drive_service_(drive_service), | 51 : drive_service_(drive_service), |
| 60 callback_(callback) { | 52 callback_(callback) { |
| 61 DCHECK(!callback_.is_null()); | 53 DCHECK(!callback_.is_null()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 DriveCache* cache, | 206 DriveCache* cache, |
| 215 google_apis::DriveServiceInterface* drive_service, | 207 google_apis::DriveServiceInterface* drive_service, |
| 216 DriveWebAppsRegistry* webapps_registry, | 208 DriveWebAppsRegistry* webapps_registry, |
| 217 DriveResourceMetadata* resource_metadata, | 209 DriveResourceMetadata* resource_metadata, |
| 218 base::SequencedTaskRunner* blocking_task_runner) | 210 base::SequencedTaskRunner* blocking_task_runner) |
| 219 : profile_(profile), | 211 : profile_(profile), |
| 220 cache_(cache), | 212 cache_(cache), |
| 221 drive_service_(drive_service), | 213 drive_service_(drive_service), |
| 222 webapps_registry_(webapps_registry), | 214 webapps_registry_(webapps_registry), |
| 223 resource_metadata_(resource_metadata), | 215 resource_metadata_(resource_metadata), |
| 224 update_timer_(true /* retain_user_task */, true /* is_repeating */), | |
| 225 last_update_check_error_(DRIVE_FILE_OK), | 216 last_update_check_error_(DRIVE_FILE_OK), |
| 226 hide_hosted_docs_(false), | 217 hide_hosted_docs_(false), |
| 227 blocking_task_runner_(blocking_task_runner), | 218 blocking_task_runner_(blocking_task_runner), |
| 228 scheduler_(new DriveScheduler(profile, drive_service)), | 219 scheduler_(new DriveScheduler(profile, drive_service)), |
| 229 polling_interval_sec_(kFastPollingIntervalInSec), | |
| 230 push_notification_enabled_(false), | 220 push_notification_enabled_(false), |
| 231 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 221 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 232 // Should be created from the file browser extension API on UI thread. | 222 // Should be created from the file browser extension API on UI thread. |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 } | 224 } |
| 235 | 225 |
| 236 void DriveFileSystem::Reload() { | 226 void DriveFileSystem::Reload() { |
| 237 resource_metadata_->Reset(base::Bind(&DriveFileSystem::ReloadAfterReset, | 227 resource_metadata_->Reset(base::Bind(&DriveFileSystem::ReloadAfterReset, |
| 238 weak_ptr_factory_.GetWeakPtr())); | 228 weak_ptr_factory_.GetWeakPtr())); |
| 239 } | 229 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // OnReadyToPerformOperations() gets called. | 317 // OnReadyToPerformOperations() gets called. |
| 328 new OperationReadinessObserver( | 318 new OperationReadinessObserver( |
| 329 drive_service_, | 319 drive_service_, |
| 330 base::Bind(&DriveFileSystem::LoadIfNeeded, | 320 base::Bind(&DriveFileSystem::LoadIfNeeded, |
| 331 weak_ptr_factory_.GetWeakPtr(), | 321 weak_ptr_factory_.GetWeakPtr(), |
| 332 DirectoryFetchInfo(), | 322 DirectoryFetchInfo(), |
| 333 base::Bind(&util::EmptyFileOperationCallback))); | 323 base::Bind(&util::EmptyFileOperationCallback))); |
| 334 } | 324 } |
| 335 } | 325 } |
| 336 | 326 |
| 337 void DriveFileSystem::StartPolling() { | |
| 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 339 | |
| 340 DCHECK(!update_timer_.IsRunning()); | |
| 341 update_timer_.Start(FROM_HERE, | |
| 342 base::TimeDelta::FromSeconds(polling_interval_sec_), | |
| 343 base::Bind(&DriveFileSystem::CheckForUpdates, | |
| 344 weak_ptr_factory_.GetWeakPtr())); | |
| 345 } | |
| 346 | |
| 347 void DriveFileSystem::StopPolling() { | |
| 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 349 if (update_timer_.IsRunning()) | |
| 350 update_timer_.Stop(); | |
| 351 } | |
| 352 | |
| 353 void DriveFileSystem::SetPushNotificationEnabled(bool enabled) { | 327 void DriveFileSystem::SetPushNotificationEnabled(bool enabled) { |
| 354 push_notification_enabled_ = enabled; | 328 push_notification_enabled_ = enabled; |
| 355 polling_interval_sec_ = enabled ? kSlowPollingIntervalInSec : | |
| 356 kFastPollingIntervalInSec; | |
| 357 } | 329 } |
| 358 | 330 |
| 359 void DriveFileSystem::GetEntryInfoByResourceId( | 331 void DriveFileSystem::GetEntryInfoByResourceId( |
| 360 const std::string& resource_id, | 332 const std::string& resource_id, |
| 361 const GetEntryInfoWithFilePathCallback& callback) { | 333 const GetEntryInfoWithFilePathCallback& callback) { |
| 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 363 DCHECK(!resource_id.empty()); | 335 DCHECK(!resource_id.empty()); |
| 364 DCHECK(!callback.is_null()); | 336 DCHECK(!callback.is_null()); |
| 365 | 337 |
| 366 resource_metadata_->GetEntryInfoByResourceId( | 338 resource_metadata_->GetEntryInfoByResourceId( |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 const GetFilesystemMetadataCallback& callback) { | 1329 const GetFilesystemMetadataCallback& callback) { |
| 1358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1359 DCHECK(!callback.is_null()); | 1331 DCHECK(!callback.is_null()); |
| 1360 | 1332 |
| 1361 DriveFileSystemMetadata metadata; | 1333 DriveFileSystemMetadata metadata; |
| 1362 metadata.loaded = change_list_loader_->loaded(); | 1334 metadata.loaded = change_list_loader_->loaded(); |
| 1363 metadata.refreshing = change_list_loader_->refreshing(); | 1335 metadata.refreshing = change_list_loader_->refreshing(); |
| 1364 | 1336 |
| 1365 // Metadata related to delta update. | 1337 // Metadata related to delta update. |
| 1366 metadata.push_notification_enabled = push_notification_enabled_; | 1338 metadata.push_notification_enabled = push_notification_enabled_; |
| 1367 metadata.polling_interval_sec = polling_interval_sec_; | |
| 1368 metadata.last_update_check_time = last_update_check_time_; | 1339 metadata.last_update_check_time = last_update_check_time_; |
| 1369 metadata.last_update_check_error = last_update_check_error_; | 1340 metadata.last_update_check_error = last_update_check_error_; |
| 1370 | 1341 |
| 1371 resource_metadata_->GetLargestChangestamp( | 1342 resource_metadata_->GetLargestChangestamp( |
| 1372 base::Bind(&OnGetLargestChangestamp, metadata, callback)); | 1343 base::Bind(&OnGetLargestChangestamp, metadata, callback)); |
| 1373 } | 1344 } |
| 1374 | 1345 |
| 1375 void DriveFileSystem::OnDisableDriveHostedFilesChanged() { | 1346 void DriveFileSystem::OnDisableDriveHostedFilesChanged() { |
| 1376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1377 PrefService* pref_service = profile_->GetPrefs(); | 1348 PrefService* pref_service = profile_->GetPrefs(); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 return; | 1667 return; |
| 1697 } | 1668 } |
| 1698 | 1669 |
| 1699 PlatformFileInfoProto entry_file_info; | 1670 PlatformFileInfoProto entry_file_info; |
| 1700 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 1671 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 1701 *entry_proto->mutable_file_info() = entry_file_info; | 1672 *entry_proto->mutable_file_info() = entry_file_info; |
| 1702 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 1673 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
| 1703 } | 1674 } |
| 1704 | 1675 |
| 1705 } // namespace drive | 1676 } // namespace drive |
| OLD | NEW |