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

Side by Side Diff: storage/browser/blob/shareable_file_reference.cc

Issue 2912823002: Deprecate NonThreadSafe in storage/browser/blob in favor of SequenceChecker. (Closed)
Patch Set: fully compile out in release builds Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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) 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 #include "storage/browser/blob/shareable_file_reference.h" 5 #include "storage/browser/blob/shareable_file_reference.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/sequence_checker.h"
12 #include "base/task_runner.h" 13 #include "base/task_runner.h"
13 #include "base/threading/non_thread_safe.h"
14 14
15 namespace storage { 15 namespace storage {
16 16
17 namespace { 17 namespace {
18 18
19 // A shareable file map with enforcement of thread checker. 19 // A shareable file map with enforcement of sequence checker.
20 class ShareableFileMap : public base::NonThreadSafe { 20 class ShareableFileMap {
21 public: 21 public:
22 typedef std::map<base::FilePath, ShareableFileReference*> FileMap; 22 typedef std::map<base::FilePath, ShareableFileReference*> FileMap;
23 typedef FileMap::iterator iterator; 23 typedef FileMap::iterator iterator;
24 typedef FileMap::key_type key_type; 24 typedef FileMap::key_type key_type;
25 typedef FileMap::value_type value_type; 25 typedef FileMap::value_type value_type;
26 26
27 ShareableFileMap() {} 27 ShareableFileMap() {}
28 28
29 ~ShareableFileMap() { 29 ~ShareableFileMap() = default;
30 DetachFromThread();
31 }
32 30
33 iterator Find(key_type key) { 31 iterator Find(key_type key) {
34 DCHECK(CalledOnValidThread()); 32 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
35 return file_map_.find(key); 33 return file_map_.find(key);
36 } 34 }
37 35
38 iterator End() { 36 iterator End() {
39 DCHECK(CalledOnValidThread()); 37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
40 return file_map_.end(); 38 return file_map_.end();
41 } 39 }
42 40
43 std::pair<iterator, bool> Insert(value_type value) { 41 std::pair<iterator, bool> Insert(value_type value) {
44 DCHECK(CalledOnValidThread()); 42 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
45 return file_map_.insert(value); 43 return file_map_.insert(value);
46 } 44 }
47 45
48 void Erase(key_type key) { 46 void Erase(key_type key) {
49 DCHECK(CalledOnValidThread()); 47 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
50 file_map_.erase(key); 48 file_map_.erase(key);
51 } 49 }
52 50
51 #if DCHECK_IS_ON()
52 void AssertCalledOnValidSequence() const {
53 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
54 }
55 #endif // DCHECK_IS_ON()
56
53 private: 57 private:
54 FileMap file_map_; 58 FileMap file_map_;
59
60 SEQUENCE_CHECKER(sequence_checker_);
61
55 DISALLOW_COPY_AND_ASSIGN(ShareableFileMap); 62 DISALLOW_COPY_AND_ASSIGN(ShareableFileMap);
56 }; 63 };
57 64
58 base::LazyInstance<ShareableFileMap>::DestructorAtExit g_file_map = 65 base::LazyInstance<ShareableFileMap>::DestructorAtExit g_file_map =
59 LAZY_INSTANCE_INITIALIZER; 66 LAZY_INSTANCE_INITIALIZER;
60 67
61 } // namespace 68 } // namespace
62 69
63 // static 70 // static
64 scoped_refptr<ShareableFileReference> ShareableFileReference::Get( 71 scoped_refptr<ShareableFileReference> ShareableFileReference::Get(
(...skipping 30 matching lines...) Expand all
95 102
96 // Wasn't in the map, create a new reference and store the pointer. 103 // Wasn't in the map, create a new reference and store the pointer.
97 scoped_refptr<ShareableFileReference> reference( 104 scoped_refptr<ShareableFileReference> reference(
98 new ShareableFileReference(std::move(scoped_file))); 105 new ShareableFileReference(std::move(scoped_file)));
99 result.first->second = reference.get(); 106 result.first->second = reference.get();
100 return reference; 107 return reference;
101 } 108 }
102 109
103 void ShareableFileReference::AddFinalReleaseCallback( 110 void ShareableFileReference::AddFinalReleaseCallback(
104 const FinalReleaseCallback& callback) { 111 const FinalReleaseCallback& callback) {
105 DCHECK(g_file_map.Get().CalledOnValidThread()); 112 #if DCHECK_IS_ON()
113 g_file_map.Get().AssertCalledOnValidSequence();
114 #endif // DCHECK_IS_ON()
106 scoped_file_.AddScopeOutCallback(callback, NULL); 115 scoped_file_.AddScopeOutCallback(callback, NULL);
107 } 116 }
108 117
109 ShareableFileReference::ShareableFileReference(ScopedFile scoped_file) 118 ShareableFileReference::ShareableFileReference(ScopedFile scoped_file)
110 : scoped_file_(std::move(scoped_file)) { 119 : scoped_file_(std::move(scoped_file)) {
111 DCHECK(g_file_map.Get().Find(path())->second == NULL); 120 DCHECK(g_file_map.Get().Find(path())->second == NULL);
112 } 121 }
113 122
114 ShareableFileReference::~ShareableFileReference() { 123 ShareableFileReference::~ShareableFileReference() {
115 DCHECK(g_file_map.Get().Find(path())->second == this); 124 DCHECK(g_file_map.Get().Find(path())->second == this);
116 g_file_map.Get().Erase(path()); 125 g_file_map.Get().Erase(path());
117 } 126 }
118 127
119 } // namespace storage 128 } // namespace storage
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698