Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: webkit/appcache/appcache_database.cc

Issue 13881003: AppCacheExecutableHandlers - parse manifest file and store the 'bit' indicating executable. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/appcache/appcache_entry.h » ('j') | webkit/appcache/appcache_interfaces.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "sql/connection.h" 12 #include "sql/connection.h"
12 #include "sql/meta_table.h" 13 #include "sql/meta_table.h"
13 #include "sql/statement.h" 14 #include "sql/statement.h"
14 #include "sql/transaction.h" 15 #include "sql/transaction.h"
15 #include "webkit/appcache/appcache_entry.h" 16 #include "webkit/appcache/appcache_entry.h"
16 #include "webkit/appcache/appcache_histograms.h" 17 #include "webkit/appcache/appcache_histograms.h"
17 18
19 namespace appcache {
20
18 // Schema ------------------------------------------------------------------- 21 // Schema -------------------------------------------------------------------
19 namespace { 22 namespace {
20 23
21 const int kCurrentVersion = 5; 24 const int kCurrentVersion = 5;
22 const int kCompatibleVersion = 5; 25 const int kCompatibleVersion = 5;
23 26
24 // A mechanism to run experiments that may affect in data being persisted 27 // A mechanism to run experiments that may affect in data being persisted
25 // in different ways such that when the experiment is toggled on/off via 28 // in different ways such that when the experiment is toggled on/off via
26 // cmd line flags, the database gets reset. The active flags are stored at 29 // cmd line flags, the database gets reset. The active flags are stored at
27 // the time of database creation and compared when reopening. If different 30 // the time of database creation and compared when reopening. If different
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 else 163 else
161 sql += "CREATE INDEX "; 164 sql += "CREATE INDEX ";
162 sql += info.index_name; 165 sql += info.index_name;
163 sql += " ON "; 166 sql += " ON ";
164 sql += info.table_name; 167 sql += info.table_name;
165 sql += info.columns; 168 sql += info.columns;
166 return db->Execute(sql.c_str()); 169 return db->Execute(sql.c_str());
167 } 170 }
168 171
169 std::string GetActiveExperimentFlags() { 172 std::string GetActiveExperimentFlags() {
173 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableExecutableHandlers))
174 return std::string("executableHandlersEnabled");
170 return std::string(); 175 return std::string();
171 } 176 }
172 177
173 } // anon namespace 178 } // anon namespace
174 179
175 // AppCacheDatabase ---------------------------------------------------------- 180 // AppCacheDatabase ----------------------------------------------------------
176 namespace appcache {
177 181
178 AppCacheDatabase::GroupRecord::GroupRecord() 182 AppCacheDatabase::GroupRecord::GroupRecord()
179 : group_id(0) { 183 : group_id(0) {
180 } 184 }
181 185
182 AppCacheDatabase::GroupRecord::~GroupRecord() { 186 AppCacheDatabase::GroupRecord::~GroupRecord() {
183 } 187 }
184 188
185 AppCacheDatabase::NamespaceRecord::NamespaceRecord() 189 AppCacheDatabase::NamespaceRecord::NamespaceRecord()
186 : cache_id(0) { 190 : cache_id(0) {
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 bool AppCacheDatabase::InsertNamespace( 697 bool AppCacheDatabase::InsertNamespace(
694 const NamespaceRecord* record) { 698 const NamespaceRecord* record) {
695 if (!LazyOpen(true)) 699 if (!LazyOpen(true))
696 return false; 700 return false;
697 701
698 const char* kSql = 702 const char* kSql =
699 "INSERT INTO Namespaces" 703 "INSERT INTO Namespaces"
700 " (cache_id, origin, type, namespace_url, target_url, is_pattern)" 704 " (cache_id, origin, type, namespace_url, target_url, is_pattern)"
701 " VALUES (?, ?, ?, ?, ?, ?)"; 705 " VALUES (?, ?, ?, ?, ?, ?)";
702 706
707 // Note: quick and dirty storage for the 'executable' bit w/o changing
708 // schemas, we use the high bit of 'type' field.
709 int type_with_executable_bit = record->namespace_.type;
710 if (record->namespace_.is_executable) {
711 type_with_executable_bit |= 0x8000000;
712 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
713 kEnableExecutableHandlers));
714 }
715
703 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); 716 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql));
704 statement.BindInt64(0, record->cache_id); 717 statement.BindInt64(0, record->cache_id);
705 statement.BindString(1, record->origin.spec()); 718 statement.BindString(1, record->origin.spec());
706 statement.BindInt(2, record->namespace_.type); 719 statement.BindInt(2, type_with_executable_bit);
707 statement.BindString(3, record->namespace_.namespace_url.spec()); 720 statement.BindString(3, record->namespace_.namespace_url.spec());
708 statement.BindString(4, record->namespace_.target_url.spec()); 721 statement.BindString(4, record->namespace_.target_url.spec());
709 statement.BindBool(5, record->namespace_.is_pattern); 722 statement.BindBool(5, record->namespace_.is_pattern);
710 return statement.Run(); 723 return statement.Run();
711 } 724 }
712 725
713 bool AppCacheDatabase::InsertNamespaceRecords( 726 bool AppCacheDatabase::InsertNamespaceRecords(
714 const std::vector<NamespaceRecord>& records) { 727 const std::vector<NamespaceRecord>& records) {
715 if (records.empty()) 728 if (records.empty())
716 return true; 729 return true;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 (type == FALLBACK_NAMESPACE) ? fallbacks : intercepts; 953 (type == FALLBACK_NAMESPACE) ? fallbacks : intercepts;
941 records->push_back(NamespaceRecord()); 954 records->push_back(NamespaceRecord());
942 ReadNamespaceRecord(statement, &records->back()); 955 ReadNamespaceRecord(statement, &records->back());
943 } 956 }
944 } 957 }
945 958
946 void AppCacheDatabase::ReadNamespaceRecord( 959 void AppCacheDatabase::ReadNamespaceRecord(
947 const sql::Statement* statement, NamespaceRecord* record) { 960 const sql::Statement* statement, NamespaceRecord* record) {
948 record->cache_id = statement->ColumnInt64(0); 961 record->cache_id = statement->ColumnInt64(0);
949 record->origin = GURL(statement->ColumnString(1)); 962 record->origin = GURL(statement->ColumnString(1));
950 record->namespace_.type = static_cast<NamespaceType>(statement->ColumnInt(2)); 963 int type_with_executable_bit = statement->ColumnInt(2);
michaeln 2013/04/16 22:25:11 could make this const to make it more clear we don
951 record->namespace_.namespace_url = GURL(statement->ColumnString(3)); 964 record->namespace_.namespace_url = GURL(statement->ColumnString(3));
952 record->namespace_.target_url = GURL(statement->ColumnString(4)); 965 record->namespace_.target_url = GURL(statement->ColumnString(4));
953 record->namespace_.is_pattern = statement->ColumnBool(5); 966 record->namespace_.is_pattern = statement->ColumnBool(5);
967
968 // Note: quick and dirty storage for the 'executable' bit w/o changing
969 // schemas, we use the high bit of 'type' field.
970 record->namespace_.type = static_cast<NamespaceType>
971 (type_with_executable_bit & 0x7ffffff);
972 record->namespace_.is_executable =
973 (type_with_executable_bit & 0x80000000) != 0;
974 DCHECK(!record->namespace_.is_executable ||
975 CommandLine::ForCurrentProcess()->HasSwitch(kEnableExecutableHandlers));
954 } 976 }
955 977
956 void AppCacheDatabase::ReadOnlineWhiteListRecord( 978 void AppCacheDatabase::ReadOnlineWhiteListRecord(
957 const sql::Statement& statement, OnlineWhiteListRecord* record) { 979 const sql::Statement& statement, OnlineWhiteListRecord* record) {
958 record->cache_id = statement.ColumnInt64(0); 980 record->cache_id = statement.ColumnInt64(0);
959 record->namespace_url = GURL(statement.ColumnString(1)); 981 record->namespace_url = GURL(statement.ColumnString(1));
960 record->is_pattern = statement.ColumnBool(2); 982 record->is_pattern = statement.ColumnBool(2);
961 } 983 }
962 984
963 bool AppCacheDatabase::LazyOpen(bool create_if_needed) { 985 bool AppCacheDatabase::LazyOpen(bool create_if_needed) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1197
1176 // So we can't go recursive. 1198 // So we can't go recursive.
1177 if (is_recreating_) 1199 if (is_recreating_)
1178 return false; 1200 return false;
1179 1201
1180 base::AutoReset<bool> auto_reset(&is_recreating_, true); 1202 base::AutoReset<bool> auto_reset(&is_recreating_, true);
1181 return LazyOpen(true); 1203 return LazyOpen(true);
1182 } 1204 }
1183 1205
1184 } // namespace appcache 1206 } // namespace appcache
OLDNEW
« no previous file with comments | « no previous file | webkit/appcache/appcache_entry.h » ('j') | webkit/appcache/appcache_interfaces.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698