| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_system/touch_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/chromeos/drive/file_change.h" |
| 11 #include "chrome/browser/chromeos/drive/file_errors.h" | 12 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 13 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 13 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 14 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 | 16 |
| 16 using content::BrowserThread; | 17 using content::BrowserThread; |
| 17 | 18 |
| 18 namespace drive { | 19 namespace drive { |
| 19 namespace file_system { | 20 namespace file_system { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Updates the timestamps of the entry specified by |file_path|. | 24 // Updates the timestamps of the entry specified by |file_path|. |
| 24 FileError UpdateLocalState(internal::ResourceMetadata* metadata, | 25 FileError UpdateLocalState(internal::ResourceMetadata* metadata, |
| 25 const base::FilePath& file_path, | 26 const base::FilePath& file_path, |
| 26 const base::Time& last_access_time, | 27 const base::Time& last_access_time, |
| 27 const base::Time& last_modified_time, | 28 const base::Time& last_modified_time, |
| 28 std::string* local_id) { | 29 ResourceEntry* entry, |
| 29 ResourceEntry entry; | 30 std::string* local_id) { |
| 30 FileError error = metadata->GetResourceEntryByPath(file_path, &entry); | 31 FileError error = metadata->GetResourceEntryByPath(file_path, entry); |
| 31 if (error != FILE_ERROR_OK) | 32 if (error != FILE_ERROR_OK) |
| 32 return error; | 33 return error; |
| 33 *local_id = entry.local_id(); | 34 *local_id = entry->local_id(); |
| 34 | 35 |
| 35 PlatformFileInfoProto* file_info = entry.mutable_file_info(); | 36 PlatformFileInfoProto* file_info = entry->mutable_file_info(); |
| 36 if (!last_access_time.is_null()) | 37 if (!last_access_time.is_null()) |
| 37 file_info->set_last_accessed(last_access_time.ToInternalValue()); | 38 file_info->set_last_accessed(last_access_time.ToInternalValue()); |
| 38 if (!last_modified_time.is_null()) | 39 if (!last_modified_time.is_null()) |
| 39 file_info->set_last_modified(last_modified_time.ToInternalValue()); | 40 file_info->set_last_modified(last_modified_time.ToInternalValue()); |
| 40 entry.set_metadata_edit_state(ResourceEntry::DIRTY); | 41 entry->set_metadata_edit_state(ResourceEntry::DIRTY); |
| 41 entry.set_modification_date(base::Time::Now().ToInternalValue()); | 42 entry->set_modification_date(base::Time::Now().ToInternalValue()); |
| 42 return metadata->RefreshEntry(entry); | 43 return metadata->RefreshEntry(*entry); |
| 43 } | 44 } |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner, | 48 TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 48 OperationObserver* observer, | 49 OperationObserver* observer, |
| 49 internal::ResourceMetadata* metadata) | 50 internal::ResourceMetadata* metadata) |
| 50 : blocking_task_runner_(blocking_task_runner), | 51 : blocking_task_runner_(blocking_task_runner), |
| 51 observer_(observer), | 52 observer_(observer), |
| 52 metadata_(metadata), | 53 metadata_(metadata), |
| 53 weak_ptr_factory_(this) { | 54 weak_ptr_factory_(this) { |
| 54 } | 55 } |
| 55 | 56 |
| 56 TouchOperation::~TouchOperation() { | 57 TouchOperation::~TouchOperation() { |
| 57 } | 58 } |
| 58 | 59 |
| 59 void TouchOperation::TouchFile(const base::FilePath& file_path, | 60 void TouchOperation::TouchFile(const base::FilePath& file_path, |
| 60 const base::Time& last_access_time, | 61 const base::Time& last_access_time, |
| 61 const base::Time& last_modified_time, | 62 const base::Time& last_modified_time, |
| 62 const FileOperationCallback& callback) { | 63 const FileOperationCallback& callback) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 64 DCHECK(!callback.is_null()); | 65 DCHECK(!callback.is_null()); |
| 65 | 66 |
| 66 std::string* local_id = new std::string; | 67 std::string* local_id = new std::string; |
| 68 ResourceEntry* entry = new ResourceEntry; |
| 67 base::PostTaskAndReplyWithResult( | 69 base::PostTaskAndReplyWithResult( |
| 68 blocking_task_runner_.get(), | 70 blocking_task_runner_.get(), |
| 69 FROM_HERE, | 71 FROM_HERE, |
| 70 base::Bind(&UpdateLocalState, | 72 base::Bind(&UpdateLocalState, |
| 71 metadata_, | 73 metadata_, |
| 72 file_path, | 74 file_path, |
| 73 last_access_time, | 75 last_access_time, |
| 74 last_modified_time, | 76 last_modified_time, |
| 77 entry, |
| 75 local_id), | 78 local_id), |
| 76 base::Bind(&TouchOperation::TouchFileAfterUpdateLocalState, | 79 base::Bind(&TouchOperation::TouchFileAfterUpdateLocalState, |
| 77 weak_ptr_factory_.GetWeakPtr(), | 80 weak_ptr_factory_.GetWeakPtr(), |
| 78 file_path, | 81 file_path, |
| 79 callback, | 82 callback, |
| 83 base::Owned(entry), |
| 80 base::Owned(local_id))); | 84 base::Owned(local_id))); |
| 81 } | 85 } |
| 82 | 86 |
| 83 void TouchOperation::TouchFileAfterUpdateLocalState( | 87 void TouchOperation::TouchFileAfterUpdateLocalState( |
| 84 const base::FilePath& file_path, | 88 const base::FilePath& file_path, |
| 85 const FileOperationCallback& callback, | 89 const FileOperationCallback& callback, |
| 90 const ResourceEntry* entry, |
| 86 const std::string* local_id, | 91 const std::string* local_id, |
| 87 FileError error) { | 92 FileError error) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 DCHECK(!callback.is_null()); | 94 DCHECK(!callback.is_null()); |
| 95 DCHECK(!entry->file_info().is_directory()); |
| 96 |
| 97 FileChange changed_files; |
| 98 changed_files.Update( |
| 99 file_path, FileChange::FILE_TYPE_FILE, FileChange::ADD_OR_UPDATE); |
| 90 | 100 |
| 91 if (error == FILE_ERROR_OK) { | 101 if (error == FILE_ERROR_OK) { |
| 92 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 102 observer_->OnFileChangedByOperation(changed_files); |
| 93 observer_->OnEntryUpdatedByOperation(*local_id); | 103 observer_->OnEntryUpdatedByOperation(*local_id); |
| 94 } | 104 } |
| 95 callback.Run(error); | 105 callback.Run(error); |
| 96 } | 106 } |
| 97 | 107 |
| 98 } // namespace file_system | 108 } // namespace file_system |
| 99 } // namespace drive | 109 } // namespace drive |
| OLD | NEW |