| 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 "webkit/browser/appcache/appcache_database.h" | 5 #include "webkit/browser/appcache/appcache_database.h" | 
| 6 | 6 | 
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" | 
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" | 
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1004   } | 1004   } | 
| 1005 | 1005 | 
| 1006   db_.reset(new sql::Connection); | 1006   db_.reset(new sql::Connection); | 
| 1007   meta_table_.reset(new sql::MetaTable); | 1007   meta_table_.reset(new sql::MetaTable); | 
| 1008 | 1008 | 
| 1009   db_->set_histogram_tag("AppCache"); | 1009   db_->set_histogram_tag("AppCache"); | 
| 1010 | 1010 | 
| 1011   bool opened = false; | 1011   bool opened = false; | 
| 1012   if (use_in_memory_db) { | 1012   if (use_in_memory_db) { | 
| 1013     opened = db_->OpenInMemory(); | 1013     opened = db_->OpenInMemory(); | 
| 1014   } else if (!file_util::CreateDirectory(db_file_path_.DirName())) { | 1014   } else if (!base::CreateDirectory(db_file_path_.DirName())) { | 
| 1015     LOG(ERROR) << "Failed to create appcache directory."; | 1015     LOG(ERROR) << "Failed to create appcache directory."; | 
| 1016   } else { | 1016   } else { | 
| 1017     opened = db_->Open(db_file_path_); | 1017     opened = db_->Open(db_file_path_); | 
| 1018     if (opened) | 1018     if (opened) | 
| 1019       db_->Preload(); | 1019       db_->Preload(); | 
| 1020   } | 1020   } | 
| 1021 | 1021 | 
| 1022   if (!opened || !EnsureDatabaseVersion()) { | 1022   if (!opened || !EnsureDatabaseVersion()) { | 
| 1023     LOG(ERROR) << "Failed to open the appcache database."; | 1023     LOG(ERROR) << "Failed to open the appcache database."; | 
| 1024     AppCacheHistograms::CountInitResult( | 1024     AppCacheHistograms::CountInitResult( | 
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1189 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { | 1189 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { | 
| 1190   DCHECK(!db_file_path_.empty()); | 1190   DCHECK(!db_file_path_.empty()); | 
| 1191   DCHECK(base::PathExists(db_file_path_)); | 1191   DCHECK(base::PathExists(db_file_path_)); | 
| 1192   VLOG(1) << "Deleting existing appcache data and starting over."; | 1192   VLOG(1) << "Deleting existing appcache data and starting over."; | 
| 1193 | 1193 | 
| 1194   ResetConnectionAndTables(); | 1194   ResetConnectionAndTables(); | 
| 1195 | 1195 | 
| 1196   // This also deletes the disk cache data. | 1196   // This also deletes the disk cache data. | 
| 1197   base::FilePath directory = db_file_path_.DirName(); | 1197   base::FilePath directory = db_file_path_.DirName(); | 
| 1198   if (!base::DeleteFile(directory, true) || | 1198   if (!base::DeleteFile(directory, true) || | 
| 1199       !file_util::CreateDirectory(directory)) { | 1199       !base::CreateDirectory(directory)) { | 
| 1200     return false; | 1200     return false; | 
| 1201   } | 1201   } | 
| 1202 | 1202 | 
| 1203   // Make sure the steps above actually deleted things. | 1203   // Make sure the steps above actually deleted things. | 
| 1204   if (base::PathExists(db_file_path_)) | 1204   if (base::PathExists(db_file_path_)) | 
| 1205     return false; | 1205     return false; | 
| 1206 | 1206 | 
| 1207   // So we can't go recursive. | 1207   // So we can't go recursive. | 
| 1208   if (is_recreating_) | 1208   if (is_recreating_) | 
| 1209     return false; | 1209     return false; | 
| 1210 | 1210 | 
| 1211   base::AutoReset<bool> auto_reset(&is_recreating_, true); | 1211   base::AutoReset<bool> auto_reset(&is_recreating_, true); | 
| 1212   return LazyOpen(true); | 1212   return LazyOpen(true); | 
| 1213 } | 1213 } | 
| 1214 | 1214 | 
| 1215 }  // namespace appcache | 1215 }  // namespace appcache | 
| OLD | NEW | 
|---|