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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ 7 8 #include <vector> 9 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" 14 15 class Profile; 16 17 namespace base { 18 class FilePath; 19 } // namespace base 20 21 namespace webkit_blob { 22 class ShareableFileReference; 23 } // namespace webkit_blob 24 25 namespace file_manager { 26 27 // Utility class for creating a snapshot of a file system file on local disk. 28 // The class wraps the underlying implementation of fileapi's CreateSnapshotFile 29 // and prolongs the lifetime of snapshot files so that the client code that just 30 // accepts file paths works without problems. 31 class SnapshotManager { 32 public: 33 // The callback type for CreateManagedSnapshot. 34 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; 35 36 explicit SnapshotManager(Profile* profile); 37 ~SnapshotManager(); 38 39 // Creates a snapshot file copy of a file system file |absolute_file_path| and 40 // returns back to |callback|. Returns empty path for failure. 41 void CreateManagedSnapshot(const base::FilePath& absolute_file_path, 42 const LocalPathCallback& callback); 43 44 private: 45 // Part of CreateManagedSnapshot. 46 void OnCreateSnapshotFile( 47 const LocalPathCallback& callback, 48 base::File::Error result, 49 const base::File::Info& file_info, 50 const base::FilePath& platform_path, 51 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); 52 53 Profile* profile_; 54 std::vector<scoped_refptr<webkit_blob::ShareableFileReference> > file_refs_; 55 56 // Note: This should remain the last member so it'll be destroyed and 57 // invalidate the weak pointers before any other members are destroyed. 58 base::WeakPtrFactory<SnapshotManager> weak_ptr_factory_; 59 DISALLOW_COPY_AND_ASSIGN(SnapshotManager); 60 }; 61 62 } // namespace file_manager 63 64 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_SNAPSHOT_MANAGER_H_ 65