Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: webkit/blob/shareable_file_reference.h

Issue 14261015: Add ScopedFile class which supports scope-out deletion and/or callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_ 5 #ifndef WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_
6 #define WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_ 6 #define WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "webkit/blob/scoped_file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "webkit/storage/webkit_storage_export.h"
14
15 namespace base {
16 class TaskRunner;
17 }
18 11
19 namespace webkit_blob { 12 namespace webkit_blob {
20 13
21 // A refcounted wrapper around a FilePath that can optionally schedule 14 // A refcounted wrapper around a FilePath that can optionally schedule
22 // the file to be deleted upon final release and/or to notify a consumer 15 // the file to be deleted upon final release and/or to notify a consumer
23 // when final release occurs. This class is single-threaded and should 16 // when final release occurs. This class is single-threaded and should
24 // only be invoked on the IO thread in chrome. 17 // only be invoked on the IO thread in chrome.
25 class WEBKIT_STORAGE_EXPORT ShareableFileReference 18 class WEBKIT_STORAGE_EXPORT ShareableFileReference
26 : public base::RefCounted<ShareableFileReference> { 19 : public base::RefCounted<ShareableFileReference> {
27 public: 20 public:
28 typedef base::Callback<void(const base::FilePath&)> FinalReleaseCallback; 21 typedef ScopedFile::ScopeOutCallback FinalReleaseCallback;
29 22
30 enum FinalReleasePolicy { 23 enum FinalReleasePolicy {
31 DELETE_ON_FINAL_RELEASE, 24 DELETE_ON_FINAL_RELEASE,
32 DONT_DELETE_ON_FINAL_RELEASE, 25 DONT_DELETE_ON_FINAL_RELEASE,
michaeln 2013/04/22 21:07:03 Maybe if these were defined in terms of the Scoped
kinuko 2013/04/23 06:31:29 Done.
33 }; 26 };
34 27
35 // Returns a ShareableFileReference for the given path, if no reference 28 // Returns a ShareableFileReference for the given path, if no reference
36 // for this path exists returns NULL. 29 // for this path exists returns NULL.
37 static scoped_refptr<ShareableFileReference> Get(const base::FilePath& path); 30 static scoped_refptr<ShareableFileReference> Get(const base::FilePath& path);
38 31
39 // Returns a ShareableFileReference for the given path, creating a new 32 // Returns a ShareableFileReference for the given path, creating a new
40 // reference if none yet exists. If there's a pre-existing reference for 33 // reference if none yet exists. If there's a pre-existing reference for
41 // the path, the deletable parameter of this method is ignored. 34 // the path, the policy parameter of this method is ignored.
42 static scoped_refptr<ShareableFileReference> GetOrCreate( 35 static scoped_refptr<ShareableFileReference> GetOrCreate(
43 const base::FilePath& path, 36 const base::FilePath& path,
44 FinalReleasePolicy policy, 37 FinalReleasePolicy policy,
45 base::TaskRunner* file_task_runner); 38 base::TaskRunner* file_task_runner);
46 39
40 // Returns a ShareableFileReference for the given path of the |scoped_file|,
41 // creating a new reference if none yet exists. The ownership of |scoped_file|
42 // is passed to this reference.
43 // If there's a pre-existing reference for the path, the scope out policy
44 // of the given |scoped_file| is ignored.
45 static scoped_refptr<ShareableFileReference> GetOrCreate(
46 ScopedFile scoped_file);
47
47 // The full file path. 48 // The full file path.
48 const base::FilePath& path() const { return path_; } 49 const base::FilePath& path() const { return scoped_file_.path(); }
49 50
50 // Whether it's to be deleted on final release. 51 // The |callback| is fired when the final reference of this instance
51 FinalReleasePolicy final_release_policy() const { 52 // is released. If release policy is DELETE_ON_FINAL_RELEASE the
52 return final_release_policy_; 53 // callback(s) is/are called before the deletion is scheduled.
michaeln 2013/04/22 21:07:03 is the latter part of the comment is strictly true
kinuko 2013/04/23 06:31:29 Updated the comment.
53 }
54
55 void AddFinalReleaseCallback(const FinalReleaseCallback& callback); 54 void AddFinalReleaseCallback(const FinalReleaseCallback& callback);
56 55
57 private: 56 private:
58 friend class base::RefCounted<ShareableFileReference>; 57 friend class base::RefCounted<ShareableFileReference>;
59 58
60 ShareableFileReference( 59 ShareableFileReference(ScopedFile scoped_file);
61 const base::FilePath& path,
62 FinalReleasePolicy policy,
63 base::TaskRunner* file_task_runner);
64 ~ShareableFileReference(); 60 ~ShareableFileReference();
65 61
66 const base::FilePath path_; 62 ScopedFile scoped_file_;
67 const FinalReleasePolicy final_release_policy_;
68 const scoped_refptr<base::TaskRunner> file_task_runner_;
69 std::vector<FinalReleaseCallback> final_release_callbacks_;
70 63
71 DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); 64 DISALLOW_COPY_AND_ASSIGN(ShareableFileReference);
72 }; 65 };
73 66
74 } // namespace webkit_blob 67 } // namespace webkit_blob
75 68
76 #endif // WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_ 69 #endif // WEBKIT_BLOB_SHAREABLE_FILE_REFERENCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698