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

Side by Side Diff: chrome/browser/browsing_data_file_system_helper.cc

Issue 10600009: Support partitioning of storage contexts based on render_id. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge in unittest fix from jam@ Created 8 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 (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_file_system_helper.h" 5 #include "chrome/browser/browsing_data_file_system_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 void FetchFileSystemInfoInFileThread(); 43 void FetchFileSystemInfoInFileThread();
44 44
45 // Triggers the success callback as the end of a StartFetching workflow. This 45 // Triggers the success callback as the end of a StartFetching workflow. This
46 // must be called on the UI thread. 46 // must be called on the UI thread.
47 void NotifyOnUIThread(); 47 void NotifyOnUIThread();
48 48
49 // Deletes all file systems associated with |origin|. This must be called on 49 // Deletes all file systems associated with |origin|. This must be called on
50 // the FILE thread. 50 // the FILE thread.
51 void DeleteFileSystemOriginInFileThread(const GURL& origin); 51 void DeleteFileSystemOriginInFileThread(const GURL& origin);
52 52
53 // We don't own the Profile object. Clients are responsible for destroying the 53 // Keep a reference to the FileSystemContext object for the current profile
54 // object when it's no longer used. 54 // for use on the FILE thread.
55 Profile* profile_; 55 scoped_refptr<fileapi::FileSystemContext> filesystem_context_;
56 56
57 // Holds the current list of file systems returned to the client after 57 // Holds the current list of file systems returned to the client after
58 // StartFetching is called. Access to |file_system_info_| is triggered 58 // StartFetching is called. Access to |file_system_info_| is triggered
59 // indirectly via the UI thread and guarded by |is_fetching_|. This means 59 // indirectly via the UI thread and guarded by |is_fetching_|. This means
60 // |file_system_info_| is only accessed while |is_fetching_| is true. The 60 // |file_system_info_| is only accessed while |is_fetching_| is true. The
61 // flag |is_fetching_| is only accessed on the UI thread. In the context of 61 // flag |is_fetching_| is only accessed on the UI thread. In the context of
62 // this class |file_system_info_| only mutates on the FILE thread. 62 // this class |file_system_info_| only mutates on the FILE thread.
63 std::list<FileSystemInfo> file_system_info_; 63 std::list<FileSystemInfo> file_system_info_;
64 64
65 // Holds the callback passed in at the beginning of the StartFetching workflow 65 // Holds the callback passed in at the beginning of the StartFetching workflow
66 // so that it can be triggered via NotifyOnUIThread. This only mutates on the 66 // so that it can be triggered via NotifyOnUIThread. This only mutates on the
67 // UI thread. 67 // UI thread.
68 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; 68 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_;
69 69
70 // Indicates whether or not we're currently fetching information: set to true 70 // Indicates whether or not we're currently fetching information: set to true
71 // when StartFetching is called on the UI thread, and reset to false when 71 // when StartFetching is called on the UI thread, and reset to false when
72 // NotifyOnUIThread triggers the success callback. 72 // NotifyOnUIThread triggers the success callback.
73 // This property only mutates on the UI thread. 73 // This property only mutates on the UI thread.
74 bool is_fetching_; 74 bool is_fetching_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); 76 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl);
77 }; 77 };
78 78
79 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( 79 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl(
80 Profile* profile) 80 Profile* profile)
81 : profile_(profile), 81 : filesystem_context_(BrowserContext::GetFileSystemContext(profile)),
82 is_fetching_(false) { 82 is_fetching_(false) {
83 DCHECK(profile_); 83 DCHECK(filesystem_context_);
84 } 84 }
85 85
86 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { 86 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() {
87 } 87 }
88 88
89 void BrowsingDataFileSystemHelperImpl::StartFetching( 89 void BrowsingDataFileSystemHelperImpl::StartFetching(
90 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { 90 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
92 DCHECK(!is_fetching_); 92 DCHECK(!is_fetching_);
93 DCHECK_EQ(false, callback.is_null()); 93 DCHECK_EQ(false, callback.is_null());
(...skipping 12 matching lines...) Expand all
106 BrowserThread::PostTask( 106 BrowserThread::PostTask(
107 BrowserThread::FILE, FROM_HERE, 107 BrowserThread::FILE, FROM_HERE,
108 base::Bind( 108 base::Bind(
109 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, 109 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread,
110 this, origin)); 110 this, origin));
111 } 111 }
112 112
113 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { 113 void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
115 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> 115 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator>
116 origin_enumerator(BrowserContext::GetFileSystemContext(profile_)-> 116 origin_enumerator(filesystem_context_->
117 sandbox_provider()->CreateOriginEnumerator()); 117 sandbox_provider()->CreateOriginEnumerator());
118 118
119 scoped_refptr<fileapi::FileSystemContext> context =
120 BrowserContext::GetFileSystemContext(profile_);
121
122 // We don't own this pointer; it's a magic singleton generated by the 119 // We don't own this pointer; it's a magic singleton generated by the
123 // profile's FileSystemContext. Deleting it would be a bad idea. 120 // profile's FileSystemContext. Deleting it would be a bad idea.
124 fileapi::FileSystemQuotaUtil* quota_util = 121 fileapi::FileSystemQuotaUtil* quota_util =
125 context->GetQuotaUtil(fileapi::kFileSystemTypeTemporary); 122 filesystem_context_->GetQuotaUtil(fileapi::kFileSystemTypeTemporary);
126 123
127 GURL current; 124 GURL current;
128 125
129 while (!(current = origin_enumerator->Next()).is_empty()) { 126 while (!(current = origin_enumerator->Next()).is_empty()) {
130 if (!BrowsingDataHelper::HasWebScheme(current)) 127 if (!BrowsingDataHelper::HasWebScheme(current))
131 continue; // Non-websafe state is not considered browsing data. 128 continue; // Non-websafe state is not considered browsing data.
132 129
133 // We can call these synchronous methods as we've already verified that 130 // We can call these synchronous methods as we've already verified that
134 // we're running on the FILE thread. 131 // we're running on the FILE thread.
135 int64 persistent_usage = quota_util->GetOriginUsageOnFileThread( 132 int64 persistent_usage = quota_util->GetOriginUsageOnFileThread(
136 context, current, 133 filesystem_context_, current,
137 fileapi::kFileSystemTypePersistent); 134 fileapi::kFileSystemTypePersistent);
138 int64 temporary_usage = quota_util->GetOriginUsageOnFileThread( 135 int64 temporary_usage = quota_util->GetOriginUsageOnFileThread(
139 context, current, 136 filesystem_context_, current,
140 fileapi::kFileSystemTypeTemporary); 137 fileapi::kFileSystemTypeTemporary);
141 file_system_info_.push_back( 138 file_system_info_.push_back(
142 FileSystemInfo( 139 FileSystemInfo(
143 current, 140 current,
144 origin_enumerator->HasFileSystemType( 141 origin_enumerator->HasFileSystemType(
145 fileapi::kFileSystemTypePersistent), 142 fileapi::kFileSystemTypePersistent),
146 origin_enumerator->HasFileSystemType( 143 origin_enumerator->HasFileSystemType(
147 fileapi::kFileSystemTypeTemporary), 144 fileapi::kFileSystemTypeTemporary),
148 persistent_usage, 145 persistent_usage,
149 temporary_usage)); 146 temporary_usage));
150 } 147 }
151 148
152 BrowserThread::PostTask( 149 BrowserThread::PostTask(
153 BrowserThread::UI, FROM_HERE, 150 BrowserThread::UI, FROM_HERE,
154 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this)); 151 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this));
155 } 152 }
156 153
157 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { 154 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159 DCHECK(is_fetching_); 156 DCHECK(is_fetching_);
160 completion_callback_.Run(file_system_info_); 157 completion_callback_.Run(file_system_info_);
161 completion_callback_.Reset(); 158 completion_callback_.Reset();
162 is_fetching_ = false; 159 is_fetching_ = false;
163 } 160 }
164 161
165 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( 162 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread(
166 const GURL& origin) { 163 const GURL& origin) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
168 BrowserContext::GetFileSystemContext(profile_)-> 165 filesystem_context_->DeleteDataForOriginOnFileThread(origin);
169 DeleteDataForOriginOnFileThread(origin);
170 } 166 }
171 167
172 } // namespace 168 } // namespace
173 169
174 BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo( 170 BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo(
175 const GURL& origin, 171 const GURL& origin,
176 bool has_persistent, 172 bool has_persistent,
177 bool has_temporary, 173 bool has_temporary,
178 int64 usage_persistent, 174 int64 usage_persistent,
179 int64 usage_temporary) 175 int64 usage_temporary)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::Bind(&CannedBrowsingDataFileSystemHelper::NotifyOnUIThread, this)); 274 base::Bind(&CannedBrowsingDataFileSystemHelper::NotifyOnUIThread, this));
279 } 275 }
280 276
281 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() { 277 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
283 DCHECK(is_fetching_); 279 DCHECK(is_fetching_);
284 completion_callback_.Run(file_system_info_); 280 completion_callback_.Run(file_system_info_);
285 completion_callback_.Reset(); 281 completion_callback_.Reset();
286 is_fetching_ = false; 282 is_fetching_ = false;
287 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698