OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_FILE_MANAGER_SNAPSHOT_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 | 14 |
15 class Profile; | 15 class Profile; |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class FilePath; | 18 class FilePath; |
19 } // namespace base | 19 } // namespace base |
20 | 20 |
21 namespace fileapi { | 21 namespace storage { |
22 class FileSystemURL; | 22 class FileSystemURL; |
23 } // namespace fileapi | 23 } // namespace storage |
24 | 24 |
25 namespace webkit_blob { | 25 namespace storage { |
26 class ShareableFileReference; | 26 class ShareableFileReference; |
27 } // namespace webkit_blob | 27 } // namespace storage |
28 | 28 |
29 namespace file_manager { | 29 namespace file_manager { |
30 | 30 |
31 // Utility class for creating a snapshot of a file system file on local disk. | 31 // Utility class for creating a snapshot of a file system file on local disk. |
32 // The class wraps the underlying implementation of fileapi's CreateSnapshotFile | 32 // The class wraps the underlying implementation of fileapi's CreateSnapshotFile |
33 // and prolongs the lifetime of snapshot files so that the client code that just | 33 // and prolongs the lifetime of snapshot files so that the client code that just |
34 // accepts file paths works without problems. | 34 // accepts file paths works without problems. |
35 class SnapshotManager { | 35 class SnapshotManager { |
36 public: | 36 public: |
37 // The callback type for CreateManagedSnapshot. | 37 // The callback type for CreateManagedSnapshot. |
38 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; | 38 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; |
39 | 39 |
40 explicit SnapshotManager(Profile* profile); | 40 explicit SnapshotManager(Profile* profile); |
41 ~SnapshotManager(); | 41 ~SnapshotManager(); |
42 | 42 |
43 // Creates a snapshot file copy of a file system file |absolute_file_path| and | 43 // Creates a snapshot file copy of a file system file |absolute_file_path| and |
44 // returns back to |callback|. Returns empty path for failure. | 44 // returns back to |callback|. Returns empty path for failure. |
45 void CreateManagedSnapshot(const base::FilePath& absolute_file_path, | 45 void CreateManagedSnapshot(const base::FilePath& absolute_file_path, |
46 const LocalPathCallback& callback); | 46 const LocalPathCallback& callback); |
47 | 47 |
48 // Struct for keeping the snapshot file reference with its file size used for | 48 // Struct for keeping the snapshot file reference with its file size used for |
49 // computing the necessity of clean up. | 49 // computing the necessity of clean up. |
50 struct FileReferenceWithSizeInfo { | 50 struct FileReferenceWithSizeInfo { |
51 FileReferenceWithSizeInfo( | 51 FileReferenceWithSizeInfo( |
52 scoped_refptr<webkit_blob::ShareableFileReference> ref, | 52 scoped_refptr<storage::ShareableFileReference> ref, |
53 int64 size); | 53 int64 size); |
54 ~FileReferenceWithSizeInfo(); | 54 ~FileReferenceWithSizeInfo(); |
55 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; | 55 scoped_refptr<storage::ShareableFileReference> file_ref; |
56 int64 file_size; | 56 int64 file_size; |
57 }; | 57 }; |
58 | 58 |
59 private: | 59 private: |
60 // Part of CreateManagedSnapshot. | 60 // Part of CreateManagedSnapshot. |
61 void CreateManagedSnapshotAfterSpaceComputed( | 61 void CreateManagedSnapshotAfterSpaceComputed( |
62 const fileapi::FileSystemURL& filesystem_url, | 62 const storage::FileSystemURL& filesystem_url, |
63 const LocalPathCallback& callback, | 63 const LocalPathCallback& callback, |
64 int64 needed_space); | 64 int64 needed_space); |
65 | 65 |
66 // Part of CreateManagedSnapshot. | 66 // Part of CreateManagedSnapshot. |
67 void OnCreateSnapshotFile( | 67 void OnCreateSnapshotFile( |
68 const LocalPathCallback& callback, | 68 const LocalPathCallback& callback, |
69 base::File::Error result, | 69 base::File::Error result, |
70 const base::File::Info& file_info, | 70 const base::File::Info& file_info, |
71 const base::FilePath& platform_path, | 71 const base::FilePath& platform_path, |
72 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 72 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
73 | 73 |
74 Profile* profile_; | 74 Profile* profile_; |
75 std::deque<FileReferenceWithSizeInfo> file_refs_; | 75 std::deque<FileReferenceWithSizeInfo> file_refs_; |
76 | 76 |
77 // Note: This should remain the last member so it'll be destroyed and | 77 // Note: This should remain the last member so it'll be destroyed and |
78 // invalidate the weak pointers before any other members are destroyed. | 78 // invalidate the weak pointers before any other members are destroyed. |
79 base::WeakPtrFactory<SnapshotManager> weak_ptr_factory_; | 79 base::WeakPtrFactory<SnapshotManager> weak_ptr_factory_; |
80 DISALLOW_COPY_AND_ASSIGN(SnapshotManager); | 80 DISALLOW_COPY_AND_ASSIGN(SnapshotManager); |
81 }; | 81 }; |
82 | 82 |
83 } // namespace file_manager | 83 } // namespace file_manager |
84 | 84 |
85 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ |
OLD | NEW |