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

Side by Side Diff: webkit/appcache/appcache_database.cc

Issue 7031065: AppCache + Quota integration (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "webkit/appcache/appcache_database.h" 5 #include "webkit/appcache/appcache_database.h"
6 6
7 #include "app/sql/connection.h" 7 #include "app/sql/connection.h"
8 #include "app/sql/diagnostic_error_delegate.h" 8 #include "app/sql/diagnostic_error_delegate.h"
9 #include "app/sql/meta_table.h" 9 #include "app/sql/meta_table.h"
10 #include "app/sql/statement.h" 10 #include "app/sql/statement.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!db_file_path_.empty()) 175 if (!db_file_path_.empty())
176 ResetConnectionAndTables(); 176 ResetConnectionAndTables();
177 } 177 }
178 178
179 void AppCacheDatabase::Disable() { 179 void AppCacheDatabase::Disable() {
180 VLOG(1) << "Disabling appcache database."; 180 VLOG(1) << "Disabling appcache database.";
181 is_disabled_ = true; 181 is_disabled_ = true;
182 ResetConnectionAndTables(); 182 ResetConnectionAndTables();
183 } 183 }
184 184
185 // TODO(michaeln): remove me
186 int64 AppCacheDatabase::GetOriginQuota(const GURL& origin) {
187 if (!LazyOpen(false))
188 return GetDefaultOriginQuota();
189 int64 quota = quota_table_->GetOriginQuota(
190 UTF8ToUTF16(origin.spec().c_str()));
191 return (quota >= 0) ? quota : GetDefaultOriginQuota();
192 }
193
185 int64 AppCacheDatabase::GetOriginUsage(const GURL& origin) { 194 int64 AppCacheDatabase::GetOriginUsage(const GURL& origin) {
186 std::vector<CacheRecord> records; 195 std::vector<CacheRecord> records;
187 if (!FindCachesForOrigin(origin, &records)) 196 if (!FindCachesForOrigin(origin, &records))
188 return 0; 197 return 0;
189 198
190 int64 origin_usage = 0; 199 int64 origin_usage = 0;
191 std::vector<CacheRecord>::const_iterator iter = records.begin(); 200 std::vector<CacheRecord>::const_iterator iter = records.begin();
192 while (iter != records.end()) { 201 while (iter != records.end()) {
193 origin_usage += iter->cache_size; 202 origin_usage += iter->cache_size;
194 ++iter; 203 ++iter;
195 } 204 }
196 return origin_usage; 205 return origin_usage;
197 } 206 }
198 207
199 int64 AppCacheDatabase::GetOriginQuota(const GURL& origin) { 208 bool AppCacheDatabase::GetAllOriginUsage(std::map<GURL, int64>* usage_map) {
200 if (!LazyOpen(false)) 209 std::set<GURL> origins;
201 return GetDefaultOriginQuota(); 210 if (!FindOriginsWithGroups(&origins))
202 int64 quota = quota_table_->GetOriginQuota( 211 return false;
203 UTF8ToUTF16(origin.spec().c_str())); 212 for (std::set<GURL>::const_iterator origin = origins.begin();
204 return (quota >= 0) ? quota : GetDefaultOriginQuota(); 213 origin != origins.end(); ++origin) {
214 (*usage_map)[*origin] = GetOriginUsage(*origin);
215 }
216 return true;
205 } 217 }
206 218
207 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) { 219 bool AppCacheDatabase::FindOriginsWithGroups(std::set<GURL>* origins) {
208 DCHECK(origins && origins->empty()); 220 DCHECK(origins && origins->empty());
209 if (!LazyOpen(false)) 221 if (!LazyOpen(false))
210 return false; 222 return false;
211 223
212 const char* kSql = 224 const char* kSql =
213 "SELECT DISTINCT(origin) FROM Groups"; 225 "SELECT DISTINCT(origin) FROM Groups";
214 226
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 1145
1134 // So we can't go recursive. 1146 // So we can't go recursive.
1135 if (is_recreating_) 1147 if (is_recreating_)
1136 return false; 1148 return false;
1137 1149
1138 AutoReset<bool> auto_reset(&is_recreating_, true); 1150 AutoReset<bool> auto_reset(&is_recreating_, true);
1139 return LazyOpen(true); 1151 return LazyOpen(true);
1140 } 1152 }
1141 1153
1142 } // namespace appcache 1154 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698