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/appcache/appcache_database.h" | 5 #include "webkit/appcache/appcache_database.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 bool AppCacheDatabase::InsertNamespace( | 682 bool AppCacheDatabase::InsertNamespace( |
| 683 const NamespaceRecord* record) { | 683 const NamespaceRecord* record) { |
| 684 if (!LazyOpen(true)) | 684 if (!LazyOpen(true)) |
| 685 return false; | 685 return false; |
| 686 | 686 |
| 687 const char* kSql = | 687 const char* kSql = |
| 688 "INSERT INTO Namespaces" | 688 "INSERT INTO Namespaces" |
| 689 " (cache_id, origin, type, namespace_url, target_url, is_pattern)" | 689 " (cache_id, origin, type, namespace_url, target_url, is_pattern)" |
| 690 " VALUES (?, ?, ?, ?, ?, ?)"; | 690 " VALUES (?, ?, ?, ?, ?, ?)"; |
| 691 | 691 |
| 692 // Note: quick and dirty storage for the 'executable' bit w/o changing | |
| 693 // schemas, we use the high bit of 'type' field | |
|
Greg Billock
2013/04/10 23:25:30
Is this going to give us maintenance hassles later
alecflett
2013/04/10 23:39:56
Yeah, for instance we lose backwards compatibility
michaeln
2013/04/10 23:47:59
This bugs me too :) We couldn't completely back ev
| |
| 694 int type_with_executable_bit = record->namespace_.type; | |
| 695 if (record->namespace_.is_executable) | |
| 696 type_with_executable_bit |= 0x80000000; | |
| 697 | |
| 692 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); | 698 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 693 statement.BindInt64(0, record->cache_id); | 699 statement.BindInt64(0, record->cache_id); |
| 694 statement.BindString(1, record->origin.spec()); | 700 statement.BindString(1, record->origin.spec()); |
| 695 statement.BindInt(2, record->namespace_.type); | 701 statement.BindInt(2, type_with_executable_bit); |
| 696 statement.BindString(3, record->namespace_.namespace_url.spec()); | 702 statement.BindString(3, record->namespace_.namespace_url.spec()); |
| 697 statement.BindString(4, record->namespace_.target_url.spec()); | 703 statement.BindString(4, record->namespace_.target_url.spec()); |
| 698 statement.BindBool(5, record->namespace_.is_pattern); | 704 statement.BindBool(5, record->namespace_.is_pattern); |
| 699 return statement.Run(); | 705 return statement.Run(); |
| 700 } | 706 } |
| 701 | 707 |
| 702 bool AppCacheDatabase::InsertNamespaceRecords( | 708 bool AppCacheDatabase::InsertNamespaceRecords( |
| 703 const std::vector<NamespaceRecord>& records) { | 709 const std::vector<NamespaceRecord>& records) { |
| 704 if (records.empty()) | 710 if (records.empty()) |
| 705 return true; | 711 return true; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 (type == FALLBACK_NAMESPACE) ? fallbacks : intercepts; | 935 (type == FALLBACK_NAMESPACE) ? fallbacks : intercepts; |
| 930 records->push_back(NamespaceRecord()); | 936 records->push_back(NamespaceRecord()); |
| 931 ReadNamespaceRecord(statement, &records->back()); | 937 ReadNamespaceRecord(statement, &records->back()); |
| 932 } | 938 } |
| 933 } | 939 } |
| 934 | 940 |
| 935 void AppCacheDatabase::ReadNamespaceRecord( | 941 void AppCacheDatabase::ReadNamespaceRecord( |
| 936 const sql::Statement* statement, NamespaceRecord* record) { | 942 const sql::Statement* statement, NamespaceRecord* record) { |
| 937 record->cache_id = statement->ColumnInt64(0); | 943 record->cache_id = statement->ColumnInt64(0); |
| 938 record->origin = GURL(statement->ColumnString(1)); | 944 record->origin = GURL(statement->ColumnString(1)); |
| 939 record->namespace_.type = static_cast<NamespaceType>(statement->ColumnInt(2)); | 945 int type_with_excutable_bit = statement->ColumnInt(2); |
| 940 record->namespace_.namespace_url = GURL(statement->ColumnString(3)); | 946 record->namespace_.namespace_url = GURL(statement->ColumnString(3)); |
| 941 record->namespace_.target_url = GURL(statement->ColumnString(4)); | 947 record->namespace_.target_url = GURL(statement->ColumnString(4)); |
| 942 record->namespace_.is_pattern = statement->ColumnBool(5); | 948 record->namespace_.is_pattern = statement->ColumnBool(5); |
| 949 | |
| 950 // Note: quick and dirty storage for the 'executable' bit w/o changing | |
| 951 // schemas, we use the high bit of 'type' field. | |
| 952 record->namespace_.type = static_cast<NamespaceType> | |
| 953 (type_with_excutable_bit & 0x7ffffffff); | |
| 954 record->namespace_.is_executable = | |
| 955 (type_with_excutable_bit & 0x80000000) != 0; | |
| 943 } | 956 } |
| 944 | 957 |
| 945 void AppCacheDatabase::ReadOnlineWhiteListRecord( | 958 void AppCacheDatabase::ReadOnlineWhiteListRecord( |
| 946 const sql::Statement& statement, OnlineWhiteListRecord* record) { | 959 const sql::Statement& statement, OnlineWhiteListRecord* record) { |
| 947 record->cache_id = statement.ColumnInt64(0); | 960 record->cache_id = statement.ColumnInt64(0); |
| 948 record->namespace_url = GURL(statement.ColumnString(1)); | 961 record->namespace_url = GURL(statement.ColumnString(1)); |
| 949 record->is_pattern = statement.ColumnBool(2); | 962 record->is_pattern = statement.ColumnBool(2); |
| 950 } | 963 } |
| 951 | 964 |
| 952 bool AppCacheDatabase::LazyOpen(bool create_if_needed) { | 965 bool AppCacheDatabase::LazyOpen(bool create_if_needed) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 | 1167 |
| 1155 // So we can't go recursive. | 1168 // So we can't go recursive. |
| 1156 if (is_recreating_) | 1169 if (is_recreating_) |
| 1157 return false; | 1170 return false; |
| 1158 | 1171 |
| 1159 base::AutoReset<bool> auto_reset(&is_recreating_, true); | 1172 base::AutoReset<bool> auto_reset(&is_recreating_, true); |
| 1160 return LazyOpen(true); | 1173 return LazyOpen(true); |
| 1161 } | 1174 } |
| 1162 | 1175 |
| 1163 } // namespace appcache | 1176 } // namespace appcache |
| OLD | NEW |