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/file_system.h" | 5 #include "chrome/browser/chromeos/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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
34 | 34 |
35 using content::BrowserThread; | 35 using content::BrowserThread; |
36 | 36 |
37 namespace drive { | 37 namespace drive { |
38 namespace { | 38 namespace { |
39 | 39 |
40 //================================ Helper functions ============================ | 40 //================================ Helper functions ============================ |
41 | 41 |
42 // Helper function for binding |path| to GetResourceEntryWithFilePathCallback | |
43 // and create GetResourceEntryCallback. | |
44 void RunGetResourceEntryWithFilePathCallback( | |
45 const GetResourceEntryWithFilePathCallback& callback, | |
46 const base::FilePath& path, | |
47 FileError error, | |
48 scoped_ptr<ResourceEntry> entry) { | |
49 DCHECK(!callback.is_null()); | |
50 callback.Run(error, path, entry.Pass()); | |
51 } | |
52 | |
53 // Callback for ResourceMetadata::GetLargestChangestamp. | 42 // Callback for ResourceMetadata::GetLargestChangestamp. |
54 // |callback| must not be null. | 43 // |callback| must not be null. |
55 void OnGetLargestChangestamp( | 44 void OnGetLargestChangestamp( |
56 FileSystemMetadata metadata, // Will be modified. | 45 FileSystemMetadata metadata, // Will be modified. |
57 const GetFilesystemMetadataCallback& callback, | 46 const GetFilesystemMetadataCallback& callback, |
58 int64 largest_changestamp) { | 47 int64 largest_changestamp) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 DCHECK(!callback.is_null()); | 49 DCHECK(!callback.is_null()); |
61 | 50 |
62 metadata.largest_changestamp = largest_changestamp; | 51 metadata.largest_changestamp = largest_changestamp; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 observers_.AddObserver(observer); | 161 observers_.AddObserver(observer); |
173 } | 162 } |
174 | 163 |
175 void FileSystem::RemoveObserver(FileSystemObserver* observer) { | 164 void FileSystem::RemoveObserver(FileSystemObserver* observer) { |
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
177 observers_.RemoveObserver(observer); | 166 observers_.RemoveObserver(observer); |
178 } | 167 } |
179 | 168 |
180 void FileSystem::GetResourceEntryById( | 169 void FileSystem::GetResourceEntryById( |
181 const std::string& resource_id, | 170 const std::string& resource_id, |
182 const GetResourceEntryWithFilePathCallback& callback) { | 171 const GetResourceEntryCallback& callback) { |
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
184 DCHECK(!resource_id.empty()); | 173 DCHECK(!resource_id.empty()); |
185 DCHECK(!callback.is_null()); | 174 DCHECK(!callback.is_null()); |
186 | 175 |
187 resource_metadata_->GetResourceEntryByIdOnUIThread( | 176 resource_metadata_->GetResourceEntryByIdOnUIThread( |
188 resource_id, | 177 resource_id, |
189 base::Bind(&FileSystem::GetResourceEntryByIdAfterGetEntry, | 178 base::Bind(&FileSystem::GetResourceEntryByIdAfterGetEntry, |
190 weak_ptr_factory_.GetWeakPtr(), | 179 weak_ptr_factory_.GetWeakPtr(), |
191 callback)); | 180 callback)); |
192 } | 181 } |
193 | 182 |
194 void FileSystem::GetResourceEntryByIdAfterGetEntry( | 183 void FileSystem::GetResourceEntryByIdAfterGetEntry( |
195 const GetResourceEntryWithFilePathCallback& callback, | 184 const GetResourceEntryCallback& callback, |
196 FileError error, | 185 FileError error, |
197 const base::FilePath& file_path, | |
198 scoped_ptr<ResourceEntry> entry) { | 186 scoped_ptr<ResourceEntry> entry) { |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
200 DCHECK(!callback.is_null()); | 188 DCHECK(!callback.is_null()); |
201 | 189 |
202 if (error != FILE_ERROR_OK) { | 190 if (error != FILE_ERROR_OK) { |
203 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 191 callback.Run(error, scoped_ptr<ResourceEntry>()); |
204 return; | 192 return; |
205 } | 193 } |
206 DCHECK(entry.get()); | 194 DCHECK(entry.get()); |
207 | 195 |
208 CheckLocalModificationAndRun( | 196 CheckLocalModificationAndRun(entry.Pass(), callback); |
209 entry.Pass(), | |
210 base::Bind(&RunGetResourceEntryWithFilePathCallback, | |
211 callback, | |
212 file_path)); | |
213 } | 197 } |
214 | 198 |
215 void FileSystem::TransferFileFromRemoteToLocal( | 199 void FileSystem::TransferFileFromRemoteToLocal( |
216 const base::FilePath& remote_src_file_path, | 200 const base::FilePath& remote_src_file_path, |
217 const base::FilePath& local_dest_file_path, | 201 const base::FilePath& local_dest_file_path, |
218 const FileOperationCallback& callback) { | 202 const FileOperationCallback& callback) { |
219 | 203 |
220 operations_.TransferFileFromRemoteToLocal(remote_src_file_path, | 204 operations_.TransferFileFromRemoteToLocal(remote_src_file_path, |
221 local_dest_file_path, | 205 local_dest_file_path, |
222 callback); | 206 callback); |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 return; | 1091 return; |
1108 } | 1092 } |
1109 | 1093 |
1110 PlatformFileInfoProto entry_file_info; | 1094 PlatformFileInfoProto entry_file_info; |
1111 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1095 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
1112 *entry->mutable_file_info() = entry_file_info; | 1096 *entry->mutable_file_info() = entry_file_info; |
1113 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1097 callback.Run(FILE_ERROR_OK, entry.Pass()); |
1114 } | 1098 } |
1115 | 1099 |
1116 } // namespace drive | 1100 } // namespace drive |
OLD | NEW |