| 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class DownloadOperation; | 35 class DownloadOperation; |
| 36 class OperationObserver; | 36 class OperationObserver; |
| 37 | 37 |
| 38 class OpenFileOperation { | 38 class OpenFileOperation { |
| 39 public: | 39 public: |
| 40 OpenFileOperation(base::SequencedTaskRunner* blocking_task_runner, | 40 OpenFileOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 41 OperationObserver* observer, | 41 OperationObserver* observer, |
| 42 JobScheduler* scheduler, | 42 JobScheduler* scheduler, |
| 43 internal::ResourceMetadata* metadata, | 43 internal::ResourceMetadata* metadata, |
| 44 internal::FileCache* cache, | 44 internal::FileCache* cache, |
| 45 const base::FilePath& temporary_file_directory, | 45 const base::FilePath& temporary_file_directory); |
| 46 std::map<base::FilePath, int>* open_files); | |
| 47 ~OpenFileOperation(); | 46 ~OpenFileOperation(); |
| 48 | 47 |
| 49 // Opens the file at |file_path|. | 48 // Opens the file at |file_path|. |
| 50 // If the file is not actually downloaded, this method starts | 49 // If the file is not actually downloaded, this method starts |
| 51 // to download it to the cache, and then runs |callback| upon the | 50 // to download it to the cache, and then runs |callback| upon the |
| 52 // completation with the path to the local cache file. | 51 // completation with the path to the local cache file. |
| 53 // See also the definition of OpenMode for its meaning. | 52 // See also the definition of OpenMode for its meaning. |
| 54 // |callback| must not be null. | 53 // |callback| must not be null. |
| 55 void OpenFile(const base::FilePath& file_path, | 54 void OpenFile(const base::FilePath& file_path, |
| 56 OpenMode open_mode, | 55 OpenMode open_mode, |
| 57 const OpenFileCallback& callback); | 56 const OpenFileCallback& callback); |
| 58 | 57 |
| 59 private: | 58 private: |
| 60 // Part of OpenFile(). Called after file creation is completed. | 59 // Part of OpenFile(). Called after file creation is completed. |
| 61 void OpenFileAfterCreateFile(const base::FilePath& file_path, | 60 void OpenFileAfterCreateFile(const base::FilePath& file_path, |
| 62 const OpenFileCallback& callback, | 61 const OpenFileCallback& callback, |
| 63 FileError error); | 62 FileError error); |
| 64 | 63 |
| 65 // Part of OpenFile(). Called after file downloading is completed. | 64 // Part of OpenFile(). Called after file downloading is completed. |
| 66 void OpenFileAfterFileDownloaded(const base::FilePath& file_path, | 65 void OpenFileAfterFileDownloaded(const OpenFileCallback& callback, |
| 67 const OpenFileCallback& callback, | |
| 68 FileError error, | 66 FileError error, |
| 69 const base::FilePath& local_file_path, | 67 const base::FilePath& local_file_path, |
| 70 scoped_ptr<ResourceEntry> entry); | 68 scoped_ptr<ResourceEntry> entry); |
| 71 | 69 |
| 72 // Part of OpenFile(). Called after the updating of the local state. | 70 // Part of OpenFile(). Called after the updating of the local state. |
| 73 void OpenFileAfterUpdateLocalState(const base::FilePath& file_path, | 71 void OpenFileAfterUpdateLocalState(const std::string& resource_id, |
| 74 const OpenFileCallback& callback, | 72 const OpenFileCallback& callback, |
| 75 const base::FilePath* local_file_path, | 73 const base::FilePath* local_file_path, |
| 76 FileError error); | 74 FileError error); |
| 77 | 75 |
| 76 // Closes the file with |resource_id|. |
| 77 void CloseFile(const std::string& resource_id); |
| 78 |
| 78 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 79 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 80 OperationObserver* observer_; |
| 79 internal::FileCache* cache_; | 81 internal::FileCache* cache_; |
| 80 | 82 |
| 81 scoped_ptr<CreateFileOperation> create_file_operation_; | 83 scoped_ptr<CreateFileOperation> create_file_operation_; |
| 82 scoped_ptr<DownloadOperation> download_operation_; | 84 scoped_ptr<DownloadOperation> download_operation_; |
| 83 | 85 |
| 84 // The map from paths for opened file to the number how many the file is | 86 // The map from resource id for an opened file to the number how many times |
| 85 // opened. The instance is owned by FileSystem and shared with | 87 // the file is opened. |
| 86 // CloseFileOperation. | 88 std::map<std::string, int> open_files_; |
| 87 std::map<base::FilePath, int>* open_files_; | |
| 88 | 89 |
| 89 // Note: This should remain the last member so it'll be destroyed and | 90 // Note: This should remain the last member so it'll be destroyed and |
| 90 // invalidate its weak pointers before any other members are destroyed. | 91 // invalidate its weak pointers before any other members are destroyed. |
| 91 base::WeakPtrFactory<OpenFileOperation> weak_ptr_factory_; | 92 base::WeakPtrFactory<OpenFileOperation> weak_ptr_factory_; |
| 92 DISALLOW_COPY_AND_ASSIGN(OpenFileOperation); | 93 DISALLOW_COPY_AND_ASSIGN(OpenFileOperation); |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 } // namespace file_system | 96 } // namespace file_system |
| 96 } // namespace drive | 97 } // namespace drive |
| 97 | 98 |
| 98 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ | 99 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_ |
| OLD | NEW |