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