OLD | NEW |
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/fileapi/file_system_quota_client.h" | 5 #include "storage/browser/fileapi/file_system_quota_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 107 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
108 DCHECK(type != kFileSystemTypeUnknown); | 108 DCHECK(type != kFileSystemTypeUnknown); |
109 | 109 |
110 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type); | 110 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type); |
111 if (!quota_util) { | 111 if (!quota_util) { |
112 callback.Run(0); | 112 callback.Run(0); |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 base::PostTaskAndReplyWithResult( | 116 base::PostTaskAndReplyWithResult( |
117 file_task_runner(), | 117 file_task_runner(), FROM_HERE, |
118 FROM_HERE, | |
119 // It is safe to pass Unretained(quota_util) since context owns it. | 118 // It is safe to pass Unretained(quota_util) since context owns it. |
120 base::Bind(&FileSystemQuotaUtil::GetOriginUsageOnFileTaskRunner, | 119 base::Bind(&FileSystemQuotaUtil::GetOriginUsageOnFileTaskRunner, |
121 base::Unretained(quota_util), | 120 base::Unretained(quota_util), |
122 file_system_context_, | 121 base::RetainedRef(file_system_context_), origin_url, type), |
123 origin_url, | |
124 type), | |
125 callback); | 122 callback); |
126 } | 123 } |
127 | 124 |
128 void FileSystemQuotaClient::GetOriginsForType( | 125 void FileSystemQuotaClient::GetOriginsForType( |
129 StorageType storage_type, | 126 StorageType storage_type, |
130 const GetOriginsCallback& callback) { | 127 const GetOriginsCallback& callback) { |
131 DCHECK(!callback.is_null()); | 128 DCHECK(!callback.is_null()); |
132 | 129 |
133 if (is_incognito_) { | 130 if (is_incognito_) { |
134 // We don't support FileSystem in incognito mode yet. | 131 // We don't support FileSystem in incognito mode yet. |
135 std::set<GURL> origins; | 132 std::set<GURL> origins; |
136 callback.Run(origins); | 133 callback.Run(origins); |
137 return; | 134 return; |
138 } | 135 } |
139 | 136 |
140 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 137 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
141 file_task_runner()->PostTaskAndReply( | 138 file_task_runner()->PostTaskAndReply( |
142 FROM_HERE, | 139 FROM_HERE, base::Bind(&GetOriginsForTypeOnFileTaskRunner, |
143 base::Bind(&GetOriginsForTypeOnFileTaskRunner, | 140 base::RetainedRef(file_system_context_), |
144 file_system_context_, | 141 storage_type, base::Unretained(origins_ptr)), |
145 storage_type, | 142 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
146 base::Unretained(origins_ptr)), | |
147 base::Bind(&DidGetOrigins, | |
148 callback, | |
149 base::Owned(origins_ptr))); | |
150 } | 143 } |
151 | 144 |
152 void FileSystemQuotaClient::GetOriginsForHost( | 145 void FileSystemQuotaClient::GetOriginsForHost( |
153 StorageType storage_type, | 146 StorageType storage_type, |
154 const std::string& host, | 147 const std::string& host, |
155 const GetOriginsCallback& callback) { | 148 const GetOriginsCallback& callback) { |
156 DCHECK(!callback.is_null()); | 149 DCHECK(!callback.is_null()); |
157 | 150 |
158 if (is_incognito_) { | 151 if (is_incognito_) { |
159 // We don't support FileSystem in incognito mode yet. | 152 // We don't support FileSystem in incognito mode yet. |
160 std::set<GURL> origins; | 153 std::set<GURL> origins; |
161 callback.Run(origins); | 154 callback.Run(origins); |
162 return; | 155 return; |
163 } | 156 } |
164 | 157 |
165 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 158 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
166 file_task_runner()->PostTaskAndReply( | 159 file_task_runner()->PostTaskAndReply( |
167 FROM_HERE, | 160 FROM_HERE, base::Bind(&GetOriginsForHostOnFileTaskRunner, |
168 base::Bind(&GetOriginsForHostOnFileTaskRunner, | 161 base::RetainedRef(file_system_context_), |
169 file_system_context_, | 162 storage_type, host, base::Unretained(origins_ptr)), |
170 storage_type, | 163 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
171 host, | |
172 base::Unretained(origins_ptr)), | |
173 base::Bind(&DidGetOrigins, | |
174 callback, | |
175 base::Owned(origins_ptr))); | |
176 } | 164 } |
177 | 165 |
178 void FileSystemQuotaClient::DeleteOriginData( | 166 void FileSystemQuotaClient::DeleteOriginData( |
179 const GURL& origin, | 167 const GURL& origin, |
180 StorageType type, | 168 StorageType type, |
181 const DeletionCallback& callback) { | 169 const DeletionCallback& callback) { |
182 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 170 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
183 DCHECK(fs_type != kFileSystemTypeUnknown); | 171 DCHECK(fs_type != kFileSystemTypeUnknown); |
184 | 172 |
185 base::PostTaskAndReplyWithResult( | 173 base::PostTaskAndReplyWithResult( |
186 file_task_runner(), | 174 file_task_runner(), FROM_HERE, |
187 FROM_HERE, | |
188 base::Bind(&DeleteOriginOnFileTaskRunner, | 175 base::Bind(&DeleteOriginOnFileTaskRunner, |
189 file_system_context_, | 176 base::RetainedRef(file_system_context_), origin, fs_type), |
190 origin, | |
191 fs_type), | |
192 callback); | 177 callback); |
193 } | 178 } |
194 | 179 |
195 bool FileSystemQuotaClient::DoesSupport( | 180 bool FileSystemQuotaClient::DoesSupport( |
196 storage::StorageType storage_type) const { | 181 storage::StorageType storage_type) const { |
197 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 182 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
198 DCHECK(type != kFileSystemTypeUnknown); | 183 DCHECK(type != kFileSystemTypeUnknown); |
199 return file_system_context_->IsSandboxFileSystem(type); | 184 return file_system_context_->IsSandboxFileSystem(type); |
200 } | 185 } |
201 | 186 |
202 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { | 187 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { |
203 return file_system_context_->default_file_task_runner(); | 188 return file_system_context_->default_file_task_runner(); |
204 } | 189 } |
205 | 190 |
206 } // namespace storage | 191 } // namespace storage |
OLD | NEW |