Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/extensions/activity_log/fullstream_ui_policy.cc

Issue 18878009: Add functions to clean URLs from the activity log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert history file changes - will do them on a new CL Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) { 198 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) {
199 scoped_ptr<Value> parsed_value( 199 scoped_ptr<Value> parsed_value(
200 base::JSONReader::Read(query.ColumnString(8))); 200 base::JSONReader::Read(query.ColumnString(8)));
201 if (parsed_value && parsed_value->IsType(Value::TYPE_DICTIONARY)) { 201 if (parsed_value && parsed_value->IsType(Value::TYPE_DICTIONARY)) {
202 action->set_other(make_scoped_ptr( 202 action->set_other(make_scoped_ptr(
203 static_cast<DictionaryValue*>(parsed_value.release()))); 203 static_cast<DictionaryValue*>(parsed_value.release())));
204 } 204 }
205 } 205 }
206 actions->push_back(action); 206 actions->push_back(action);
207 } 207 }
208
209 return actions.Pass(); 208 return actions.Pass();
210 } 209 }
211 210
212 scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadData( 211 scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadData(
213 const std::string& extension_id, 212 const std::string& extension_id,
214 const int days_ago) { 213 const int days_ago) {
215 // Ensure data is flushed to the database first so that we query over all 214 // Ensure data is flushed to the database first so that we query over all
216 // data. 215 // data.
217 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); 216 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
218 217
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7) 270 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7)
272 << "'"; 271 << "'";
273 } 272 }
274 } 273 }
275 274
276 actions->push_back(action); 275 actions->push_back(action);
277 } 276 }
278 return actions.Pass(); 277 return actions.Pass();
279 } 278 }
280 279
280 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
281 sql::Connection* db = GetDatabaseConnection();
282 if (!db) {
283 LOG(ERROR) << "Unable to connect to database";
284 return;
285 }
286
287 // Make sure any queued in memory are sent to the database before cleaning.
288 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
289
290 // If no restrictions then then all URLs need to be removed.
291 if (restrict_urls.empty()) {
292 sql::Statement statement;
293 std::string sql_str = base::StringPrintf(
294 "UPDATE %s SET page_url=NULL,page_title=NULL,arg_url=NULL",
295 kTableName);
296 statement.Assign(db->GetCachedStatement(
297 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
298
299 if (!statement.Run()) {
300 LOG(ERROR) << "Removing URLs from database failed: "
301 << statement.GetSQLStatement();
302 }
303 return;
304 }
305
306 // If URLs are specified then restrict to only those URLs.
307 for (size_t i = 0; i < restrict_urls.size(); ++i) {
308 if (!restrict_urls[i].is_valid()) {
309 continue;
310 }
311
312 // Remove any matching page url info.
313 sql::Statement statement;
314 std::string sql_str = base::StringPrintf(
315 "UPDATE %s SET page_url=NULL,page_title=NULL WHERE page_url=?",
316 kTableName);
317 statement.Assign(db->GetCachedStatement(
318 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
319 statement.BindString(0, restrict_urls[i].spec());
320
321 if (!statement.Run()) {
322 LOG(ERROR) << "Removing page URL from database failed: "
323 << statement.GetSQLStatement();
324 }
325
326 // Remove any matching arg urls.
327 sql_str = base::StringPrintf("UPDATE %s SET arg_url=NULL WHERE arg_url=?",
328 kTableName);
329 statement.Assign(db->GetCachedStatement(
330 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
331 statement.BindString(0, restrict_urls[i].spec());
332
333 if (!statement.Run()) {
334 LOG(ERROR) << "Removing arg URL from database failed: "
335 << statement.GetSQLStatement();
336 }
337 }
338 }
339
281 void FullStreamUIPolicy::OnDatabaseFailure() { 340 void FullStreamUIPolicy::OnDatabaseFailure() {
282 queued_actions_.clear(); 341 queued_actions_.clear();
283 } 342 }
284 343
285 void FullStreamUIPolicy::OnDatabaseClose() { 344 void FullStreamUIPolicy::OnDatabaseClose() {
286 delete this; 345 delete this;
287 } 346 }
288 347
289 void FullStreamUIPolicy::Close() { 348 void FullStreamUIPolicy::Close() {
290 // The policy object should have never been created if there's no DB thread. 349 // The policy object should have never been created if there's no DB thread.
(...skipping 30 matching lines...) Expand all
321 base::Bind(&FullStreamUIPolicy::DoReadFilteredData, 380 base::Bind(&FullStreamUIPolicy::DoReadFilteredData,
322 base::Unretained(this), 381 base::Unretained(this),
323 extension_id, 382 extension_id,
324 type, 383 type,
325 api_name, 384 api_name,
326 page_url, 385 page_url,
327 arg_url), 386 arg_url),
328 callback); 387 callback);
329 } 388 }
330 389
390 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
391 ScheduleAndForget(this, &FullStreamUIPolicy::DoRemoveURLs, restrict_urls);
392 }
393
331 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( 394 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments(
332 scoped_refptr<Action> action) const { 395 scoped_refptr<Action> action) const {
333 return action; 396 return action;
334 } 397 }
335 398
336 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { 399 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) {
337 // TODO(mvrable): Right now this argument stripping updates the Action object 400 // 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 401 // 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 402 // database writing is moved to policy class, the modifications should be
340 // made locally. 403 // made locally.
341 action = ProcessArguments(action); 404 action = ProcessArguments(action);
342 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); 405 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action);
343 } 406 }
344 407
345 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { 408 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) {
346 if (activity_database()->is_db_valid()) { 409 if (activity_database()->is_db_valid()) {
347 queued_actions_.push_back(action); 410 queued_actions_.push_back(action);
348 activity_database()->AdviseFlush(queued_actions_.size()); 411 activity_database()->AdviseFlush(queued_actions_.size());
349 } 412 }
350 } 413 }
351 414
352 } // namespace extensions 415 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698