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

Side by Side Diff: components/enhanced_bookmarks/persistent_image_store.cc

Issue 305963004: Add GetStoreSize() to ImageStore to know the actual db size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: size += bitmap.getSize(); Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/enhanced_bookmarks/persistent_image_store.h" 5 #include "components/enhanced_bookmarks/persistent_image_store.h"
6 6
7 #include "base/files/file.h"
7 #include "components/enhanced_bookmarks/image_store_util.h" 8 #include "components/enhanced_bookmarks/image_store_util.h"
8 #include "sql/statement.h" 9 #include "sql/statement.h"
9 #include "sql/transaction.h" 10 #include "sql/transaction.h"
10 #include "ui/gfx/geometry/size.h" 11 #include "ui/gfx/geometry/size.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace { 14 namespace {
14 15
15 bool InitTables(sql::Connection& db) { 16 bool InitTables(sql::Connection& db) {
16 const char kTableSql[] = 17 const char kTableSql[] =
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void PersistentImageStore::ClearAll() { 191 void PersistentImageStore::ClearAll() {
191 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 192 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
192 if (OpenDatabase() != sql::INIT_OK) 193 if (OpenDatabase() != sql::INIT_OK)
193 return; 194 return;
194 195
195 sql::Statement statement(db_.GetCachedStatement( 196 sql::Statement statement(db_.GetCachedStatement(
196 SQL_FROM_HERE, "DELETE FROM images_by_url")); 197 SQL_FROM_HERE, "DELETE FROM images_by_url"));
197 statement.Run(); 198 statement.Run();
198 } 199 }
199 200
201 int64 PersistentImageStore::GetStoreSizeInBytes() {
202 base::File file(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
203 return file.IsValid() ? file.GetLength() : -1;
204 }
205
200 PersistentImageStore::~PersistentImageStore() { 206 PersistentImageStore::~PersistentImageStore() {
201 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 207 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
202 } 208 }
203 209
204 sql::InitStatus PersistentImageStore::OpenDatabase() { 210 sql::InitStatus PersistentImageStore::OpenDatabase() {
205 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 211 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
206 212
207 if (db_.is_open()) 213 if (db_.is_open())
208 return sql::INIT_OK; 214 return sql::INIT_OK;
209 215
210 const size_t kAttempts = 2; 216 const size_t kAttempts = 2;
211 217
212 sql::InitStatus status = sql::INIT_FAILURE; 218 sql::InitStatus status = sql::INIT_FAILURE;
213 for (size_t i = 0; i < kAttempts; ++i) { 219 for (size_t i = 0; i < kAttempts; ++i) {
214 status = OpenDatabaseImpl(db_, path_); 220 status = OpenDatabaseImpl(db_, path_);
215 if (status == sql::INIT_OK) 221 if (status == sql::INIT_OK)
216 return status; 222 return status;
217 223
218 // Can't open, raze(). 224 // Can't open, raze().
219 if (db_.is_open()) 225 if (db_.is_open())
220 db_.Raze(); 226 db_.Raze();
221 db_.Close(); 227 db_.Close();
222 } 228 }
223 229
224 DCHECK(false) << "Can't open image DB"; 230 DCHECK(false) << "Can't open image DB";
225 return sql::INIT_FAILURE; 231 return sql::INIT_FAILURE;
226 } 232 }
OLDNEW
« no previous file with comments | « components/enhanced_bookmarks/persistent_image_store.h ('k') | components/enhanced_bookmarks/test_image_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698