Chromium Code Reviews| 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/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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "sql/connection.h" | 18 #include "sql/connection.h" |
| 19 #include "sql/diagnostic_error_delegate.h" | 19 #include "sql/diagnostic_error_delegate.h" |
| 20 #include "sql/meta_table.h" | 20 #include "sql/meta_table.h" |
| 21 #include "sql/transaction.h" | 21 #include "sql/transaction.h" |
| 22 #include "third_party/sqlite/sqlite3.h" | |
| 22 #include "webkit/database/database_quota_client.h" | 23 #include "webkit/database/database_quota_client.h" |
| 23 #include "webkit/database/database_util.h" | 24 #include "webkit/database/database_util.h" |
| 24 #include "webkit/database/databases_table.h" | 25 #include "webkit/database/databases_table.h" |
| 25 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
| 26 #include "webkit/quota/special_storage_policy.h" | 27 #include "webkit/quota/special_storage_policy.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class HistogramUniquifier { | 31 class HistogramUniquifier { |
| 31 public: | 32 public: |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 quota_manager_proxy_->NotifyStorageAccessed( | 173 quota_manager_proxy_->NotifyStorageAccessed( |
| 173 quota::QuotaClient::kDatabase, | 174 quota::QuotaClient::kDatabase, |
| 174 DatabaseUtil::GetOriginFromIdentifier(origin_identifier), | 175 DatabaseUtil::GetOriginFromIdentifier(origin_identifier), |
| 175 quota::kStorageTypeTemporary); | 176 quota::kStorageTypeTemporary); |
| 176 | 177 |
| 177 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name); | 178 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name); |
| 178 if (database_connections_.RemoveConnection(origin_identifier, database_name)) | 179 if (database_connections_.RemoveConnection(origin_identifier, database_name)) |
| 179 DeleteDatabaseIfNeeded(origin_identifier, database_name); | 180 DeleteDatabaseIfNeeded(origin_identifier, database_name); |
| 180 } | 181 } |
| 181 | 182 |
| 183 void DatabaseTracker::HandleSqliteError( | |
| 184 const string16& origin_identifier, | |
| 185 const string16& database_name, | |
| 186 int error) { | |
| 187 // We only handle errors that indicate corruption and we | |
| 188 // do sp with a heavy hand, we delete it. Any renderers/workers | |
| 189 // with this database open will receive a message to close it | |
| 190 // immediately, once all have closed, the files will be deleted. | |
| 191 // In the interim, all attempts to open a new connection to that | |
| 192 // database will fail. | |
|
Scott Hess - ex-Googler
2012/02/10 23:34:07
I guess that DeleteDatabase() implements all that
michaeln
2012/02/11 00:34:20
Yes
| |
| 193 if (error == SQLITE_CORRUPT || error == SQLITE_NOTADB) { | |
|
Scott Hess - ex-Googler
2012/02/10 23:34:07
The sender also has this guard. It is definitely
michaeln
2012/02/11 00:34:20
That could be, but i'm avoiding necessary messagin
Scott Hess - ex-Googler
2012/02/11 19:48:24
OK. In that case, perhaps document that this is s
| |
| 194 DeleteDatabase(origin_identifier, database_name, | |
| 195 net::CompletionCallback()); | |
| 196 } | |
| 197 } | |
| 198 | |
| 182 void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) { | 199 void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) { |
| 183 if (database_connections_.IsEmpty()) { | 200 if (database_connections_.IsEmpty()) { |
| 184 DCHECK(!is_initialized_ || connections.IsEmpty()); | 201 DCHECK(!is_initialized_ || connections.IsEmpty()); |
| 185 return; | 202 return; |
| 186 } | 203 } |
| 187 | 204 |
| 188 // When being closed by this route, there's a chance that | 205 // When being closed by this route, there's a chance that |
| 189 // the tracker missed some DatabseModified calls. This method is used | 206 // the tracker missed some DatabseModified calls. This method is used |
| 190 // when a renderer crashes to cleanup it's open resources. | 207 // when a renderer crashes to cleanup it's open resources. |
| 191 // We need to examine what we have in connections for the | 208 // We need to examine what we have in connections for the |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 876 if (!db_tracker_thread_->BelongsToCurrentThread()) { | 893 if (!db_tracker_thread_->BelongsToCurrentThread()) { |
| 877 db_tracker_thread_->PostTask( | 894 db_tracker_thread_->PostTask( |
| 878 FROM_HERE, | 895 FROM_HERE, |
| 879 base::Bind(&DatabaseTracker::SaveSessionState, this)); | 896 base::Bind(&DatabaseTracker::SaveSessionState, this)); |
| 880 return; | 897 return; |
| 881 } | 898 } |
| 882 save_session_state_ = true; | 899 save_session_state_ = true; |
| 883 } | 900 } |
| 884 | 901 |
| 885 } // namespace webkit_database | 902 } // namespace webkit_database |
| OLD | NEW |