| 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 db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
| 303 statement.BindString(0, extension_id); | |
| 304 if (!statement.Run()) { | |
| 305 LOG(ERROR) << "Removing URLs for extension " | |
| 306 << extension_id << "from database failed: " | |
| 307 << statement.GetSQLStatement(); | |
| 308 } | |
| 309 } | |
| 310 | |
| 311 void FullStreamUIPolicy::DoDeleteDatabase() { | 285 void FullStreamUIPolicy::DoDeleteDatabase() { |
| 312 sql::Connection* db = GetDatabaseConnection(); | 286 sql::Connection* db = GetDatabaseConnection(); |
| 313 if (!db) { | 287 if (!db) { |
| 314 LOG(ERROR) << "Unable to connect to database"; | 288 LOG(ERROR) << "Unable to connect to database"; |
| 315 return; | 289 return; |
| 316 } | 290 } |
| 317 | 291 |
| 318 queued_actions_.clear(); | 292 queued_actions_.clear(); |
| 319 | 293 |
| 320 // Not wrapped in a transaction because the deletion should happen even if | 294 // 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... |
| 370 page_url, | 344 page_url, |
| 371 arg_url, | 345 arg_url, |
| 372 days_ago), | 346 days_ago), |
| 373 callback); | 347 callback); |
| 374 } | 348 } |
| 375 | 349 |
| 376 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 350 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
| 377 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | 351 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); |
| 378 } | 352 } |
| 379 | 353 |
| 380 void FullStreamUIPolicy::RemoveExtensionData(const std::string& extension_id) { | |
| 381 ScheduleAndForget( | |
| 382 this, &FullStreamUIPolicy::DoRemoveExtensionData, extension_id); | |
| 383 } | |
| 384 | |
| 385 void FullStreamUIPolicy::DeleteDatabase() { | 354 void FullStreamUIPolicy::DeleteDatabase() { |
| 386 ScheduleAndForget(this, &FullStreamUIPolicy::DoDeleteDatabase); | 355 ScheduleAndForget(this, &FullStreamUIPolicy::DoDeleteDatabase); |
| 387 } | 356 } |
| 388 | 357 |
| 389 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( | 358 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( |
| 390 scoped_refptr<Action> action) const { | 359 scoped_refptr<Action> action) const { |
| 391 return action; | 360 return action; |
| 392 } | 361 } |
| 393 | 362 |
| 394 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { | 363 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
| 395 // TODO(mvrable): Right now this argument stripping updates the Action object | 364 // TODO(mvrable): Right now this argument stripping updates the Action object |
| 396 // in place, which isn't good if there are other users of the object. When | 365 // in place, which isn't good if there are other users of the object. When |
| 397 // database writing is moved to policy class, the modifications should be | 366 // database writing is moved to policy class, the modifications should be |
| 398 // made locally. | 367 // made locally. |
| 399 action = ProcessArguments(action); | 368 action = ProcessArguments(action); |
| 400 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); | 369 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); |
| 401 } | 370 } |
| 402 | 371 |
| 403 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 372 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
| 404 if (activity_database()->is_db_valid()) { | 373 if (activity_database()->is_db_valid()) { |
| 405 queued_actions_.push_back(action); | 374 queued_actions_.push_back(action); |
| 406 activity_database()->AdviseFlush(queued_actions_.size()); | 375 activity_database()->AdviseFlush(queued_actions_.size()); |
| 407 } | 376 } |
| 408 } | 377 } |
| 409 | 378 |
| 410 } // namespace extensions | 379 } // namespace extensions |
| OLD | NEW |