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

Side by Side Diff: webkit/database/database_tracker.cc

Issue 7748025: Cleanup: Remove a DCHECK about an empty database name that should not be there. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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
« no previous file with comments | « webkit/database/database_tracker.h ('k') | webkit/database/database_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/database/database_tracker.h" 5 #include "webkit/database/database_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 if (quota_manager_proxy_) 135 if (quota_manager_proxy_)
136 quota_manager_proxy_->NotifyStorageAccessed( 136 quota_manager_proxy_->NotifyStorageAccessed(
137 quota::QuotaClient::kDatabase, 137 quota::QuotaClient::kDatabase,
138 DatabaseUtil::GetOriginFromIdentifier(origin_identifier), 138 DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
139 quota::kStorageTypeTemporary); 139 quota::kStorageTypeTemporary);
140 140
141 InsertOrUpdateDatabaseDetails(origin_identifier, database_name, 141 InsertOrUpdateDatabaseDetails(origin_identifier, database_name,
142 database_description, estimated_size); 142 database_description, estimated_size);
143 if (database_connections_.AddConnection(origin_identifier, database_name)) { 143 if (database_connections_.AddConnection(origin_identifier, database_name)) {
144 *database_size = SeedOpenDatabaseSize(origin_identifier, database_name); 144 *database_size = SeedOpenDatabaseInfo(origin_identifier,
145 database_name,
146 database_description);
145 return; 147 return;
146 } 148 }
147 *database_size = UpdateOpenDatabaseSizeAndNotify(origin_identifier, 149 *database_size = UpdateOpenDatabaseInfoAndNotify(origin_identifier,
148 database_name); 150 database_name,
151 &database_description);
149 } 152 }
150 153
151 void DatabaseTracker::DatabaseModified(const string16& origin_identifier, 154 void DatabaseTracker::DatabaseModified(const string16& origin_identifier,
152 const string16& database_name) { 155 const string16& database_name) {
153 if (!LazyInit()) 156 if (!LazyInit())
154 return; 157 return;
155 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name); 158 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name);
156 } 159 }
157 160
158 void DatabaseTracker::DatabaseClosed(const string16& origin_identifier, 161 void DatabaseTracker::DatabaseClosed(const string16& origin_identifier,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 string16 origin_directory = 274 string16 origin_directory =
272 base::IntToString16(incognito_origin_directories_generator_++); 275 base::IntToString16(incognito_origin_directories_generator_++);
273 incognito_origin_directories_[origin_identifier] = origin_directory; 276 incognito_origin_directories_[origin_identifier] = origin_directory;
274 return origin_directory; 277 return origin_directory;
275 } 278 }
276 279
277 FilePath DatabaseTracker::GetFullDBFilePath( 280 FilePath DatabaseTracker::GetFullDBFilePath(
278 const string16& origin_identifier, 281 const string16& origin_identifier,
279 const string16& database_name) { 282 const string16& database_name) {
280 DCHECK(!origin_identifier.empty()); 283 DCHECK(!origin_identifier.empty());
281 DCHECK(!database_name.empty());
282 if (!LazyInit()) 284 if (!LazyInit())
283 return FilePath(); 285 return FilePath();
284 286
285 int64 id = databases_table_->GetDatabaseID( 287 int64 id = databases_table_->GetDatabaseID(
286 origin_identifier, database_name); 288 origin_identifier, database_name);
287 if (id < 0) 289 if (id < 0)
288 return FilePath(); 290 return FilePath();
289 291
290 FilePath file_name = FilePath::FromWStringHack( 292 FilePath file_name = FilePath::FromWStringHack(
291 UTF8ToWide(base::Int64ToString(id))); 293 UTF8ToWide(base::Int64ToString(id)));
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 details.description = database_description; 526 details.description = database_description;
525 details.estimated_size = estimated_size; 527 details.estimated_size = estimated_size;
526 databases_table_->UpdateDatabaseDetails(details); 528 databases_table_->UpdateDatabaseDetails(details);
527 } 529 }
528 } 530 }
529 531
530 void DatabaseTracker::ClearAllCachedOriginInfo() { 532 void DatabaseTracker::ClearAllCachedOriginInfo() {
531 origins_info_map_.clear(); 533 origins_info_map_.clear();
532 } 534 }
533 535
534 DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo( 536 DatabaseTracker::CachedOriginInfo* DatabaseTracker::MaybeGetCachedOriginInfo(
535 const string16& origin_identifier) { 537 const string16& origin_identifier, bool create_if_needed) {
536 if (!LazyInit()) 538 if (!LazyInit())
537 return NULL; 539 return NULL;
538 540
539 // Populate the cache with data for this origin if needed. 541 // Populate the cache with data for this origin if needed.
540 if (origins_info_map_.find(origin_identifier) == origins_info_map_.end()) { 542 if (origins_info_map_.find(origin_identifier) == origins_info_map_.end()) {
543 if (!create_if_needed)
544 return NULL;
545
541 std::vector<DatabaseDetails> details; 546 std::vector<DatabaseDetails> details;
542 if (!databases_table_->GetAllDatabaseDetailsForOrigin( 547 if (!databases_table_->GetAllDatabaseDetailsForOrigin(
543 origin_identifier, &details)) { 548 origin_identifier, &details)) {
544 return NULL; 549 return NULL;
545 } 550 }
546 551
547 CachedOriginInfo& origin_info = origins_info_map_[origin_identifier]; 552 CachedOriginInfo& origin_info = origins_info_map_[origin_identifier];
548 origin_info.SetOrigin(origin_identifier); 553 origin_info.SetOrigin(origin_identifier);
549 for (std::vector<DatabaseDetails>::const_iterator it = details.begin(); 554 for (std::vector<DatabaseDetails>::const_iterator it = details.begin();
550 it != details.end(); it++) { 555 it != details.end(); it++) {
(...skipping 15 matching lines...) Expand all
566 571
567 int64 DatabaseTracker::GetDBFileSize(const string16& origin_identifier, 572 int64 DatabaseTracker::GetDBFileSize(const string16& origin_identifier,
568 const string16& database_name) { 573 const string16& database_name) {
569 FilePath db_file_name = GetFullDBFilePath(origin_identifier, database_name); 574 FilePath db_file_name = GetFullDBFilePath(origin_identifier, database_name);
570 int64 db_file_size = 0; 575 int64 db_file_size = 0;
571 if (!file_util::GetFileSize(db_file_name, &db_file_size)) 576 if (!file_util::GetFileSize(db_file_name, &db_file_size))
572 db_file_size = 0; 577 db_file_size = 0;
573 return db_file_size; 578 return db_file_size;
574 } 579 }
575 580
576 int64 DatabaseTracker::SeedOpenDatabaseSize( 581 int64 DatabaseTracker::SeedOpenDatabaseInfo(
577 const string16& origin_id, const string16& name) { 582 const string16& origin_id, const string16& name,
583 const string16& description) {
578 DCHECK(database_connections_.IsDatabaseOpened(origin_id, name)); 584 DCHECK(database_connections_.IsDatabaseOpened(origin_id, name));
579 int64 size = GetDBFileSize(origin_id, name); 585 int64 size = GetDBFileSize(origin_id, name);
580 database_connections_.SetOpenDatabaseSize(origin_id, name, size); 586 database_connections_.SetOpenDatabaseSize(origin_id, name, size);
581 if (origins_info_map_.find(origin_id) != origins_info_map_.end()) 587 CachedOriginInfo* info = MaybeGetCachedOriginInfo(origin_id, false);
582 origins_info_map_[origin_id].SetDatabaseSize(name, size); 588 if (info) {
589 info->SetDatabaseSize(name, size);
590 info->SetDatabaseDescription(name, description);
591 }
583 return size; 592 return size;
584 } 593 }
585 594
586 int64 DatabaseTracker::UpdateOpenDatabaseSizeAndNotify( 595 int64 DatabaseTracker::UpdateOpenDatabaseInfoAndNotify(
587 const string16& origin_id, const string16& name) { 596 const string16& origin_id, const string16& name,
597 const string16* opt_description) {
588 DCHECK(database_connections_.IsDatabaseOpened(origin_id, name)); 598 DCHECK(database_connections_.IsDatabaseOpened(origin_id, name));
589 int64 new_size = GetDBFileSize(origin_id, name); 599 int64 new_size = GetDBFileSize(origin_id, name);
590 int64 old_size = database_connections_.GetOpenDatabaseSize(origin_id, name); 600 int64 old_size = database_connections_.GetOpenDatabaseSize(origin_id, name);
601 CachedOriginInfo* info = MaybeGetCachedOriginInfo(origin_id, false);
602 if (info && opt_description)
603 info->SetDatabaseDescription(name, *opt_description);
591 if (old_size != new_size) { 604 if (old_size != new_size) {
592 database_connections_.SetOpenDatabaseSize(origin_id, name, new_size); 605 database_connections_.SetOpenDatabaseSize(origin_id, name, new_size);
593 if (origins_info_map_.find(origin_id) != origins_info_map_.end()) 606 if (info)
594 origins_info_map_[origin_id].SetDatabaseSize(name, new_size); 607 info->SetDatabaseSize(name, new_size);
595 if (quota_manager_proxy_) 608 if (quota_manager_proxy_)
596 quota_manager_proxy_->NotifyStorageModified( 609 quota_manager_proxy_->NotifyStorageModified(
597 quota::QuotaClient::kDatabase, 610 quota::QuotaClient::kDatabase,
598 DatabaseUtil::GetOriginFromIdentifier(origin_id), 611 DatabaseUtil::GetOriginFromIdentifier(origin_id),
599 quota::kStorageTypeTemporary, 612 quota::kStorageTypeTemporary,
600 new_size - old_size); 613 new_size - old_size);
601 FOR_EACH_OBSERVER(Observer, observers_, OnDatabaseSizeChanged( 614 FOR_EACH_OBSERVER(Observer, observers_, OnDatabaseSizeChanged(
602 origin_id, name, new_size)); 615 origin_id, name, new_size));
603 } 616 }
604 return new_size; 617 return new_size;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 return; 854 return;
842 } 855 }
843 if (shutting_down_) { 856 if (shutting_down_) {
844 NOTREACHED(); 857 NOTREACHED();
845 return; 858 return;
846 } 859 }
847 clear_local_state_on_exit_ = clear_local_state_on_exit; 860 clear_local_state_on_exit_ = clear_local_state_on_exit;
848 } 861 }
849 862
850 } // namespace webkit_database 863 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_tracker.h ('k') | webkit/database/database_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698