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" | |
11 #include "sql/statement.h" | 10 #include "sql/statement.h" |
12 #include "sql/transaction.h" | 11 #include "sql/transaction.h" |
13 | 12 |
14 // Current version number. Note: when changing the current version number, | 13 // Current version number. Note: when changing the current version number, |
15 // corresponding changes must happen in the unit tests, and new migration test | 14 // corresponding changes must happen in the unit tests, and new migration test |
16 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. | 15 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. |
17 // static | 16 // static |
18 const int WebDatabase::kCurrentVersionNumber = 51; | 17 const int WebDatabase::kCurrentVersionNumber = 51; |
19 | 18 |
20 namespace { | 19 namespace { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 62 |
64 void WebDatabase::CommitTransaction() { | 63 void WebDatabase::CommitTransaction() { |
65 db_.CommitTransaction(); | 64 db_.CommitTransaction(); |
66 } | 65 } |
67 | 66 |
68 sql::Connection* WebDatabase::GetSQLConnection() { | 67 sql::Connection* WebDatabase::GetSQLConnection() { |
69 return &db_; | 68 return &db_; |
70 } | 69 } |
71 | 70 |
72 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { | 71 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { |
73 // When running in unit tests, there is already a NotificationService object. | |
74 // Since only one can exist at a time per thread, check first. | |
75 if (!content::NotificationService::current()) | |
76 notification_service_.reset(content::NotificationService::Create()); | |
77 | |
78 db_.set_histogram_tag("Web"); | 72 db_.set_histogram_tag("Web"); |
79 | 73 |
80 // We don't store that much data in the tables so use a small page size. | 74 // 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 | 75 // This provides a large benefit for empty tables (which is very likely with |
82 // the tables we create). | 76 // the tables we create). |
83 db_.set_page_size(2048); | 77 db_.set_page_size(2048); |
84 | 78 |
85 // We shouldn't have much data and what access we currently have is quite | 79 // We shouldn't have much data and what access we currently have is quite |
86 // infrequent. So we go with a small cache size. | 80 // infrequent. So we go with a small cache size. |
87 db_.set_cache_size(32); | 81 db_.set_cache_size(32); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (!it->second->MigrateToVersion(next_version, | 158 if (!it->second->MigrateToVersion(next_version, |
165 &update_compatible_version)) { | 159 &update_compatible_version)) { |
166 return FailedMigrationTo(next_version); | 160 return FailedMigrationTo(next_version); |
167 } | 161 } |
168 | 162 |
169 ChangeVersion(&meta_table_, next_version, update_compatible_version); | 163 ChangeVersion(&meta_table_, next_version, update_compatible_version); |
170 } | 164 } |
171 } | 165 } |
172 return sql::INIT_OK; | 166 return sql::INIT_OK; |
173 } | 167 } |
OLD | NEW |