Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h

Issue 1432403003: Do not call stat() when reading directories via File API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed FSP tests. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" 19 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
20 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "storage/browser/fileapi/async_file_util.h" 22 #include "storage/browser/fileapi/async_file_util.h"
22 23
23 struct SnapshotRequestInfo; 24 struct SnapshotRequestInfo;
24 25
25 // MTPDeviceDelegateImplLinux communicates with the media transfer protocol 26 // MTPDeviceDelegateImplLinux communicates with the media transfer protocol
26 // (MTP) device to complete file system operations. These operations are 27 // (MTP) device to complete file system operations. These operations are
27 // performed asynchronously. Instantiate this class per MTP device storage. 28 // performed asynchronously. Instantiate this class per MTP device storage.
28 // MTPDeviceDelegateImplLinux lives on the IO thread. 29 // MTPDeviceDelegateImplLinux lives on the IO thread.
29 // MTPDeviceDelegateImplLinux does a call-and-reply to the UI thread 30 // MTPDeviceDelegateImplLinux does a call-and-reply to the UI thread
(...skipping 25 matching lines...) Expand all
55 const tracked_objects::Location location; 56 const tracked_objects::Location location;
56 const base::Closure task; 57 const base::Closure task;
57 }; 58 };
58 59
59 class MTPFileNode; 60 class MTPFileNode;
60 61
61 // Maps file ids to file nodes. 62 // Maps file ids to file nodes.
62 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap; 63 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap;
63 64
64 // Maps file paths to file info. 65 // Maps file paths to file info.
65 typedef std::map<base::FilePath, storage::DirectoryEntry> FileInfoCache; 66 typedef std::map<base::FilePath, MTPDeviceTaskHelper::MTPEntry> FileInfoCache;
66 67
67 typedef base::Closure DeleteObjectSuccessCallback; 68 typedef base::Closure DeleteObjectSuccessCallback;
68 69
69 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. 70 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call.
70 // Defer the device initializations until the first file operation request. 71 // Defer the device initializations until the first file operation request.
71 // Do all the initializations in EnsureInitAndRunTask() function. 72 // Do all the initializations in EnsureInitAndRunTask() function.
72 MTPDeviceDelegateImplLinux(const std::string& device_location, 73 MTPDeviceDelegateImplLinux(const std::string& device_location,
73 const bool read_only); 74 const bool read_only);
74 75
75 // Destructed via CancelPendingTasksAndDeleteDelegate(). 76 // Destructed via CancelPendingTasksAndDeleteDelegate().
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const CreateDirectorySuccessCallback& success_callback, 194 const CreateDirectorySuccessCallback& success_callback,
194 const ErrorCallback& error_callback); 195 const ErrorCallback& error_callback);
195 196
196 // Called when ReadDirectoryInternal() completes for filling cache as part of 197 // Called when ReadDirectoryInternal() completes for filling cache as part of
197 // creating directories. 198 // creating directories.
198 virtual void OnDidReadDirectoryToCreateDirectory( 199 virtual void OnDidReadDirectoryToCreateDirectory(
199 const std::vector<base::FilePath>& components, 200 const std::vector<base::FilePath>& components,
200 const bool exclusive, 201 const bool exclusive,
201 const CreateDirectorySuccessCallback& success_callback, 202 const CreateDirectorySuccessCallback& success_callback,
202 const ErrorCallback& error_callback, 203 const ErrorCallback& error_callback,
203 const storage::AsyncFileUtil::EntryList& /* file_list */, 204 const storage::AsyncFileUtil::EntryList& entries,
204 const bool has_more); 205 const bool has_more);
205 206
206 // Called when ReadDirectory succeeds. 207 // Called when ReadDirectory succeeds.
207 virtual void OnDidReadDirectoryToDeleteDirectory( 208 virtual void OnDidReadDirectoryToDeleteDirectory(
208 const base::FilePath& directory_path, 209 const base::FilePath& directory_path,
209 const uint32 directory_id, 210 const uint32 directory_id,
210 const DeleteDirectorySuccessCallback& success_callback, 211 const DeleteDirectorySuccessCallback& success_callback,
211 const ErrorCallback& error_callback, 212 const ErrorCallback& error_callback,
212 const storage::AsyncFileUtil::EntryList& entries, 213 const MTPDeviceTaskHelper::MTPEntries& entries,
213 const bool has_more); 214 const bool has_more);
214 215
215 // Calls DeleteObjectOnUIThread on UI thread. 216 // Calls DeleteObjectOnUIThread on UI thread.
216 virtual void RunDeleteObjectOnUIThread( 217 virtual void RunDeleteObjectOnUIThread(
217 const base::FilePath& object_path, 218 const base::FilePath& object_path,
218 const uint32 object_id, 219 const uint32 object_id,
219 const DeleteObjectSuccessCallback& success_callback, 220 const DeleteObjectSuccessCallback& success_callback,
220 const ErrorCallback& error_callback); 221 const ErrorCallback& error_callback);
221 222
222 // Notifies |chage_type| of |file_path| to watchers. 223 // Notifies |chage_type| of |file_path| to watchers.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 342
342 // Called when ReadDirectory() succeeds. 343 // Called when ReadDirectory() succeeds.
343 // 344 //
344 // |dir_id| is the directory read. 345 // |dir_id| is the directory read.
345 // |success_callback| is invoked to notify the caller about the directory 346 // |success_callback| is invoked to notify the caller about the directory
346 // file entries. 347 // file entries.
347 // |file_list| contains the directory file entries with their file ids. 348 // |file_list| contains the directory file entries with their file ids.
348 // |has_more| is true if there are more file entries to read. 349 // |has_more| is true if there are more file entries to read.
349 void OnDidReadDirectory(uint32 dir_id, 350 void OnDidReadDirectory(uint32 dir_id,
350 const ReadDirectorySuccessCallback& success_callback, 351 const ReadDirectorySuccessCallback& success_callback,
351 const storage::AsyncFileUtil::EntryList& file_list, 352 const MTPDeviceTaskHelper::MTPEntries& mtp_entries,
352 bool has_more); 353 bool has_more);
353 354
354 // Called when WriteDataIntoSnapshotFile() succeeds. 355 // Called when WriteDataIntoSnapshotFile() succeeds.
355 // 356 //
356 // |snapshot_file_info| specifies the snapshot file metadata details. 357 // |snapshot_file_info| specifies the snapshot file metadata details.
357 // 358 //
358 // |current_snapshot_request_info_.success_callback| is invoked to notify the 359 // |current_snapshot_request_info_.success_callback| is invoked to notify the
359 // caller about |snapshot_file_info|. 360 // caller about |snapshot_file_info|.
360 void OnDidWriteDataIntoSnapshotFile( 361 void OnDidWriteDataIntoSnapshotFile(
361 const base::File::Info& snapshot_file_info, 362 const base::File::Info& snapshot_file_info,
362 const base::FilePath& snapshot_file_path); 363 const base::FilePath& snapshot_file_path);
363 364
364 // Called when WriteDataIntoSnapshotFile() fails. 365 // Called when WriteDataIntoSnapshotFile() fails.
365 // 366 //
366 // |error| specifies the file error code. 367 // |error| specifies the file error code.
367 // 368 //
368 // |current_snapshot_request_info_.error_callback| is invoked to notify the 369 // |current_snapshot_request_info_.error_callback| is invoked to notify the
369 // caller about |error|. 370 // caller about |error|.
370 void OnWriteDataIntoSnapshotFileError(base::File::Error error); 371 void OnWriteDataIntoSnapshotFileError(base::File::Error error);
371 372
372 // Called when ReadBytes() succeeds. 373 // Called when ReadBytes() succeeds.
373 // 374 //
374 // |success_callback| is invoked to notify the caller about the read bytes. 375 // |success_callback| is invoked to notify the caller about the read bytes.
375 // |bytes_read| is the number of bytes read. 376 // |bytes_read| is the number of bytes read.
376 void OnDidReadBytes(const ReadBytesSuccessCallback& success_callback, 377 void OnDidReadBytes(const ReadBytesSuccessCallback& success_callback,
377 const base::File::Info& file_info, int bytes_read); 378 const base::File::Info& file_info, int bytes_read);
378 379
379 // Called when FillFileCache() succeeds. 380 // Called when FillFileCache() succeeds.
380 void OnDidFillFileCache(const base::FilePath& path, 381 void OnDidFillFileCache(
381 const storage::AsyncFileUtil::EntryList& file_list, 382 const base::FilePath& path,
382 bool has_more); 383 const storage::AsyncFileUtil::EntryList& /* entries */,
384 bool has_more);
383 385
384 // Called when FillFileCache() fails. 386 // Called when FillFileCache() fails.
385 void OnFillFileCacheFailed(base::File::Error error); 387 void OnFillFileCacheFailed(base::File::Error error);
386 388
387 // Called when CreateTemporaryFile() completes for CopyFileLocal. 389 // Called when CreateTemporaryFile() completes for CopyFileLocal.
388 void OnDidCreateTemporaryFileToCopyFileLocal( 390 void OnDidCreateTemporaryFileToCopyFileLocal(
389 const base::FilePath& source_file_path, 391 const base::FilePath& source_file_path,
390 const base::FilePath& device_file_path, 392 const base::FilePath& device_file_path,
391 const CopyFileProgressCallback& progress_callback, 393 const CopyFileProgressCallback& progress_callback,
392 const CopyFileLocalSuccessCallback& success_callback, 394 const CopyFileLocalSuccessCallback& success_callback,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // the ReadDirectory operation. 516 // the ReadDirectory operation.
515 FileInfoCache file_info_cache_; 517 FileInfoCache file_info_cache_;
516 518
517 // For callbacks that may run after destruction. 519 // For callbacks that may run after destruction.
518 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; 520 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_;
519 521
520 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); 522 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux);
521 }; 523 };
522 524
523 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H _ 525 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698