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 int batch_size = 50; |
| 237 int iter = action_ids.size() / batch_size; |
| 238 for (int i = 0; i < iter; i++) { |
| 239 int start = i * batch_size; |
| 240 int end = start + batch_size; |
| 241 std::string rowid_set; |
| 242 for (int j = start; j < end; j++) { |
| 243 rowid_set += "?,"; |
| 244 } |
| 245 // Delete the last comma from the set. |
| 246 rowid_set = rowid_set.substr(0, rowid_set.length() - 1); |
| 247 std::string query_str = base::StringPrintf( |
| 248 "DELETE FROM %s WHERE rowid in (%s)", kTableName, rowid_set.c_str()); |
| 249 sql::Statement query(db->GetUniqueStatement(query_str.c_str())); |
| 250 for (int j = start; j < end; j++) { |
| 251 query.BindInt64(j - start, action_ids[j]); |
| 252 } |
| 253 if (!query.Run()) { |
| 254 LOG(ERROR) << "Removing activities from database failed: " |
| 255 << query.GetSQLStatement(); |
| 256 return; |
| 257 } |
| 258 } |
| 259 int start = iter * batch_size; |
| 260 int end = action_ids.size(); |
| 261 std::string rowid_set; |
| 262 for (int i = start; i < end; i++) { |
| 263 rowid_set += "?,"; |
| 264 } |
| 265 // Delete the last comma from the set. |
| 266 rowid_set = rowid_set.substr(0, rowid_set.length() - 1); |
| 267 std::string query_str = base::StringPrintf( |
| 268 "DELETE FROM %s WHERE rowid in (%s)", kTableName, rowid_set.c_str()); |
| 269 sql::Statement query(db->GetUniqueStatement(query_str.c_str())); |
| 270 for (int i = start; i < end; i++) { |
| 271 query.BindInt64(i - start, action_ids[i]); |
| 272 } |
| 273 if (!query.Run()) { |
| 274 LOG(ERROR) << "Removing activities from database failed: " |
| 275 << query.GetSQLStatement(); |
| 276 return; |
| 277 } |
| 278 } |
| 279 |
223 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | 280 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { |
224 sql::Connection* db = GetDatabaseConnection(); | 281 sql::Connection* db = GetDatabaseConnection(); |
225 if (!db) { | 282 if (!db) { |
226 LOG(ERROR) << "Unable to connect to database"; | 283 LOG(ERROR) << "Unable to connect to database"; |
227 return; | 284 return; |
228 } | 285 } |
229 | 286 |
230 // Make sure any queued in memory are sent to the database before cleaning. | 287 // Make sure any queued in memory are sent to the database before cleaning. |
231 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | 288 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
232 | 289 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 base::Unretained(this), | 424 base::Unretained(this), |
368 extension_id, | 425 extension_id, |
369 type, | 426 type, |
370 api_name, | 427 api_name, |
371 page_url, | 428 page_url, |
372 arg_url, | 429 arg_url, |
373 days_ago), | 430 days_ago), |
374 callback); | 431 callback); |
375 } | 432 } |
376 | 433 |
| 434 void FullStreamUIPolicy::RemoveActions(const std::vector<int64>& action_ids) { |
| 435 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveActions, action_ids); |
| 436 } |
| 437 |
377 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 438 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
378 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | 439 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); |
379 } | 440 } |
380 | 441 |
381 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { | 442 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { |
382 ScheduleAndForget( | 443 ScheduleAndForget( |
383 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); | 444 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); |
384 } | 445 } |
385 | 446 |
386 void FullStreamUIPolicy::DeleteDatabase() { | 447 void FullStreamUIPolicy::DeleteDatabase() { |
(...skipping 15 matching lines...) Expand all Loading... |
402 } | 463 } |
403 | 464 |
404 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 465 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
405 if (activity_database()->is_db_valid()) { | 466 if (activity_database()->is_db_valid()) { |
406 queued_actions_.push_back(action); | 467 queued_actions_.push_back(action); |
407 activity_database()->AdviseFlush(queued_actions_.size()); | 468 activity_database()->AdviseFlush(queued_actions_.size()); |
408 } | 469 } |
409 } | 470 } |
410 | 471 |
411 } // namespace extensions | 472 } // namespace extensions |
OLD | NEW |