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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 statement.BindString(0, restrict_urls[i].spec()); | 275 statement.BindString(0, restrict_urls[i].spec()); |
276 | 276 |
277 if (!statement.Run()) { | 277 if (!statement.Run()) { |
278 LOG(ERROR) << "Removing arg URL from database failed: " | 278 LOG(ERROR) << "Removing arg URL from database failed: " |
279 << statement.GetSQLStatement(); | 279 << statement.GetSQLStatement(); |
280 return; | 280 return; |
281 } | 281 } |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
| 285 void FullStreamUIPolicy::DoRemoveExtensionData( |
| 286 const std::string& extension_id) { |
| 287 if (extension_id.empty()) |
| 288 return; |
| 289 |
| 290 sql::Connection* db = GetDatabaseConnection(); |
| 291 if (!db) { |
| 292 LOG(ERROR) << "Unable to connect to database"; |
| 293 return; |
| 294 } |
| 295 |
| 296 // Make sure any queued in memory are sent to the database before cleaning. |
| 297 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
| 298 |
| 299 std::string sql_str = base::StringPrintf( |
| 300 "DELETE FROM %s WHERE extension_id=?", kTableName); |
| 301 sql::Statement statement; |
| 302 statement.Assign( |
| 303 db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
| 304 statement.BindString(0, extension_id); |
| 305 if (!statement.Run()) { |
| 306 LOG(ERROR) << "Removing URLs for extension " |
| 307 << extension_id << "from database failed: " |
| 308 << statement.GetSQLStatement(); |
| 309 } |
| 310 } |
| 311 |
285 void FullStreamUIPolicy::DoDeleteDatabase() { | 312 void FullStreamUIPolicy::DoDeleteDatabase() { |
286 sql::Connection* db = GetDatabaseConnection(); | 313 sql::Connection* db = GetDatabaseConnection(); |
287 if (!db) { | 314 if (!db) { |
288 LOG(ERROR) << "Unable to connect to database"; | 315 LOG(ERROR) << "Unable to connect to database"; |
289 return; | 316 return; |
290 } | 317 } |
291 | 318 |
292 queued_actions_.clear(); | 319 queued_actions_.clear(); |
293 | 320 |
294 // Not wrapped in a transaction because the deletion should happen even if | 321 // Not wrapped in a transaction because the deletion should happen even if |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 page_url, | 371 page_url, |
345 arg_url, | 372 arg_url, |
346 days_ago), | 373 days_ago), |
347 callback); | 374 callback); |
348 } | 375 } |
349 | 376 |
350 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 377 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
351 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | 378 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); |
352 } | 379 } |
353 | 380 |
| 381 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { |
| 382 ScheduleAndForget( |
| 383 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); |
| 384 } |
| 385 |
354 void FullStreamUIPolicy::DeleteDatabase() { | 386 void FullStreamUIPolicy::DeleteDatabase() { |
355 ScheduleAndForget(this, &FullStreamUIPolicy::DoDeleteDatabase); | 387 ScheduleAndForget(this, &FullStreamUIPolicy::DoDeleteDatabase); |
356 } | 388 } |
357 | 389 |
358 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( | 390 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( |
359 scoped_refptr<Action> action) const { | 391 scoped_refptr<Action> action) const { |
360 return action; | 392 return action; |
361 } | 393 } |
362 | 394 |
363 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { | 395 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
364 // TODO(mvrable): Right now this argument stripping updates the Action object | 396 // TODO(mvrable): Right now this argument stripping updates the Action object |
365 // in place, which isn't good if there are other users of the object. When | 397 // in place, which isn't good if there are other users of the object. When |
366 // database writing is moved to policy class, the modifications should be | 398 // database writing is moved to policy class, the modifications should be |
367 // made locally. | 399 // made locally. |
368 action = ProcessArguments(action); | 400 action = ProcessArguments(action); |
369 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); | 401 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); |
370 } | 402 } |
371 | 403 |
372 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 404 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
373 if (activity_database()->is_db_valid()) { | 405 if (activity_database()->is_db_valid()) { |
374 queued_actions_.push_back(action); | 406 queued_actions_.push_back(action); |
375 activity_database()->AdviseFlush(queued_actions_.size()); | 407 activity_database()->AdviseFlush(queued_actions_.size()); |
376 } | 408 } |
377 } | 409 } |
378 | 410 |
379 } // namespace extensions | 411 } // namespace extensions |
OLD | NEW |