| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 19 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 19 #include "chrome/browser/extensions/activity_log/activity_database.h" | 20 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "extensions/common/dom_action_types.h" | 24 #include "extensions/common/dom_action_types.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "sql/statement.h" | 26 #include "sql/statement.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 if (!transaction.Commit()) | 118 if (!transaction.Commit()) |
| 118 return false; | 119 return false; |
| 119 | 120 |
| 120 queued_actions_.clear(); | 121 queued_actions_.clear(); |
| 121 return true; | 122 return true; |
| 122 } | 123 } |
| 123 | 124 |
| 124 scoped_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData( | 125 std::unique_ptr<Action::ActionVector> FullStreamUIPolicy::DoReadFilteredData( |
| 125 const std::string& extension_id, | 126 const std::string& extension_id, |
| 126 const Action::ActionType type, | 127 const Action::ActionType type, |
| 127 const std::string& api_name, | 128 const std::string& api_name, |
| 128 const std::string& page_url, | 129 const std::string& page_url, |
| 129 const std::string& arg_url, | 130 const std::string& arg_url, |
| 130 const int days_ago) { | 131 const int days_ago) { |
| 131 // Ensure data is flushed to the database first so that we query over all | 132 // Ensure data is flushed to the database first so that we query over all |
| 132 // data. | 133 // data. |
| 133 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | 134 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
| 134 scoped_ptr<Action::ActionVector> actions(new Action::ActionVector()); | 135 std::unique_ptr<Action::ActionVector> actions(new Action::ActionVector()); |
| 135 | 136 |
| 136 sql::Connection* db = GetDatabaseConnection(); | 137 sql::Connection* db = GetDatabaseConnection(); |
| 137 if (!db) { | 138 if (!db) { |
| 138 return actions; | 139 return actions; |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Build up the query based on which parameters were specified. | 142 // Build up the query based on which parameters were specified. |
| 142 std::string where_str = ""; | 143 std::string where_str = ""; |
| 143 std::string where_next = ""; | 144 std::string where_next = ""; |
| 144 if (!extension_id.empty()) { | 145 if (!extension_id.empty()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 191 |
| 191 // Execute the query and get results. | 192 // Execute the query and get results. |
| 192 while (query.is_valid() && query.Step()) { | 193 while (query.is_valid() && query.Step()) { |
| 193 scoped_refptr<Action> action = | 194 scoped_refptr<Action> action = |
| 194 new Action(query.ColumnString(0), | 195 new Action(query.ColumnString(0), |
| 195 base::Time::FromInternalValue(query.ColumnInt64(1)), | 196 base::Time::FromInternalValue(query.ColumnInt64(1)), |
| 196 static_cast<Action::ActionType>(query.ColumnInt(2)), | 197 static_cast<Action::ActionType>(query.ColumnInt(2)), |
| 197 query.ColumnString(3), query.ColumnInt64(9)); | 198 query.ColumnString(3), query.ColumnInt64(9)); |
| 198 | 199 |
| 199 if (query.ColumnType(4) != sql::COLUMN_TYPE_NULL) { | 200 if (query.ColumnType(4) != sql::COLUMN_TYPE_NULL) { |
| 200 scoped_ptr<base::Value> parsed_value = | 201 std::unique_ptr<base::Value> parsed_value = |
| 201 base::JSONReader::Read(query.ColumnString(4)); | 202 base::JSONReader::Read(query.ColumnString(4)); |
| 202 if (parsed_value && parsed_value->IsType(base::Value::TYPE_LIST)) { | 203 if (parsed_value && parsed_value->IsType(base::Value::TYPE_LIST)) { |
| 203 action->set_args(make_scoped_ptr( | 204 action->set_args(base::WrapUnique( |
| 204 static_cast<base::ListValue*>(parsed_value.release()))); | 205 static_cast<base::ListValue*>(parsed_value.release()))); |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 | 208 |
| 208 action->ParsePageUrl(query.ColumnString(5)); | 209 action->ParsePageUrl(query.ColumnString(5)); |
| 209 action->set_page_title(query.ColumnString(6)); | 210 action->set_page_title(query.ColumnString(6)); |
| 210 action->ParseArgUrl(query.ColumnString(7)); | 211 action->ParseArgUrl(query.ColumnString(7)); |
| 211 | 212 |
| 212 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) { | 213 if (query.ColumnType(8) != sql::COLUMN_TYPE_NULL) { |
| 213 scoped_ptr<base::Value> parsed_value = | 214 std::unique_ptr<base::Value> parsed_value = |
| 214 base::JSONReader::Read(query.ColumnString(8)); | 215 base::JSONReader::Read(query.ColumnString(8)); |
| 215 if (parsed_value && parsed_value->IsType(base::Value::TYPE_DICTIONARY)) { | 216 if (parsed_value && parsed_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 216 action->set_other(make_scoped_ptr( | 217 action->set_other(base::WrapUnique( |
| 217 static_cast<base::DictionaryValue*>(parsed_value.release()))); | 218 static_cast<base::DictionaryValue*>(parsed_value.release()))); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 actions->push_back(action); | 221 actions->push_back(action); |
| 221 } | 222 } |
| 222 | 223 |
| 223 return actions; | 224 return actions; |
| 224 } | 225 } |
| 225 | 226 |
| 226 void FullStreamUIPolicy::DoRemoveActions( | 227 void FullStreamUIPolicy::DoRemoveActions( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 392 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
| 392 } | 393 } |
| 393 | 394 |
| 394 void FullStreamUIPolicy::ReadFilteredData( | 395 void FullStreamUIPolicy::ReadFilteredData( |
| 395 const std::string& extension_id, | 396 const std::string& extension_id, |
| 396 const Action::ActionType type, | 397 const Action::ActionType type, |
| 397 const std::string& api_name, | 398 const std::string& api_name, |
| 398 const std::string& page_url, | 399 const std::string& page_url, |
| 399 const std::string& arg_url, | 400 const std::string& arg_url, |
| 400 const int days_ago, | 401 const int days_ago, |
| 401 const base::Callback | 402 const base::Callback<void(std::unique_ptr<Action::ActionVector>)>& |
| 402 <void(scoped_ptr<Action::ActionVector>)>& callback) { | 403 callback) { |
| 403 BrowserThread::PostTaskAndReplyWithResult( | 404 BrowserThread::PostTaskAndReplyWithResult( |
| 404 BrowserThread::DB, | 405 BrowserThread::DB, |
| 405 FROM_HERE, | 406 FROM_HERE, |
| 406 base::Bind(&FullStreamUIPolicy::DoReadFilteredData, | 407 base::Bind(&FullStreamUIPolicy::DoReadFilteredData, |
| 407 base::Unretained(this), | 408 base::Unretained(this), |
| 408 extension_id, | 409 extension_id, |
| 409 type, | 410 type, |
| 410 api_name, | 411 api_name, |
| 411 page_url, | 412 page_url, |
| 412 arg_url, | 413 arg_url, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 447 } |
| 447 | 448 |
| 448 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 449 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
| 449 if (activity_database()->is_db_valid()) { | 450 if (activity_database()->is_db_valid()) { |
| 450 queued_actions_.push_back(action); | 451 queued_actions_.push_back(action); |
| 451 activity_database()->AdviseFlush(queued_actions_.size()); | 452 activity_database()->AdviseFlush(queued_actions_.size()); |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 | 455 |
| 455 } // namespace extensions | 456 } // namespace extensions |
| OLD | NEW |