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 "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "storage/browser/fileapi/file_system_context.h" |
18 #include "webkit/browser/fileapi/file_system_quota_util.h" | 18 #include "storage/browser/fileapi/file_system_quota_util.h" |
19 #include "webkit/common/fileapi/file_system_types.h" | 19 #include "storage/common/fileapi/file_system_types.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 | 22 |
23 namespace fileapi { | 23 namespace storage { |
24 class FileSystemContext; | 24 class FileSystemContext; |
25 } | 25 } |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // An implementation of the BrowsingDataFileSystemHelper interface that pulls | 29 // An implementation of the BrowsingDataFileSystemHelper interface that pulls |
30 // data from a given |filesystem_context| and returns a list of FileSystemInfo | 30 // data from a given |filesystem_context| and returns a list of FileSystemInfo |
31 // items to a client. | 31 // items to a client. |
32 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { | 32 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { |
33 public: | 33 public: |
34 // BrowsingDataFileSystemHelper implementation | 34 // BrowsingDataFileSystemHelper implementation |
35 explicit BrowsingDataFileSystemHelperImpl( | 35 explicit BrowsingDataFileSystemHelperImpl( |
36 fileapi::FileSystemContext* filesystem_context); | 36 storage::FileSystemContext* filesystem_context); |
37 virtual void StartFetching(const base::Callback< | 37 virtual void StartFetching(const base::Callback< |
38 void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; | 38 void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; |
39 virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE; | 39 virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE; |
40 | 40 |
41 private: | 41 private: |
42 virtual ~BrowsingDataFileSystemHelperImpl(); | 42 virtual ~BrowsingDataFileSystemHelperImpl(); |
43 | 43 |
44 // Enumerates all filesystem files, storing the resulting list into | 44 // Enumerates all filesystem files, storing the resulting list into |
45 // file_system_file_ for later use. This must be called on the file | 45 // file_system_file_ for later use. This must be called on the file |
46 // task runner. | 46 // task runner. |
47 void FetchFileSystemInfoInFileThread(); | 47 void FetchFileSystemInfoInFileThread(); |
48 | 48 |
49 // Triggers the success callback as the end of a StartFetching workflow. This | 49 // Triggers the success callback as the end of a StartFetching workflow. This |
50 // must be called on the UI thread. | 50 // must be called on the UI thread. |
51 void NotifyOnUIThread(); | 51 void NotifyOnUIThread(); |
52 | 52 |
53 // Deletes all file systems associated with |origin|. This must be called on | 53 // Deletes all file systems associated with |origin|. This must be called on |
54 // the file task runner. | 54 // the file task runner. |
55 void DeleteFileSystemOriginInFileThread(const GURL& origin); | 55 void DeleteFileSystemOriginInFileThread(const GURL& origin); |
56 | 56 |
57 // Returns the file task runner for the |filesystem_context_|. | 57 // Returns the file task runner for the |filesystem_context_|. |
58 base::SequencedTaskRunner* file_task_runner() { | 58 base::SequencedTaskRunner* file_task_runner() { |
59 return filesystem_context_->default_file_task_runner(); | 59 return filesystem_context_->default_file_task_runner(); |
60 } | 60 } |
61 | 61 |
62 // Keep a reference to the FileSystemContext object for the current profile | 62 // Keep a reference to the FileSystemContext object for the current profile |
63 // for use on the file task runner. | 63 // for use on the file task runner. |
64 scoped_refptr<fileapi::FileSystemContext> filesystem_context_; | 64 scoped_refptr<storage::FileSystemContext> filesystem_context_; |
65 | 65 |
66 // Holds the current list of file systems returned to the client after | 66 // Holds the current list of file systems returned to the client after |
67 // StartFetching is called. Access to |file_system_info_| is triggered | 67 // StartFetching is called. Access to |file_system_info_| is triggered |
68 // indirectly via the UI thread and guarded by |is_fetching_|. This means | 68 // indirectly via the UI thread and guarded by |is_fetching_|. This means |
69 // |file_system_info_| is only accessed while |is_fetching_| is true. The | 69 // |file_system_info_| is only accessed while |is_fetching_| is true. The |
70 // flag |is_fetching_| is only accessed on the UI thread. In the context of | 70 // flag |is_fetching_| is only accessed on the UI thread. In the context of |
71 // this class |file_system_info_| only mutates on the file task runner. | 71 // this class |file_system_info_| only mutates on the file task runner. |
72 std::list<FileSystemInfo> file_system_info_; | 72 std::list<FileSystemInfo> file_system_info_; |
73 | 73 |
74 // Holds the callback passed in at the beginning of the StartFetching workflow | 74 // Holds the callback passed in at the beginning of the StartFetching workflow |
75 // so that it can be triggered via NotifyOnUIThread. This only mutates on the | 75 // so that it can be triggered via NotifyOnUIThread. This only mutates on the |
76 // UI thread. | 76 // UI thread. |
77 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; | 77 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; |
78 | 78 |
79 // Indicates whether or not we're currently fetching information: set to true | 79 // Indicates whether or not we're currently fetching information: set to true |
80 // when StartFetching is called on the UI thread, and reset to false when | 80 // when StartFetching is called on the UI thread, and reset to false when |
81 // NotifyOnUIThread triggers the success callback. | 81 // NotifyOnUIThread triggers the success callback. |
82 // This property only mutates on the UI thread. | 82 // This property only mutates on the UI thread. |
83 bool is_fetching_; | 83 bool is_fetching_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); | 85 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); |
86 }; | 86 }; |
87 | 87 |
88 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( | 88 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( |
89 fileapi::FileSystemContext* filesystem_context) | 89 storage::FileSystemContext* filesystem_context) |
90 : filesystem_context_(filesystem_context), | 90 : filesystem_context_(filesystem_context), is_fetching_(false) { |
91 is_fetching_(false) { | |
92 DCHECK(filesystem_context_.get()); | 91 DCHECK(filesystem_context_.get()); |
93 } | 92 } |
94 | 93 |
95 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { | 94 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { |
96 } | 95 } |
97 | 96 |
98 void BrowsingDataFileSystemHelperImpl::StartFetching( | 97 void BrowsingDataFileSystemHelperImpl::StartFetching( |
99 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { | 98 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
101 DCHECK(!is_fetching_); | 100 DCHECK(!is_fetching_); |
(...skipping 14 matching lines...) Expand all Loading... |
116 FROM_HERE, | 115 FROM_HERE, |
117 base::Bind( | 116 base::Bind( |
118 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, | 117 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, |
119 this, origin)); | 118 this, origin)); |
120 } | 119 } |
121 | 120 |
122 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { | 121 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { |
123 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); | 122 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); |
124 | 123 |
125 // We check usage for these filesystem types. | 124 // We check usage for these filesystem types. |
126 const fileapi::FileSystemType types[] = { | 125 const storage::FileSystemType types[] = { |
127 fileapi::kFileSystemTypeTemporary, | 126 storage::kFileSystemTypeTemporary, |
128 fileapi::kFileSystemTypePersistent, | 127 storage::kFileSystemTypePersistent, |
129 #if defined(ENABLE_EXTENSIONS) | 128 #if defined(ENABLE_EXTENSIONS) |
130 fileapi::kFileSystemTypeSyncable, | 129 storage::kFileSystemTypeSyncable, |
131 #endif | 130 #endif |
132 }; | 131 }; |
133 | 132 |
134 typedef std::map<GURL, FileSystemInfo> OriginInfoMap; | 133 typedef std::map<GURL, FileSystemInfo> OriginInfoMap; |
135 OriginInfoMap file_system_info_map; | 134 OriginInfoMap file_system_info_map; |
136 for (size_t i = 0; i < arraysize(types); ++i) { | 135 for (size_t i = 0; i < arraysize(types); ++i) { |
137 fileapi::FileSystemType type = types[i]; | 136 storage::FileSystemType type = types[i]; |
138 fileapi::FileSystemQuotaUtil* quota_util = | 137 storage::FileSystemQuotaUtil* quota_util = |
139 filesystem_context_->GetQuotaUtil(type); | 138 filesystem_context_->GetQuotaUtil(type); |
140 DCHECK(quota_util); | 139 DCHECK(quota_util); |
141 std::set<GURL> origins; | 140 std::set<GURL> origins; |
142 quota_util->GetOriginsForTypeOnFileTaskRunner(type, &origins); | 141 quota_util->GetOriginsForTypeOnFileTaskRunner(type, &origins); |
143 for (std::set<GURL>::iterator iter = origins.begin(); | 142 for (std::set<GURL>::iterator iter = origins.begin(); |
144 iter != origins.end(); ++iter) { | 143 iter != origins.end(); ++iter) { |
145 const GURL& current = *iter; | 144 const GURL& current = *iter; |
146 if (!BrowsingDataHelper::HasWebScheme(current)) | 145 if (!BrowsingDataHelper::HasWebScheme(current)) |
147 continue; // Non-websafe state is not considered browsing data. | 146 continue; // Non-websafe state is not considered browsing data. |
148 int64 usage = quota_util->GetOriginUsageOnFileTaskRunner( | 147 int64 usage = quota_util->GetOriginUsageOnFileTaskRunner( |
149 filesystem_context_.get(), current, type); | 148 filesystem_context_.get(), current, type); |
(...skipping 30 matching lines...) Expand all Loading... |
180 | 179 |
181 } // namespace | 180 } // namespace |
182 | 181 |
183 BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo( | 182 BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo( |
184 const GURL& origin) : origin(origin) {} | 183 const GURL& origin) : origin(origin) {} |
185 | 184 |
186 BrowsingDataFileSystemHelper::FileSystemInfo::~FileSystemInfo() {} | 185 BrowsingDataFileSystemHelper::FileSystemInfo::~FileSystemInfo() {} |
187 | 186 |
188 // static | 187 // static |
189 BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create( | 188 BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create( |
190 fileapi::FileSystemContext* filesystem_context) { | 189 storage::FileSystemContext* filesystem_context) { |
191 return new BrowsingDataFileSystemHelperImpl(filesystem_context); | 190 return new BrowsingDataFileSystemHelperImpl(filesystem_context); |
192 } | 191 } |
193 | 192 |
194 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper( | 193 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper( |
195 Profile* profile) { | 194 Profile* profile) { |
196 } | 195 } |
197 | 196 |
198 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper() { | 197 CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper() { |
199 } | 198 } |
200 | 199 |
201 CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {} | 200 CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {} |
202 | 201 |
203 CannedBrowsingDataFileSystemHelper* | 202 CannedBrowsingDataFileSystemHelper* |
204 CannedBrowsingDataFileSystemHelper::Clone() { | 203 CannedBrowsingDataFileSystemHelper::Clone() { |
205 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
206 CannedBrowsingDataFileSystemHelper* clone = | 205 CannedBrowsingDataFileSystemHelper* clone = |
207 new CannedBrowsingDataFileSystemHelper(); | 206 new CannedBrowsingDataFileSystemHelper(); |
208 // This list only mutates on the UI thread, so it's safe to work with it here | 207 // This list only mutates on the UI thread, so it's safe to work with it here |
209 // (given the DCHECK above). | 208 // (given the DCHECK above). |
210 clone->file_system_info_ = file_system_info_; | 209 clone->file_system_info_ = file_system_info_; |
211 return clone; | 210 return clone; |
212 } | 211 } |
213 | 212 |
214 void CannedBrowsingDataFileSystemHelper::AddFileSystem( | 213 void CannedBrowsingDataFileSystemHelper::AddFileSystem( |
215 const GURL& origin, const fileapi::FileSystemType type, const int64 size) { | 214 const GURL& origin, |
| 215 const storage::FileSystemType type, |
| 216 const int64 size) { |
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
217 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which | 218 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which |
218 // is fine, as it isn't meant for use in a high-volume context. If it turns | 219 // is fine, as it isn't meant for use in a high-volume context. If it turns |
219 // out that we want to start using this in a context with many, many origins, | 220 // out that we want to start using this in a context with many, many origins, |
220 // we should think about reworking the implementation. | 221 // we should think about reworking the implementation. |
221 bool duplicate_origin = false; | 222 bool duplicate_origin = false; |
222 for (std::list<FileSystemInfo>::iterator | 223 for (std::list<FileSystemInfo>::iterator |
223 file_system = file_system_info_.begin(); | 224 file_system = file_system_info_.begin(); |
224 file_system != file_system_info_.end(); | 225 file_system != file_system_info_.end(); |
225 ++file_system) { | 226 ++file_system) { |
(...skipping 28 matching lines...) Expand all Loading... |
254 } | 255 } |
255 | 256 |
256 void CannedBrowsingDataFileSystemHelper::StartFetching( | 257 void CannedBrowsingDataFileSystemHelper::StartFetching( |
257 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { | 258 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 259 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
259 DCHECK(!callback.is_null()); | 260 DCHECK(!callback.is_null()); |
260 | 261 |
261 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
262 BrowserThread::UI, FROM_HERE, base::Bind(callback, file_system_info_)); | 263 BrowserThread::UI, FROM_HERE, base::Bind(callback, file_system_info_)); |
263 } | 264 } |
OLD | NEW |