OLD | NEW |
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 Loading... |
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 for (size_t i = 0; i < action_ids.size(); i++) { |
| 241 std::string query_str = |
| 242 base::StringPrintf("DELETE FROM %s WHERE rowid = ?", kTableName); |
| 243 sql::Statement query(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), |
| 244 query_str.c_str())); |
| 245 query.BindInt64(0, action_ids[i]); |
| 246 if (!query.Run()) { |
| 247 LOG(ERROR) << "Removing activities from database failed: " |
| 248 << query.GetSQLStatement(); |
| 249 return; |
| 250 } |
| 251 } |
| 252 |
| 253 if (!transaction.Commit()) { |
| 254 LOG(ERROR) << "Removing activities from database failed"; |
| 255 } |
| 256 } |
| 257 |
223 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | 258 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { |
224 sql::Connection* db = GetDatabaseConnection(); | 259 sql::Connection* db = GetDatabaseConnection(); |
225 if (!db) { | 260 if (!db) { |
226 LOG(ERROR) << "Unable to connect to database"; | 261 LOG(ERROR) << "Unable to connect to database"; |
227 return; | 262 return; |
228 } | 263 } |
229 | 264 |
230 // Make sure any queued in memory are sent to the database before cleaning. | 265 // Make sure any queued in memory are sent to the database before cleaning. |
231 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | 266 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
232 | 267 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 base::Unretained(this), | 402 base::Unretained(this), |
368 extension_id, | 403 extension_id, |
369 type, | 404 type, |
370 api_name, | 405 api_name, |
371 page_url, | 406 page_url, |
372 arg_url, | 407 arg_url, |
373 days_ago), | 408 days_ago), |
374 callback); | 409 callback); |
375 } | 410 } |
376 | 411 |
| 412 void FullStreamUIPolicy::RemoveActions(const std::vector<int64>& action_ids) { |
| 413 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveActions, action_ids); |
| 414 } |
| 415 |
377 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 416 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
378 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | 417 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); |
379 } | 418 } |
380 | 419 |
381 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { | 420 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { |
382 ScheduleAndForget( | 421 ScheduleAndForget( |
383 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); | 422 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); |
384 } | 423 } |
385 | 424 |
386 void FullStreamUIPolicy::DeleteDatabase() { | 425 void FullStreamUIPolicy::DeleteDatabase() { |
(...skipping 15 matching lines...) Expand all Loading... |
402 } | 441 } |
403 | 442 |
404 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 443 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
405 if (activity_database()->is_db_valid()) { | 444 if (activity_database()->is_db_valid()) { |
406 queued_actions_.push_back(action); | 445 queued_actions_.push_back(action); |
407 activity_database()->AdviseFlush(queued_actions_.size()); | 446 activity_database()->AdviseFlush(queued_actions_.size()); |
408 } | 447 } |
409 } | 448 } |
410 | 449 |
411 } // namespace extensions | 450 } // namespace extensions |
OLD | NEW |