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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 google_apis::DriveServiceInterface* drive_service, | 337 google_apis::DriveServiceInterface* drive_service, |
338 google_apis::DriveUploaderInterface* uploader, | 338 google_apis::DriveUploaderInterface* uploader, |
339 DriveWebAppsRegistryInterface* webapps_registry, | 339 DriveWebAppsRegistryInterface* webapps_registry, |
340 base::SequencedTaskRunner* blocking_task_runner) | 340 base::SequencedTaskRunner* blocking_task_runner) |
341 : profile_(profile), | 341 : profile_(profile), |
342 cache_(cache), | 342 cache_(cache), |
343 uploader_(uploader), | 343 uploader_(uploader), |
344 drive_service_(drive_service), | 344 drive_service_(drive_service), |
345 webapps_registry_(webapps_registry), | 345 webapps_registry_(webapps_registry), |
346 update_timer_(true /* retain_user_task */, true /* is_repeating */), | 346 update_timer_(true /* retain_user_task */, true /* is_repeating */), |
| 347 last_update_check_error_(DRIVE_FILE_OK), |
347 hide_hosted_docs_(false), | 348 hide_hosted_docs_(false), |
348 blocking_task_runner_(blocking_task_runner), | 349 blocking_task_runner_(blocking_task_runner), |
349 scheduler_(new DriveScheduler(profile, &drive_operations_)), | 350 scheduler_(new DriveScheduler(profile, &drive_operations_)), |
| 351 polling_interval_sec_(kFastPollingIntervalInSec), |
| 352 push_notification_enabled_(false), |
350 ALLOW_THIS_IN_INITIALIZER_LIST(ui_weak_ptr_factory_(this)), | 353 ALLOW_THIS_IN_INITIALIZER_LIST(ui_weak_ptr_factory_(this)), |
351 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()), | 354 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { |
352 polling_interval_sec_(kFastPollingIntervalInSec) { | |
353 // Should be created from the file browser extension API on UI thread. | 355 // Should be created from the file browser extension API on UI thread. |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 } | 357 } |
356 | 358 |
357 void DriveFileSystem::Reload() { | 359 void DriveFileSystem::Reload() { |
358 InitializeResourceMetadataAndFeedLoader(); | 360 InitializeResourceMetadataAndFeedLoader(); |
359 | 361 |
360 feed_loader_->ReloadFromServerIfNeeded( | 362 feed_loader_->ReloadFromServerIfNeeded( |
361 base::Bind(&DriveFileSystem::NotifyInitialLoadFinishedAndRun, | 363 base::Bind(&DriveFileSystem::NotifyInitialLoadFinishedAndRun, |
362 ui_weak_ptr_, | 364 ui_weak_ptr_, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 406 |
405 if (resource_metadata_->initialized() && !feed_loader_->refreshing()) { | 407 if (resource_metadata_->initialized() && !feed_loader_->refreshing()) { |
406 feed_loader_->ReloadFromServerIfNeeded( | 408 feed_loader_->ReloadFromServerIfNeeded( |
407 base::Bind(&DriveFileSystem::OnUpdateChecked, ui_weak_ptr_)); | 409 base::Bind(&DriveFileSystem::OnUpdateChecked, ui_weak_ptr_)); |
408 } | 410 } |
409 } | 411 } |
410 | 412 |
411 void DriveFileSystem::OnUpdateChecked(DriveFileError error) { | 413 void DriveFileSystem::OnUpdateChecked(DriveFileError error) { |
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
413 DVLOG(1) << "CheckForUpdates finished: " << error; | 415 DVLOG(1) << "CheckForUpdates finished: " << error; |
| 416 last_update_check_time_ = base::Time::Now(); |
| 417 last_update_check_error_ = error; |
414 } | 418 } |
415 | 419 |
416 DriveFileSystem::~DriveFileSystem() { | 420 DriveFileSystem::~DriveFileSystem() { |
417 // This should be called from UI thread, from DriveSystemService shutdown. | 421 // This should be called from UI thread, from DriveSystemService shutdown. |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
419 | 423 |
420 feed_loader_->RemoveObserver(this); | 424 feed_loader_->RemoveObserver(this); |
421 | 425 |
422 // Cancel all the in-flight operations. | 426 // Cancel all the in-flight operations. |
423 // This asynchronously cancels the URL fetch operations. | 427 // This asynchronously cancels the URL fetch operations. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // DriveSystemService::RemoveDriveMountPoint(), this will be called again from | 469 // DriveSystemService::RemoveDriveMountPoint(), this will be called again from |
466 // FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(). | 470 // FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(). |
467 // We choose to stopping updates asynchronous without waiting for filemanager, | 471 // We choose to stopping updates asynchronous without waiting for filemanager, |
468 // rather than waiting for completion of unmounting on filemanager. | 472 // rather than waiting for completion of unmounting on filemanager. |
469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
470 if (update_timer_.IsRunning()) | 474 if (update_timer_.IsRunning()) |
471 update_timer_.Stop(); | 475 update_timer_.Stop(); |
472 } | 476 } |
473 | 477 |
474 void DriveFileSystem::SetPushNotificationEnabled(bool enabled) { | 478 void DriveFileSystem::SetPushNotificationEnabled(bool enabled) { |
| 479 push_notification_enabled_ = enabled; |
475 polling_interval_sec_ = enabled ? kSlowPollingIntervalInSec : | 480 polling_interval_sec_ = enabled ? kSlowPollingIntervalInSec : |
476 kFastPollingIntervalInSec; | 481 kFastPollingIntervalInSec; |
477 } | 482 } |
478 | 483 |
479 void DriveFileSystem::GetEntryInfoByResourceId( | 484 void DriveFileSystem::GetEntryInfoByResourceId( |
480 const std::string& resource_id, | 485 const std::string& resource_id, |
481 const GetEntryInfoWithFilePathCallback& callback) { | 486 const GetEntryInfoWithFilePathCallback& callback) { |
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
483 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 488 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
484 DCHECK(!callback.is_null()); | 489 DCHECK(!callback.is_null()); |
(...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 params.callback)); | 2137 params.callback)); |
2133 } | 2138 } |
2134 | 2139 |
2135 DriveFileSystemMetadata DriveFileSystem::GetMetadata() const { | 2140 DriveFileSystemMetadata DriveFileSystem::GetMetadata() const { |
2136 DriveFileSystemMetadata metadata; | 2141 DriveFileSystemMetadata metadata; |
2137 metadata.largest_changestamp = resource_metadata_->largest_changestamp(); | 2142 metadata.largest_changestamp = resource_metadata_->largest_changestamp(); |
2138 metadata.origin = resource_metadata_->initialized() ? | 2143 metadata.origin = resource_metadata_->initialized() ? |
2139 "INITIALIZED" : "UNINITIALIZED"; | 2144 "INITIALIZED" : "UNINITIALIZED"; |
2140 if (feed_loader_->refreshing()) | 2145 if (feed_loader_->refreshing()) |
2141 metadata.origin += " (refreshing)"; | 2146 metadata.origin += " (refreshing)"; |
| 2147 |
| 2148 // Metadata related to delta update. |
| 2149 metadata.push_notification_enabled = push_notification_enabled_; |
| 2150 metadata.polling_interval_sec = polling_interval_sec_; |
| 2151 metadata.last_update_check_time = last_update_check_time_; |
| 2152 metadata.last_update_check_error = last_update_check_error_; |
| 2153 |
2142 return metadata; | 2154 return metadata; |
2143 } | 2155 } |
2144 | 2156 |
2145 void DriveFileSystem::Observe(int type, | 2157 void DriveFileSystem::Observe(int type, |
2146 const content::NotificationSource& source, | 2158 const content::NotificationSource& source, |
2147 const content::NotificationDetails& details) { | 2159 const content::NotificationDetails& details) { |
2148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2149 | 2161 |
2150 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 2162 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
2151 PrefService* pref_service = profile_->GetPrefs(); | 2163 PrefService* pref_service = profile_->GetPrefs(); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 return; | 2515 return; |
2504 } | 2516 } |
2505 | 2517 |
2506 PlatformFileInfoProto entry_file_info; | 2518 PlatformFileInfoProto entry_file_info; |
2507 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 2519 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
2508 *entry_proto->mutable_file_info() = entry_file_info; | 2520 *entry_proto->mutable_file_info() = entry_file_info; |
2509 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 2521 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
2510 } | 2522 } |
2511 | 2523 |
2512 } // namespace drive | 2524 } // namespace drive |
OLD | NEW |