Chromium Code Reviews| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7) | 271 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7) |
| 272 << "'"; | 272 << "'"; |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 actions->push_back(action); | 276 actions->push_back(action); |
| 277 } | 277 } |
| 278 return actions.Pass(); | 278 return actions.Pass(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | |
| 282 sql::Connection* db = GetDatabaseConnection(); | |
| 283 if (!db) { | |
| 284 LOG(ERROR) << "Unable to connect to database"; | |
| 285 return; | |
| 286 } | |
| 287 | |
| 288 // Make sure any queued in memory are sent to the database before cleaning. | |
| 289 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | |
| 290 | |
| 291 // If no restrictions then then all URLs need to be removed. | |
| 292 if (restrict_urls.empty()) { | |
| 293 sql::Statement statement; | |
| 294 std::string sql_str = base::StringPrintf( | |
| 295 "UPDATE %s SET page_url=NULL,page_title=NULL,arg_url=NULL", | |
| 296 kTableName); | |
| 297 statement.Assign(db->GetCachedStatement( | |
| 298 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
| 299 | |
| 300 if (!statement.Run()) { | |
| 301 LOG(ERROR) << "Removing URLs from database failed: " | |
| 302 << statement.GetSQLStatement(); | |
| 303 } | |
| 304 return; | |
|
felt
2013/08/27 23:16:55
is this return in the wrong block?
karenlees
2013/08/27 23:26:55
No, it was always supposed to return here as there
| |
| 305 } | |
| 306 | |
| 307 // If URLs are specified then restrict to only those URLs. | |
| 308 for (size_t i = 0; i < restrict_urls.size(); ++i) { | |
| 309 if (!restrict_urls[i].is_valid()) { | |
| 310 continue; | |
| 311 } | |
| 312 | |
| 313 // Remove any matching page url info. | |
| 314 sql::Statement statement; | |
| 315 std::string sql_str = base::StringPrintf( | |
| 316 "UPDATE %s SET page_url=NULL,page_title=NULL WHERE page_url=?", | |
| 317 kTableName); | |
| 318 statement.Assign(db->GetCachedStatement( | |
| 319 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
| 320 statement.BindString(0, restrict_urls[i].spec()); | |
| 321 | |
| 322 if (!statement.Run()) { | |
| 323 LOG(ERROR) << "Removing page URL from database failed: " | |
| 324 << statement.GetSQLStatement(); | |
| 325 return; | |
| 326 } | |
| 327 | |
| 328 // Remove any matching arg urls. | |
| 329 sql_str = base::StringPrintf("UPDATE %s SET arg_url=NULL WHERE arg_url=?", | |
| 330 kTableName); | |
| 331 statement.Assign(db->GetCachedStatement( | |
| 332 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
| 333 statement.BindString(0, restrict_urls[i].spec()); | |
| 334 | |
| 335 if (!statement.Run()) { | |
| 336 LOG(ERROR) << "Removing arg URL from database failed: " | |
| 337 << statement.GetSQLStatement(); | |
| 338 return; | |
| 339 } | |
| 340 } | |
| 341 } | |
| 342 | |
| 281 void FullStreamUIPolicy::OnDatabaseFailure() { | 343 void FullStreamUIPolicy::OnDatabaseFailure() { |
| 282 queued_actions_.clear(); | 344 queued_actions_.clear(); |
| 283 } | 345 } |
| 284 | 346 |
| 285 void FullStreamUIPolicy::OnDatabaseClose() { | 347 void FullStreamUIPolicy::OnDatabaseClose() { |
| 286 delete this; | 348 delete this; |
| 287 } | 349 } |
| 288 | 350 |
| 289 void FullStreamUIPolicy::Close() { | 351 void FullStreamUIPolicy::Close() { |
| 290 // The policy object should have never been created if there's no DB thread. | 352 // The policy object should have never been created if there's no DB thread. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 321 base::Bind(&FullStreamUIPolicy::DoReadFilteredData, | 383 base::Bind(&FullStreamUIPolicy::DoReadFilteredData, |
| 322 base::Unretained(this), | 384 base::Unretained(this), |
| 323 extension_id, | 385 extension_id, |
| 324 type, | 386 type, |
| 325 api_name, | 387 api_name, |
| 326 page_url, | 388 page_url, |
| 327 arg_url), | 389 arg_url), |
| 328 callback); | 390 callback); |
| 329 } | 391 } |
| 330 | 392 |
| 393 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | |
| 394 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls); | |
| 395 } | |
| 396 | |
| 331 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( | 397 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( |
| 332 scoped_refptr<Action> action) const { | 398 scoped_refptr<Action> action) const { |
| 333 return action; | 399 return action; |
| 334 } | 400 } |
| 335 | 401 |
| 336 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { | 402 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
| 337 // TODO(mvrable): Right now this argument stripping updates the Action object | 403 // TODO(mvrable): Right now this argument stripping updates the Action object |
| 338 // in place, which isn't good if there are other users of the object. When | 404 // in place, which isn't good if there are other users of the object. When |
| 339 // database writing is moved to policy class, the modifications should be | 405 // database writing is moved to policy class, the modifications should be |
| 340 // made locally. | 406 // made locally. |
| 341 action = ProcessArguments(action); | 407 action = ProcessArguments(action); |
| 342 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); | 408 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); |
| 343 } | 409 } |
| 344 | 410 |
| 345 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 411 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
| 346 if (activity_database()->is_db_valid()) { | 412 if (activity_database()->is_db_valid()) { |
| 347 queued_actions_.push_back(action); | 413 queued_actions_.push_back(action); |
| 348 activity_database()->AdviseFlush(queued_actions_.size()); | 414 activity_database()->AdviseFlush(queued_actions_.size()); |
| 349 } | 415 } |
| 350 } | 416 } |
| 351 | 417 |
| 352 } // namespace extensions | 418 } // namespace extensions |
| OLD | NEW |