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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_
10 #include "base/callback_forward.h"
11 #include "base/files/file.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
23 } // namespace fileapi
25 namespace webkit_blob {
26 class ShareableFileReference;
27 } // namespace webkit_blob
29 namespace file_manager {
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
33 // and prolongs the lifetime of snapshot files so that the client code that just
34 // accepts file paths works without problems.
35 class SnapshotManager {
37 // The callback type for CreateManagedSnapshot.
38 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback;
40 explicit SnapshotManager(Profile* profile);
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.
45 void CreateManagedSnapshot(const base::FilePath& absolute_file_path,
46 const LocalPathCallback& callback);
48 // Struct for keeping the snapshot file reference with its file size used for
49 // computing the necessity of clean up.
50 struct FileReferenceWithSizeInfo {
51 FileReferenceWithSizeInfo(
52 scoped_refptr<webkit_blob::ShareableFileReference> ref,
54 ~FileReferenceWithSizeInfo();
55 scoped_refptr<webkit_blob::ShareableFileReference> file_ref;
60 // Part of CreateManagedSnapshot.
61 void CreateManagedSnapshotAfterSpaceComputed(
62 const fileapi::FileSystemURL& filesystem_url,
63 const LocalPathCallback& callback,
66 // Part of CreateManagedSnapshot.
67 void OnCreateSnapshotFile(
68 const LocalPathCallback& callback,
69 base::File::Error result,
70 const base::File::Info& file_info,
71 const base::FilePath& platform_path,
72 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
75 std::deque<FileReferenceWithSizeInfo> file_refs_;
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.
79 base::WeakPtrFactory<SnapshotManager> weak_ptr_factory_;
80 DISALLOW_COPY_AND_ASSIGN(SnapshotManager);
83 } // namespace file_manager
85 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_