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

Side by Side Diff: storage/browser/blob/scoped_file.h

Issue 1407443002: Remove old C++03 move emulation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::move and reflow Created 5 years 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
« no previous file with comments | « remoting/base/typed_buffer.h ('k') | storage/browser/blob/scoped_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ 5 #ifndef STORAGE_BROWSER_BLOB_SCOPED_FILE_H_
6 #define STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ 6 #define STORAGE_BROWSER_BLOB_SCOPED_FILE_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/move.h" 13 #include "base/move.h"
14 #include "storage/browser/storage_browser_export.h" 14 #include "storage/browser/storage_browser_export.h"
15 15
16 namespace base { 16 namespace base {
17 class TaskRunner; 17 class TaskRunner;
18 } 18 }
19 19
20 namespace storage { 20 namespace storage {
21 21
22 // A scoped reference for a FilePath that can optionally schedule the file 22 // A scoped reference for a FilePath that can optionally schedule the file
23 // to be deleted and/or to notify a consumer when it is going to be scoped out. 23 // to be deleted and/or to notify a consumer when it is going to be scoped out.
24 // This class supports move semantics, i.e. consumers can call Pass() to 24 // This class supports move semantics, i.e. consumers can call Pass() to
25 // pass the ownership of ScopedFile. 25 // pass the ownership of ScopedFile.
26 // 26 //
27 // TODO(kinuko): Probably this can be moved under base or somewhere more 27 // TODO(kinuko): Probably this can be moved under base or somewhere more
28 // common place. 28 // common place.
29 class STORAGE_EXPORT ScopedFile { 29 class STORAGE_EXPORT ScopedFile {
30 // To support destructive assignment from an l-value assignment. 30 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedFile)
31 // This provides Pass() method which creates an r-value for the current
32 // instance. (See base/move.h for details)
33 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedFile, RValue)
34 31
35 public: 32 public:
36 typedef base::Callback<void(const base::FilePath&)> ScopeOutCallback; 33 typedef base::Callback<void(const base::FilePath&)> ScopeOutCallback;
37 typedef std::pair<ScopeOutCallback, scoped_refptr<base::TaskRunner> > 34 typedef std::pair<ScopeOutCallback, scoped_refptr<base::TaskRunner> >
38 ScopeOutCallbackPair; 35 ScopeOutCallbackPair;
39 typedef std::vector<ScopeOutCallbackPair> ScopeOutCallbackList; 36 typedef std::vector<ScopeOutCallbackPair> ScopeOutCallbackList;
40 37
41 enum ScopeOutPolicy { 38 enum ScopeOutPolicy {
42 DELETE_ON_SCOPE_OUT, 39 DELETE_ON_SCOPE_OUT,
43 DONT_DELETE_ON_SCOPE_OUT, 40 DONT_DELETE_ON_SCOPE_OUT,
44 }; 41 };
45 42
46 ScopedFile(); 43 ScopedFile();
47 44
48 // |file_task_runner| is used to schedule a file deletion if |policy| 45 // |file_task_runner| is used to schedule a file deletion if |policy|
49 // is DELETE_ON_SCOPE_OUT. 46 // is DELETE_ON_SCOPE_OUT.
50 ScopedFile(const base::FilePath& path, 47 ScopedFile(const base::FilePath& path,
51 ScopeOutPolicy policy, 48 ScopeOutPolicy policy,
52 const scoped_refptr<base::TaskRunner>& file_task_runner); 49 const scoped_refptr<base::TaskRunner>& file_task_runner);
53 50
54 // Move constructor and operator. The data of r-value will be transfered 51 // Move constructor and operator. The data of r-value will be transfered
55 // in a destructive way. (See base/move.h) 52 // in a destructive way. (See base/move.h)
56 ScopedFile(RValue other); 53 ScopedFile(ScopedFile&& other);
57 ScopedFile& operator=(RValue rhs) { 54 ScopedFile& operator=(ScopedFile&& rhs) {
58 MoveFrom(*rhs.object); 55 MoveFrom(rhs);
59 return *this; 56 return *this;
60 } 57 }
61 58
62 ~ScopedFile(); 59 ~ScopedFile();
63 60
64 // The |callback| is fired on |callback_runner| when the final reference 61 // The |callback| is fired on |callback_runner| when the final reference
65 // of this instance is released. 62 // of this instance is released.
66 // If release policy is DELETE_ON_SCOPE_OUT the 63 // If release policy is DELETE_ON_SCOPE_OUT the
67 // callback task(s) is/are posted before the deletion is scheduled. 64 // callback task(s) is/are posted before the deletion is scheduled.
68 void AddScopeOutCallback(const ScopeOutCallback& callback, 65 void AddScopeOutCallback(const ScopeOutCallback& callback,
(...skipping 16 matching lines...) Expand all
85 82
86 base::FilePath path_; 83 base::FilePath path_;
87 ScopeOutPolicy scope_out_policy_; 84 ScopeOutPolicy scope_out_policy_;
88 scoped_refptr<base::TaskRunner> file_task_runner_; 85 scoped_refptr<base::TaskRunner> file_task_runner_;
89 ScopeOutCallbackList scope_out_callbacks_; 86 ScopeOutCallbackList scope_out_callbacks_;
90 }; 87 };
91 88
92 } // namespace storage 89 } // namespace storage
93 90
94 #endif // STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ 91 #endif // STORAGE_BROWSER_BLOB_SCOPED_FILE_H_
OLDNEW
« no previous file with comments | « remoting/base/typed_buffer.h ('k') | storage/browser/blob/scoped_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698