OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 entry. | 3 // found in the LICENSE entry. |
4 // | 4 // |
5 // This class isn't pretty. It's just a step better than globals, which is what | 5 // This class isn't pretty. It's just a step better than globals, which is what |
6 // these were previously. | 6 // these were previously. |
7 | 7 |
8 #include "chrome/browser/sync/util/user_settings.h" | 8 #include "chrome/browser/sync/util/user_settings.h" |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 { | 77 { |
78 // Scrape the 'shares' table to find the syncable DB. 'shares' had a | 78 // Scrape the 'shares' table to find the syncable DB. 'shares' had a |
79 // pair of string columns that mapped the username to the filename of | 79 // pair of string columns that mapped the username to the filename of |
80 // the sync data sqlite3 file. Version 11 switched to a constant | 80 // the sync data sqlite3 file. Version 11 switched to a constant |
81 // filename, so here we read the string, copy the file to the new name, | 81 // filename, so here we read the string, copy the file to the new name, |
82 // delete the old one, and then drop the unused shares table. | 82 // delete the old one, and then drop the unused shares table. |
83 ScopedStatement share_query(PrepareQuery(handle, | 83 ScopedStatement share_query(PrepareQuery(handle, |
84 "SELECT share_name, file_name FROM shares")); | 84 "SELECT share_name, file_name FROM shares")); |
85 int query_result = sqlite3_step(share_query.get()); | 85 int query_result = sqlite3_step(share_query.get()); |
86 CHECK(SQLITE_ROW == query_result); | 86 CHECK(SQLITE_ROW == query_result); |
87 PathString share_name, file_name; | 87 FilePath::StringType share_name, file_name; |
88 GetColumn(share_query.get(), 0, &share_name); | 88 GetColumn(share_query.get(), 0, &share_name); |
89 GetColumn(share_query.get(), 1, &file_name); | 89 GetColumn(share_query.get(), 1, &file_name); |
90 | 90 |
91 if (!file_util::Move(FilePath(file_name), | 91 if (!file_util::Move(FilePath(file_name), |
92 FilePath(DirectoryManager::GetSyncDataDatabaseFilename()))) { | 92 DirectoryManager::GetSyncDataDatabaseFilename())) { |
93 LOG(WARNING) << "Unable to upgrade UserSettings from v10"; | 93 LOG(WARNING) << "Unable to upgrade UserSettings from v10"; |
94 return; | 94 return; |
95 } | 95 } |
96 } | 96 } |
97 ExecOrDie(handle, "DROP TABLE shares"); | 97 ExecOrDie(handle, "DROP TABLE shares"); |
98 ExecOrDie(handle, "UPDATE db_version SET version = 11"); | 98 ExecOrDie(handle, "UPDATE db_version SET version = 11"); |
99 // FALL THROUGH | 99 // FALL THROUGH |
100 case kCurrentDBVersion: | 100 case kCurrentDBVersion: |
101 // Nothing to migrate. | 101 // Nothing to migrate. |
102 return; | 102 return; |
(...skipping 18 matching lines...) Expand all Loading... |
121 } | 121 } |
122 | 122 |
123 static void MakeClientIDTable(sqlite3* const dbhandle) { | 123 static void MakeClientIDTable(sqlite3* const dbhandle) { |
124 // Stores a single client ID value that can be used as the client id, if | 124 // Stores a single client ID value that can be used as the client id, if |
125 // there's not another such ID provided on the install. | 125 // there's not another such ID provided on the install. |
126 ExecOrDie(dbhandle, "CREATE TABLE client_id (id) "); | 126 ExecOrDie(dbhandle, "CREATE TABLE client_id (id) "); |
127 ExecOrDie(dbhandle, "INSERT INTO client_id values ( ? )", | 127 ExecOrDie(dbhandle, "INSERT INTO client_id values ( ? )", |
128 Generate128BitRandomHexString()); | 128 Generate128BitRandomHexString()); |
129 } | 129 } |
130 | 130 |
131 bool UserSettings::Init(const PathString& settings_path) { | 131 bool UserSettings::Init(const FilePath& settings_path) { |
132 { // Scope the handle | 132 { // Scope the handle. |
133 ScopedDBHandle dbhandle(this); | 133 ScopedDBHandle dbhandle(this); |
134 if (dbhandle_) | 134 if (dbhandle_) |
135 sqlite3_close(dbhandle_); | 135 sqlite3_close(dbhandle_); |
136 CHECK(SQLITE_OK == SqliteOpen(settings_path.c_str(), &dbhandle_)); | 136 CHECK(SQLITE_OK == SqliteOpen(settings_path, &dbhandle_)); |
137 // In the worst case scenario, the user may hibernate his computer during | 137 // In the worst case scenario, the user may hibernate his computer during |
138 // one of our transactions. | 138 // one of our transactions. |
139 sqlite3_busy_timeout(dbhandle_, numeric_limits<int>::max()); | 139 sqlite3_busy_timeout(dbhandle_, numeric_limits<int>::max()); |
140 | 140 |
141 int sqlite_result = Exec(dbhandle.get(), "BEGIN EXCLUSIVE TRANSACTION"); | 141 int sqlite_result = Exec(dbhandle.get(), "BEGIN EXCLUSIVE TRANSACTION"); |
142 CHECK(SQLITE_DONE == sqlite_result); | 142 CHECK(SQLITE_DONE == sqlite_result); |
143 ScopedStatement table_query(PrepareQuery(dbhandle.get(), | 143 ScopedStatement table_query(PrepareQuery(dbhandle.get(), |
144 "select count(*) from sqlite_master where type = 'table'" | 144 "select count(*) from sqlite_master where type = 'table'" |
145 " and name = 'db_version'")); | 145 " and name = 'db_version'")); |
146 int query_result = sqlite3_step(table_query.get()); | 146 int query_result = sqlite3_step(table_query.get()); |
(...skipping 29 matching lines...) Expand all Loading... |
176 MakeSigninsTable(dbhandle.get()); | 176 MakeSigninsTable(dbhandle.get()); |
177 MakeCookiesTable(dbhandle.get()); | 177 MakeCookiesTable(dbhandle.get()); |
178 MakeSigninTypesTable(dbhandle.get()); | 178 MakeSigninTypesTable(dbhandle.get()); |
179 MakeClientIDTable(dbhandle.get()); | 179 MakeClientIDTable(dbhandle.get()); |
180 } | 180 } |
181 ExecOrDie(dbhandle.get(), "COMMIT TRANSACTION"); | 181 ExecOrDie(dbhandle.get(), "COMMIT TRANSACTION"); |
182 } | 182 } |
183 #if defined(OS_WIN) | 183 #if defined(OS_WIN) |
184 // Do not index this file. Scanning can occur every time we close the file, | 184 // Do not index this file. Scanning can occur every time we close the file, |
185 // which causes long delays in SQLite's file locking. | 185 // which causes long delays in SQLite's file locking. |
186 const DWORD attrs = GetFileAttributes(settings_path.c_str()); | 186 const DWORD attrs = GetFileAttributes(settings_path.value().c_str()); |
187 const BOOL attrs_set = | 187 const BOOL attrs_set = |
188 SetFileAttributes(settings_path.c_str(), | 188 SetFileAttributes(settings_path.value().c_str(), |
189 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); | 189 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); |
190 #endif | 190 #endif |
191 return true; | 191 return true; |
192 } | 192 } |
193 | 193 |
194 UserSettings::~UserSettings() { | 194 UserSettings::~UserSettings() { |
195 if (dbhandle_) | 195 if (dbhandle_) |
196 sqlite3_close(dbhandle_); | 196 sqlite3_close(dbhandle_); |
197 } | 197 } |
198 | 198 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 ScopedStatement query(PrepareQuery(dbhandle.get(), | 341 ScopedStatement query(PrepareQuery(dbhandle.get(), |
342 "SELECT id FROM client_id")); | 342 "SELECT id FROM client_id")); |
343 int query_result = sqlite3_step(query.get()); | 343 int query_result = sqlite3_step(query.get()); |
344 string client_id; | 344 string client_id; |
345 if (query_result == SQLITE_ROW) | 345 if (query_result == SQLITE_ROW) |
346 GetColumn(query.get(), 0, &client_id); | 346 GetColumn(query.get(), 0, &client_id); |
347 return client_id; | 347 return client_id; |
348 } | 348 } |
349 | 349 |
350 } // namespace browser_sync | 350 } // namespace browser_sync |
OLD | NEW |