| 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 "components/webdata/common/web_database.h" | 5 #include "components/webdata/common/web_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // |sql::INIT_FAILURE|. | 37 // |sql::INIT_FAILURE|. |
| 38 sql::InitStatus FailedMigrationTo(int version_num) { | 38 sql::InitStatus FailedMigrationTo(int version_num) { |
| 39 LOG(WARNING) << "Unable to update web database to version " | 39 LOG(WARNING) << "Unable to update web database to version " |
| 40 << version_num << "."; | 40 << version_num << "."; |
| 41 NOTREACHED(); | 41 NOTREACHED(); |
| 42 return sql::INIT_FAILURE; | 42 return sql::INIT_FAILURE; |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 WebDatabase::WebDatabase() {} | 47 WebDatabase::WebDatabase() |
| 48 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 49 |
| 50 } |
| 48 | 51 |
| 49 WebDatabase::~WebDatabase() { | 52 WebDatabase::~WebDatabase() { |
| 53 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void WebDatabase::AddTable(WebDatabaseTable* table) { | 56 void WebDatabase::AddTable(WebDatabaseTable* table) { |
| 53 tables_[table->GetTypeKey()] = table; | 57 tables_[table->GetTypeKey()] = table; |
| 54 } | 58 } |
| 55 | 59 |
| 56 WebDatabaseTable* WebDatabase::GetTable(WebDatabaseTable::TypeKey key) { | 60 WebDatabaseTable* WebDatabase::GetTable(WebDatabaseTable::TypeKey key) { |
| 57 return tables_[key]; | 61 return tables_[key]; |
| 58 } | 62 } |
| 59 | 63 |
| 60 void WebDatabase::BeginTransaction() { | 64 void WebDatabase::BeginTransaction() { |
| 61 db_.BeginTransaction(); | 65 db_.BeginTransaction(); |
| 62 } | 66 } |
| 63 | 67 |
| 64 void WebDatabase::CommitTransaction() { | 68 void WebDatabase::CommitTransaction() { |
| 65 db_.CommitTransaction(); | 69 db_.CommitTransaction(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 sql::Connection* WebDatabase::GetSQLConnection() { | 72 sql::Connection* WebDatabase::GetSQLConnection() { |
| 69 return &db_; | 73 return &db_; |
| 70 } | 74 } |
| 71 | 75 |
| 76 base::WeakPtr<WebDatabase> WebDatabase::AsWeakPtr() { |
| 77 return weak_ptr_factory_.GetWeakPtr(); |
| 78 } |
| 79 |
| 72 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { | 80 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { |
| 73 // When running in unit tests, there is already a NotificationService object. | 81 // When running in unit tests, there is already a NotificationService object. |
| 74 // Since only one can exist at a time per thread, check first. | 82 // Since only one can exist at a time per thread, check first. |
| 75 if (!content::NotificationService::current()) | 83 if (!content::NotificationService::current()) |
| 76 notification_service_.reset(content::NotificationService::Create()); | 84 notification_service_.reset(content::NotificationService::Create()); |
| 77 | 85 |
| 78 db_.set_error_histogram_name("Sqlite.Web.Error"); | 86 db_.set_error_histogram_name("Sqlite.Web.Error"); |
| 79 | 87 |
| 80 // We don't store that much data in the tables so use a small page size. | 88 // We don't store that much data in the tables so use a small page size. |
| 81 // This provides a large benefit for empty tables (which is very likely with | 89 // This provides a large benefit for empty tables (which is very likely with |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (!it->second->MigrateToVersion(next_version, | 172 if (!it->second->MigrateToVersion(next_version, |
| 165 &update_compatible_version)) { | 173 &update_compatible_version)) { |
| 166 return FailedMigrationTo(next_version); | 174 return FailedMigrationTo(next_version); |
| 167 } | 175 } |
| 168 | 176 |
| 169 ChangeVersion(&meta_table_, next_version, update_compatible_version); | 177 ChangeVersion(&meta_table_, next_version, update_compatible_version); |
| 170 } | 178 } |
| 171 } | 179 } |
| 172 return sql::INIT_OK; | 180 return sql::INIT_OK; |
| 173 } | 181 } |
| OLD | NEW |