Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / activity_log / counting_policy.cc
index ae93466..432a627 100644 (file)
@@ -108,7 +108,8 @@ static const char kPolicyMiscSetup[] =
     "    x4.value AS page_url,\n"
     "    x5.value AS page_title,\n"
     "    x6.value AS arg_url,\n"
-    "    x7.value AS other\n"
+    "    x7.value AS other,\n"
+    "    activitylog_compressed.rowid AS activity_id\n"
     "FROM activitylog_compressed\n"
     "    LEFT JOIN string_ids AS x1 ON (x1.id = extension_id_x)\n"
     "    LEFT JOIN string_ids AS x2 ON (x2.id = api_name_x)\n"
@@ -456,8 +457,8 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
 
   std::string query_str = base::StringPrintf(
       "SELECT extension_id,time, action_type, api_name, args, page_url,"
-      "page_title, arg_url, other, count FROM %s %s %s ORDER BY count DESC,"
-      " time DESC LIMIT 300",
+      "page_title, arg_url, other, count, activity_id FROM %s %s %s ORDER BY "
+      "count DESC, time DESC LIMIT 300",
       kReadViewName,
       where_str.empty() ? "" : "WHERE",
       where_str.c_str());
@@ -487,7 +488,7 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
         new Action(query.ColumnString(0),
                    base::Time::FromInternalValue(query.ColumnInt64(1)),
                    static_cast<Action::ActionType>(query.ColumnInt(2)),
-                   query.ColumnString(3));
+                   query.ColumnString(3), query.ColumnInt64(10));
 
     if (query.ColumnType(4) != sql::COLUMN_TYPE_NULL) {
       scoped_ptr<base::Value> parsed_value(
@@ -517,6 +518,44 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
   return actions.Pass();
 }
 
+void CountingPolicy::DoRemoveActions(const std::vector<int64>& action_ids) {
+  if (action_ids.empty())
+    return;
+
+  sql::Connection* db = GetDatabaseConnection();
+  if (!db) {
+    LOG(ERROR) << "Unable to connect to database";
+    return;
+  }
+
+  // Flush data first so the activity removal affects queued-up data as well.
+  activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
+
+  sql::Transaction transaction(db);
+  if (!transaction.Begin())
+    return;
+
+  std::string statement_str =
+      base::StringPrintf("DELETE FROM %s WHERE rowid = ?", kTableName);
+  sql::Statement statement(db->GetCachedStatement(
+      sql::StatementID(SQL_FROM_HERE), statement_str.c_str()));
+  for (size_t i = 0; i < action_ids.size(); i++) {
+    statement.Reset(true);
+    statement.BindInt64(0, action_ids[i]);
+    if (!statement.Run()) {
+      LOG(ERROR) << "Removing activities from database failed: "
+                 << statement.GetSQLStatement();
+      break;
+    }
+  }
+
+  CleanStringTables(db);
+
+  if (!transaction.Commit()) {
+    LOG(ERROR) << "Removing activities from database failed";
+  }
+}
+
 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
   sql::Connection* db = GetDatabaseConnection();
   if (!db) {
@@ -644,6 +683,7 @@ void CountingPolicy::DoDeleteDatabase() {
     return;
   }
   statement.Clear();
+  string_table_.ClearCache();
   statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
                                           "DELETE FROM string_ids"));
   if (!statement.Run()) {
@@ -652,6 +692,7 @@ void CountingPolicy::DoDeleteDatabase() {
     return;
   }
   statement.Clear();
+  url_table_.ClearCache();
   statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
                                           "DELETE FROM url_ids"));
   if (!statement.Run()) {
@@ -691,6 +732,10 @@ void CountingPolicy::ReadFilteredData(
       callback);
 }
 
+void CountingPolicy::RemoveActions(const std::vector<int64>& action_ids) {
+  ScheduleAndForget(this, &CountingPolicy::DoRemoveActions, action_ids);
+}
+
 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
   ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls);
 }