Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / snapshot_manager.h
blobbf6486e4ce66f5f3c1d1c7cff9d5edf280316562
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_
8 #include <deque>
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"
15 class Profile;
17 namespace base {
18 class FilePath;
19 } // namespace base
21 namespace storage {
22 class FileSystemURL;
23 } // namespace storage
25 namespace storage {
26 class ShareableFileReference;
27 } // namespace storage
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 {
36 public:
37 // The callback type for CreateManagedSnapshot.
38 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback;
40 explicit SnapshotManager(Profile* profile);
41 ~SnapshotManager();
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<storage::ShareableFileReference> ref,
53 int64 size);
54 ~FileReferenceWithSizeInfo();
55 scoped_refptr<storage::ShareableFileReference> file_ref;
56 int64 file_size;
59 private:
60 // Part of CreateManagedSnapshot.
61 void CreateManagedSnapshotAfterSpaceComputed(
62 const storage::FileSystemURL& filesystem_url,
63 const LocalPathCallback& callback,
64 int64 needed_space);
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<storage::ShareableFileReference>& file_ref);
74 Profile* profile_;
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_