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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_status.cc

Issue 2129083002: Explicitly check various sync_file_system classes live on the IO thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests, remove unneeded check Created 4 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" 5 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/public/browser/browser_thread.h"
9 #include "storage/common/fileapi/file_system_util.h" 10 #include "storage/common/fileapi/file_system_util.h"
10 11
11 using storage::FileSystemURL; 12 using storage::FileSystemURL;
12 using storage::FileSystemURLSet; 13 using storage::FileSystemURLSet;
13 14
14 namespace sync_file_system { 15 namespace sync_file_system {
15 16
16 namespace { 17 namespace {
17 18
18 typedef LocalFileSyncStatus::OriginAndType OriginAndType; 19 using OriginAndType = LocalFileSyncStatus::OriginAndType;
19 20
20 OriginAndType GetOriginAndType(const storage::FileSystemURL& url) { 21 OriginAndType GetOriginAndType(const storage::FileSystemURL& url) {
21 return std::make_pair(url.origin(), url.type()); 22 return std::make_pair(url.origin(), url.type());
22 } 23 }
23 24
24 base::FilePath NormalizePath(const base::FilePath& path) { 25 base::FilePath NormalizePath(const base::FilePath& path) {
25 // Ensure |path| has single trailing path-separator, so that we can use 26 // Ensure |path| has single trailing path-separator, so that we can use
26 // prefix-match to find descendants of |path| in an ordered container. 27 // prefix-match to find descendants of |path| in an ordered container.
27 return base::FilePath(path.StripTrailingSeparators().value() + 28 return base::FilePath(path.StripTrailingSeparators().value() +
28 storage::VirtualPath::kSeparator); 29 storage::VirtualPath::kSeparator);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 72 }
72 } 73 }
73 74
74 } // namespace 75 } // namespace
75 76
76 LocalFileSyncStatus::LocalFileSyncStatus() {} 77 LocalFileSyncStatus::LocalFileSyncStatus() {}
77 78
78 LocalFileSyncStatus::~LocalFileSyncStatus() {} 79 LocalFileSyncStatus::~LocalFileSyncStatus() {}
79 80
80 void LocalFileSyncStatus::StartWriting(const FileSystemURL& url) { 81 void LocalFileSyncStatus::StartWriting(const FileSystemURL& url) {
81 DCHECK(CalledOnValidThread()); 82 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
82 DCHECK(!IsChildOrParentSyncing(url)); 83 DCHECK(!IsChildOrParentSyncing(url));
83 writing_[GetOriginAndType(url)][NormalizePath(url.path())]++; 84 writing_[GetOriginAndType(url)][NormalizePath(url.path())]++;
84 } 85 }
85 86
86 void LocalFileSyncStatus::EndWriting(const FileSystemURL& url) { 87 void LocalFileSyncStatus::EndWriting(const FileSystemURL& url) {
87 DCHECK(CalledOnValidThread()); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
88 base::FilePath normalized_path = NormalizePath(url.path()); 89 base::FilePath normalized_path = NormalizePath(url.path());
89 OriginAndType origin_and_type = GetOriginAndType(url); 90 OriginAndType origin_and_type = GetOriginAndType(url);
90 91
91 int count = --writing_[origin_and_type][normalized_path]; 92 int count = --writing_[origin_and_type][normalized_path];
92 if (count == 0) { 93 if (count == 0) {
93 writing_[origin_and_type].erase(normalized_path); 94 writing_[origin_and_type].erase(normalized_path);
94 if (writing_[origin_and_type].empty()) 95 if (writing_[origin_and_type].empty())
95 writing_.erase(origin_and_type); 96 writing_.erase(origin_and_type);
96 FOR_EACH_OBSERVER(Observer, observer_list_, OnSyncEnabled(url)); 97 FOR_EACH_OBSERVER(Observer, observer_list_, OnSyncEnabled(url));
97 } 98 }
98 } 99 }
99 100
100 void LocalFileSyncStatus::StartSyncing(const FileSystemURL& url) { 101 void LocalFileSyncStatus::StartSyncing(const FileSystemURL& url) {
101 DCHECK(CalledOnValidThread()); 102 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
102 DCHECK(!IsChildOrParentWriting(url)); 103 DCHECK(!IsChildOrParentWriting(url));
103 DCHECK(!IsChildOrParentSyncing(url)); 104 DCHECK(!IsChildOrParentSyncing(url));
104 syncing_[GetOriginAndType(url)].insert(NormalizePath(url.path())); 105 syncing_[GetOriginAndType(url)].insert(NormalizePath(url.path()));
105 } 106 }
106 107
107 void LocalFileSyncStatus::EndSyncing(const FileSystemURL& url) { 108 void LocalFileSyncStatus::EndSyncing(const FileSystemURL& url) {
108 DCHECK(CalledOnValidThread()); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
109 base::FilePath normalized_path = NormalizePath(url.path()); 110 base::FilePath normalized_path = NormalizePath(url.path());
110 OriginAndType origin_and_type = GetOriginAndType(url); 111 OriginAndType origin_and_type = GetOriginAndType(url);
111 112
112 syncing_[origin_and_type].erase(normalized_path); 113 syncing_[origin_and_type].erase(normalized_path);
113 if (syncing_[origin_and_type].empty()) 114 if (syncing_[origin_and_type].empty())
114 syncing_.erase(origin_and_type); 115 syncing_.erase(origin_and_type);
115 FOR_EACH_OBSERVER(Observer, observer_list_, OnSyncEnabled(url)); 116 FOR_EACH_OBSERVER(Observer, observer_list_, OnSyncEnabled(url));
116 FOR_EACH_OBSERVER(Observer, observer_list_, OnWriteEnabled(url)); 117 FOR_EACH_OBSERVER(Observer, observer_list_, OnWriteEnabled(url));
117 } 118 }
118 119
119 bool LocalFileSyncStatus::IsWriting(const FileSystemURL& url) const { 120 bool LocalFileSyncStatus::IsWriting(const FileSystemURL& url) const {
120 DCHECK(CalledOnValidThread()); 121 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
121 return IsChildOrParentWriting(url); 122 return IsChildOrParentWriting(url);
122 } 123 }
123 124
124 bool LocalFileSyncStatus::IsWritable(const FileSystemURL& url) const { 125 bool LocalFileSyncStatus::IsWritable(const FileSystemURL& url) const {
125 DCHECK(CalledOnValidThread()); 126 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
126 return !IsChildOrParentSyncing(url); 127 return !IsChildOrParentSyncing(url);
127 } 128 }
128 129
129 bool LocalFileSyncStatus::IsSyncable(const FileSystemURL& url) const { 130 bool LocalFileSyncStatus::IsSyncable(const FileSystemURL& url) const {
130 DCHECK(CalledOnValidThread()); 131 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
131 return !IsChildOrParentSyncing(url) && !IsChildOrParentWriting(url); 132 return !IsChildOrParentSyncing(url) && !IsChildOrParentWriting(url);
132 } 133 }
133 134
134 void LocalFileSyncStatus::AddObserver(Observer* observer) { 135 void LocalFileSyncStatus::AddObserver(Observer* observer) {
135 DCHECK(CalledOnValidThread()); 136 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
136 observer_list_.AddObserver(observer); 137 observer_list_.AddObserver(observer);
137 } 138 }
138 139
139 void LocalFileSyncStatus::RemoveObserver(Observer* observer) { 140 void LocalFileSyncStatus::RemoveObserver(Observer* observer) {
140 DCHECK(CalledOnValidThread()); 141 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
141 observer_list_.RemoveObserver(observer); 142 observer_list_.RemoveObserver(observer);
142 } 143 }
143 144
144 bool LocalFileSyncStatus::IsChildOrParentWriting( 145 bool LocalFileSyncStatus::IsChildOrParentWriting(
145 const FileSystemURL& url) const { 146 const FileSystemURL& url) const {
146 DCHECK(CalledOnValidThread()); 147 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
147 148
148 URLBucket::const_iterator found = writing_.find(GetOriginAndType(url)); 149 URLBucket::const_iterator found = writing_.find(GetOriginAndType(url));
149 if (found == writing_.end()) 150 if (found == writing_.end())
150 return false; 151 return false;
151 return ContainsChildOrParent(found->second, url.path(), 152 return ContainsChildOrParent(found->second, url.path(),
152 MapKeyHelper()); 153 MapKeyHelper());
153 } 154 }
154 155
155 bool LocalFileSyncStatus::IsChildOrParentSyncing( 156 bool LocalFileSyncStatus::IsChildOrParentSyncing(
156 const FileSystemURL& url) const { 157 const FileSystemURL& url) const {
157 DCHECK(CalledOnValidThread()); 158 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
158 URLSet::const_iterator found = syncing_.find(GetOriginAndType(url)); 159 URLSet::const_iterator found = syncing_.find(GetOriginAndType(url));
159 if (found == syncing_.end()) 160 if (found == syncing_.end())
160 return false; 161 return false;
161 return ContainsChildOrParent(found->second, url.path(), 162 return ContainsChildOrParent(found->second, url.path(),
162 SetKeyHelper()); 163 SetKeyHelper());
163 } 164 }
164 165
165 } // namespace sync_file_system 166 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698