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_errors.h" | 11 #include "chrome/browser/chromeos/drive/file_errors.h" |
12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
14 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
16 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 16 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
21 namespace drive { | 21 namespace drive { |
22 namespace file_system { | 22 namespace file_system { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Returns ResourceEntry and the local ID of the entry at the given path. | |
27 FileError GetResourceEntryAndIdByPath(internal::ResourceMetadata* metadata, | |
28 const base::FilePath& file_path, | |
29 std::string* local_id, | |
30 ResourceEntry* entry) { | |
31 FileError error = metadata->GetIdByPath(file_path, local_id); | |
32 if (error != FILE_ERROR_OK) | |
33 return error; | |
34 return metadata->GetResourceEntryById(*local_id, entry); | |
35 } | |
36 | |
37 // Refreshes the entry specified by |local_id| with the contents of | 26 // Refreshes the entry specified by |local_id| with the contents of |
38 // |resource_entry|. | 27 // |resource_entry|. |
39 FileError RefreshEntry(internal::ResourceMetadata* metadata, | 28 FileError RefreshEntry(internal::ResourceMetadata* metadata, |
40 const std::string& local_id, | 29 const std::string& local_id, |
41 scoped_ptr<google_apis::ResourceEntry> resource_entry, | 30 scoped_ptr<google_apis::ResourceEntry> resource_entry, |
42 base::FilePath* file_path) { | 31 base::FilePath* file_path) { |
43 DCHECK(resource_entry); | 32 DCHECK(resource_entry); |
44 | 33 |
45 ResourceEntry entry; | 34 ResourceEntry entry; |
46 std::string parent_resource_id; | 35 std::string parent_resource_id; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 70 } |
82 | 71 |
83 void TouchOperation::TouchFile(const base::FilePath& file_path, | 72 void TouchOperation::TouchFile(const base::FilePath& file_path, |
84 const base::Time& last_access_time, | 73 const base::Time& last_access_time, |
85 const base::Time& last_modified_time, | 74 const base::Time& last_modified_time, |
86 const FileOperationCallback& callback) { | 75 const FileOperationCallback& callback) { |
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
88 DCHECK(!callback.is_null()); | 77 DCHECK(!callback.is_null()); |
89 | 78 |
90 ResourceEntry* entry = new ResourceEntry; | 79 ResourceEntry* entry = new ResourceEntry; |
91 std::string* local_id = new std::string; | |
92 base::PostTaskAndReplyWithResult( | 80 base::PostTaskAndReplyWithResult( |
93 blocking_task_runner_.get(), | 81 blocking_task_runner_.get(), |
94 FROM_HERE, | 82 FROM_HERE, |
95 base::Bind(&GetResourceEntryAndIdByPath, | 83 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, |
96 base::Unretained(metadata_), | 84 base::Unretained(metadata_), |
97 file_path, | 85 file_path, |
98 local_id, | |
99 entry), | 86 entry), |
100 base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry, | 87 base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry, |
101 weak_ptr_factory_.GetWeakPtr(), | 88 weak_ptr_factory_.GetWeakPtr(), |
102 last_access_time, | 89 last_access_time, |
103 last_modified_time, | 90 last_modified_time, |
104 callback, | 91 callback, |
105 base::Owned(local_id), | |
106 base::Owned(entry))); | 92 base::Owned(entry))); |
107 } | 93 } |
108 | 94 |
109 void TouchOperation::TouchFileAfterGetResourceEntry( | 95 void TouchOperation::TouchFileAfterGetResourceEntry( |
110 const base::Time& last_access_time, | 96 const base::Time& last_access_time, |
111 const base::Time& last_modified_time, | 97 const base::Time& last_modified_time, |
112 const FileOperationCallback& callback, | 98 const FileOperationCallback& callback, |
113 std::string* local_id, | |
114 ResourceEntry* entry, | 99 ResourceEntry* entry, |
115 FileError error) { | 100 FileError error) { |
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
117 DCHECK(!callback.is_null()); | 102 DCHECK(!callback.is_null()); |
118 DCHECK(entry); | 103 DCHECK(entry); |
119 | 104 |
120 if (error != FILE_ERROR_OK) { | 105 if (error != FILE_ERROR_OK) { |
121 callback.Run(error); | 106 callback.Run(error); |
122 return; | 107 return; |
123 } | 108 } |
124 | 109 |
125 // Note: |last_modified_time| is mapped to modifiedDate, |last_access_time| | 110 // Note: |last_modified_time| is mapped to modifiedDate, |last_access_time| |
126 // is mapped to lastViewedByMeDate. See also ConvertToResourceEntry(). | 111 // is mapped to lastViewedByMeDate. See also ConvertToResourceEntry(). |
127 scheduler_->TouchResource( | 112 scheduler_->TouchResource( |
128 entry->resource_id(), last_modified_time, last_access_time, | 113 entry->resource_id(), last_modified_time, last_access_time, |
129 base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated, | 114 base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated, |
130 weak_ptr_factory_.GetWeakPtr(), | 115 weak_ptr_factory_.GetWeakPtr(), |
131 *local_id, callback)); | 116 entry->local_id(), callback)); |
132 } | 117 } |
133 | 118 |
134 void TouchOperation::TouchFileAfterServerTimeStampUpdated( | 119 void TouchOperation::TouchFileAfterServerTimeStampUpdated( |
135 const std::string& local_id, | 120 const std::string& local_id, |
136 const FileOperationCallback& callback, | 121 const FileOperationCallback& callback, |
137 google_apis::GDataErrorCode gdata_error, | 122 google_apis::GDataErrorCode gdata_error, |
138 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 123 scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
140 DCHECK(!callback.is_null()); | 125 DCHECK(!callback.is_null()); |
141 | 126 |
(...skipping 26 matching lines...) Expand all Loading... |
168 DCHECK(!callback.is_null()); | 153 DCHECK(!callback.is_null()); |
169 | 154 |
170 if (error == FILE_ERROR_OK) | 155 if (error == FILE_ERROR_OK) |
171 observer_->OnDirectoryChangedByOperation(file_path->DirName()); | 156 observer_->OnDirectoryChangedByOperation(file_path->DirName()); |
172 | 157 |
173 callback.Run(error); | 158 callback.Run(error); |
174 } | 159 } |
175 | 160 |
176 } // namespace file_system | 161 } // namespace file_system |
177 } // namespace drive | 162 } // namespace drive |
OLD | NEW |