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

Side by Side Diff: chrome/browser/extensions/activity_log/counting_policy.cc

Issue 22901002: Fix a copy-paste error in the extension activity log code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add comments about BindNull Created 7 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // A policy for storing activity log data to a database that performs 5 // A policy for storing activity log data to a database that performs
6 // aggregation to reduce the size of the database. The database layout is 6 // aggregation to reduce the size of the database. The database layout is
7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a 7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a
8 // few changes: 8 // few changes:
9 // - a "count" column is added to track how many log records were merged 9 // - a "count" column is added to track how many log records were merged
10 // together into this row 10 // together into this row
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
319 // Assume there is an existing row for this action, and try to update the 319 // Assume there is an existing row for this action, and try to update the
320 // count. 320 // count.
321 sql::Statement update_statement(db->GetCachedStatement( 321 sql::Statement update_statement(db->GetCachedStatement(
322 sql::StatementID(SQL_FROM_HERE), update_str.c_str())); 322 sql::StatementID(SQL_FROM_HERE), update_str.c_str()));
323 update_statement.BindInt64(0, action.time().ToInternalValue()); 323 update_statement.BindInt64(0, action.time().ToInternalValue());
324 update_statement.BindInt64(1, day_start.ToInternalValue()); 324 update_statement.BindInt64(1, day_start.ToInternalValue());
325 update_statement.BindInt64(2, next_day.ToInternalValue()); 325 update_statement.BindInt64(2, next_day.ToInternalValue());
326 for (size_t j = 0; j < matched_values.size(); j++) { 326 for (size_t j = 0; j < matched_values.size(); j++) {
327 // A call to BindNull when matched_values contains -1 is likely not
328 // necessary as parameters default to null before they are explicitly
329 // bound. But to be completely clear, and in case a cached statement
330 // ever comes with some values already bound, we bind all parameters
331 // (even null ones) explicitly.
327 if (matched_values[j] == -1) 332 if (matched_values[j] == -1)
328 update_statement.BindNull(j + 3); 333 update_statement.BindNull(j + 3);
329 else 334 else
330 update_statement.BindInt64(j + 3, matched_values[j]); 335 update_statement.BindInt64(j + 3, matched_values[j]);
331 } 336 }
332 if (!update_statement.Run()) 337 if (!update_statement.Run())
333 return false; 338 return false;
334 339
335 // Check if the update succeeded (was the count of updated rows non-zero)? 340 // Check if the update succeeded (was the count of updated rows non-zero)?
336 // If it failed because no matching row existed, fall back to inserting a 341 // If it failed because no matching row existed, fall back to inserting a
337 // new record. 342 // new record.
338 if (db->GetLastChangeCount() > 0) { 343 if (db->GetLastChangeCount() > 0) {
339 if (db->GetLastChangeCount() > 1) { 344 if (db->GetLastChangeCount() > 1) {
340 LOG(WARNING) << "Found and updated multiple rows in the activity log " 345 LOG(WARNING) << "Found and updated multiple rows in the activity log "
341 << "database; counts may be off!"; 346 << "database; counts may be off!";
342 } 347 }
343 continue; 348 continue;
344 } 349 }
345 sql::Statement insert_statement(db->GetCachedStatement( 350 sql::Statement insert_statement(db->GetCachedStatement(
346 sql::StatementID(SQL_FROM_HERE), insert_str.c_str())); 351 sql::StatementID(SQL_FROM_HERE), insert_str.c_str()));
347 insert_statement.BindInt64(0, action.time().ToInternalValue()); 352 insert_statement.BindInt64(0, action.time().ToInternalValue());
348 for (size_t j = 0; j < matched_values.size(); j++) { 353 for (size_t j = 0; j < matched_values.size(); j++) {
349 if (matched_values[j] == -1) 354 if (matched_values[j] == -1)
350 update_statement.BindNull(j + 1); 355 insert_statement.BindNull(j + 1);
351 else 356 else
352 insert_statement.BindInt64(j + 1, matched_values[j]); 357 insert_statement.BindInt64(j + 1, matched_values[j]);
353 } 358 }
354 if (!insert_statement.Run()) 359 if (!insert_statement.Run())
355 return false; 360 return false;
356 } 361 }
357 362
358 if (clean_database) { 363 if (clean_database) {
359 base::Time cutoff = (Now() - retention_time()).LocalMidnight(); 364 base::Time cutoff = (Now() - retention_time()).LocalMidnight();
360 if (!CleanOlderThan(db, cutoff)) 365 if (!CleanOlderThan(db, cutoff))
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 return true; 501 return true;
497 } 502 }
498 503
499 void CountingPolicy::Close() { 504 void CountingPolicy::Close() {
500 // The policy object should have never been created if there's no DB thread. 505 // The policy object should have never been created if there's no DB thread.
501 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 506 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
502 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 507 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
503 } 508 }
504 509
505 } // namespace extensions 510 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698