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

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

Issue 154053004: Introducing the activityLogPrivate.deleteActivities() API call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebasing Created 6 years, 10 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
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 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" 5 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 action->set_other(make_scoped_ptr( 213 action->set_other(make_scoped_ptr(
214 static_cast<base::DictionaryValue*>(parsed_value.release()))); 214 static_cast<base::DictionaryValue*>(parsed_value.release())));
215 } 215 }
216 } 216 }
217 actions->push_back(action); 217 actions->push_back(action);
218 } 218 }
219 219
220 return actions.Pass(); 220 return actions.Pass();
221 } 221 }
222 222
223 void FullStreamUIPolicy::DoRemoveActions(const std::vector<int64>& action_ids) {
224 if (action_ids.empty())
225 return;
226
227 sql::Connection* db = GetDatabaseConnection();
228 if (!db) {
229 LOG(ERROR) << "Unable to connect to database";
230 return;
231 }
232
233 // Flush data first so the activity removal affects queued-up data as well.
234 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
235
236 sql::Transaction transaction(db);
237 if (!transaction.Begin())
238 return;
239
240 std::string statement_str =
241 base::StringPrintf("DELETE FROM %s WHERE rowid = ?", kTableName);
242 sql::Statement statement(db->GetCachedStatement(
243 sql::StatementID(SQL_FROM_HERE), statement_str.c_str()));
244 for (size_t i = 0; i < action_ids.size(); i++) {
245 statement.Reset(true);
246 statement.BindInt64(0, action_ids[i]);
247 if (!statement.Run()) {
248 LOG(ERROR) << "Removing activities from database failed: "
249 << statement.GetSQLStatement();
250 return;
251 }
252 }
253
254 if (!transaction.Commit()) {
255 LOG(ERROR) << "Removing activities from database failed";
256 }
257 }
258
223 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { 259 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
224 sql::Connection* db = GetDatabaseConnection(); 260 sql::Connection* db = GetDatabaseConnection();
225 if (!db) { 261 if (!db) {
226 LOG(ERROR) << "Unable to connect to database"; 262 LOG(ERROR) << "Unable to connect to database";
227 return; 263 return;
228 } 264 }
229 265
230 // Make sure any queued in memory are sent to the database before cleaning. 266 // Make sure any queued in memory are sent to the database before cleaning.
231 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); 267 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
232 268
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 base::Unretained(this), 403 base::Unretained(this),
368 extension_id, 404 extension_id,
369 type, 405 type,
370 api_name, 406 api_name,
371 page_url, 407 page_url,
372 arg_url, 408 arg_url,
373 days_ago), 409 days_ago),
374 callback); 410 callback);
375 } 411 }
376 412
413 void FullStreamUIPolicy::RemoveActions(const std::vector<int64>& action_ids) {
414 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveActions, action_ids);
415 }
416
377 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { 417 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
378 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); 418 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls);
379 } 419 }
380 420
381 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { 421 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) {
382 ScheduleAndForget( 422 ScheduleAndForget(
383 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); 423 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id);
384 } 424 }
385 425
386 void FullStreamUIPolicy::DeleteDatabase() { 426 void FullStreamUIPolicy::DeleteDatabase() {
(...skipping 15 matching lines...) Expand all
402 } 442 }
403 443
404 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { 444 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) {
405 if (activity_database()->is_db_valid()) { 445 if (activity_database()->is_db_valid()) {
406 queued_actions_.push_back(action); 446 queued_actions_.push_back(action);
407 activity_database()->AdviseFlush(queued_actions_.size()); 447 activity_database()->AdviseFlush(queued_actions_.size());
408 } 448 }
409 } 449 }
410 450
411 } // namespace extensions 451 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698