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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 if (action.args()) { | 90 if (action.args()) { |
91 statement.BindString(4, Util::Serialize(action.args())); | 91 statement.BindString(4, Util::Serialize(action.args())); |
92 } | 92 } |
93 std::string page_url_string = action.SerializePageUrl(); | 93 std::string page_url_string = action.SerializePageUrl(); |
94 if (!page_url_string.empty()) { | 94 if (!page_url_string.empty()) { |
95 statement.BindString(5, page_url_string); | 95 statement.BindString(5, page_url_string); |
96 } | 96 } |
97 if (!action.page_title().empty()) { | 97 if (!action.page_title().empty()) { |
98 statement.BindString(6, action.page_title()); | 98 statement.BindString(6, action.page_title()); |
99 } | 99 } |
100 std::string arg_url_string = action.SerializePageUrl(); | 100 std::string arg_url_string = action.SerializeArgUrl(); |
101 if (!arg_url_string.empty()) { | 101 if (!arg_url_string.empty()) { |
102 statement.BindString(5, arg_url_string); | 102 statement.BindString(7, arg_url_string); |
103 } | 103 } |
104 if (action.other()) { | 104 if (action.other()) { |
105 statement.BindString(8, Util::Serialize(action.other())); | 105 statement.BindString(8, Util::Serialize(action.other())); |
106 } | 106 } |
107 | 107 |
108 if (!statement.Run()) { | 108 if (!statement.Run()) { |
109 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; | 109 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
110 return false; | 110 return false; |
111 } | 111 } |
112 } | 112 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7) | 180 LOG(WARNING) << "Unable to parse other: '" << query.ColumnString(7) |
181 << "'"; | 181 << "'"; |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 actions->push_back(action); | 185 actions->push_back(action); |
186 } | 186 } |
187 return actions.Pass(); | 187 return actions.Pass(); |
188 } | 188 } |
189 | 189 |
190 void FullStreamUIPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | |
191 sql::Connection* db = GetDatabaseConnection(); | |
192 if (!db) { | |
193 LOG(ERROR) << "Unable to connect to database"; | |
194 return; | |
195 } | |
196 | |
mvrable
2013/08/26 18:22:42
Add a
activity_database()->AdviseFlush(ActivityD
karenlees
2013/08/26 22:58:36
Done.
| |
197 // If no restrictions then then all URLs need to be removed. | |
198 if (restrict_urls.empty()) { | |
199 sql::Statement statement; | |
200 std::string sql_str = base::StringPrintf( | |
201 "UPDATE %s SET page_url=NULL,page_title=NULL,arg_url=NULL", | |
202 kTableName); | |
203 statement.Assign(db->GetCachedStatement( | |
204 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
205 | |
206 if (!statement.Run()) { | |
207 LOG(ERROR) << "Removing URLs from database failed: " | |
208 << statement.GetSQLStatement(); | |
209 } | |
210 return; | |
211 } | |
212 | |
213 // If URLs are specified then restrict to only those URLs. | |
214 for (uint32_t i = 0; i < restrict_urls.size(); ++i) { | |
mvrable
2013/08/26 20:38:50
size_t
karenlees
2013/08/26 22:58:36
Done.
| |
215 if (!restrict_urls[i].is_valid()) { | |
216 continue; | |
217 } | |
218 DLOG(INFO) << "Removing URL " << restrict_urls[i].spec(); | |
219 | |
220 sql::Statement statement; | |
221 std::string sql_str = base::StringPrintf( | |
222 "UPDATE %s SET page_url=NULL,page_title=NULL,arg_url=NULL " | |
223 "WHERE page_url=? OR arg_url=?", | |
224 kTableName); | |
225 statement.Assign(db->GetCachedStatement( | |
226 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
227 statement.BindString(0, restrict_urls[i].spec()); | |
228 statement.BindString(1, restrict_urls[i].spec()); | |
229 | |
230 if (!statement.Run()) { | |
231 LOG(ERROR) << "Removing URL from database failed: " | |
232 << statement.GetSQLStatement(); | |
233 } | |
234 } | |
235 } | |
236 | |
190 void FullStreamUIPolicy::OnDatabaseFailure() { | 237 void FullStreamUIPolicy::OnDatabaseFailure() { |
191 queued_actions_.clear(); | 238 queued_actions_.clear(); |
192 } | 239 } |
193 | 240 |
194 void FullStreamUIPolicy::OnDatabaseClose() { | 241 void FullStreamUIPolicy::OnDatabaseClose() { |
195 delete this; | 242 delete this; |
196 } | 243 } |
197 | 244 |
198 void FullStreamUIPolicy::Close() { | 245 void FullStreamUIPolicy::Close() { |
199 // The policy object should have never been created if there's no DB thread. | 246 // The policy object should have never been created if there's no DB thread. |
200 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 247 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
201 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 248 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
202 } | 249 } |
203 | 250 |
204 // Get data as a set of key-value pairs. The keys are policy-specific. | 251 // Get data as a set of key-value pairs. The keys are policy-specific. |
205 void FullStreamUIPolicy::ReadData( | 252 void FullStreamUIPolicy::ReadData( |
206 const std::string& extension_id, | 253 const std::string& extension_id, |
207 const int day, | 254 const int day, |
208 const Callback<void(scoped_ptr<Action::ActionVector>)>& callback) { | 255 const Callback<void(scoped_ptr<Action::ActionVector>)>& callback) { |
209 BrowserThread::PostTaskAndReplyWithResult( | 256 BrowserThread::PostTaskAndReplyWithResult( |
210 BrowserThread::DB, | 257 BrowserThread::DB, |
211 FROM_HERE, | 258 FROM_HERE, |
212 base::Bind(&FullStreamUIPolicy::DoReadData, | 259 base::Bind(&FullStreamUIPolicy::DoReadData, |
213 base::Unretained(this), | 260 base::Unretained(this), |
214 extension_id, | 261 extension_id, |
215 day), | 262 day), |
216 callback); | 263 callback); |
217 } | 264 } |
218 | 265 |
266 void FullStreamUIPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | |
267 BrowserThread::PostTask( | |
mvrable
2013/08/26 20:38:50
ScheduleAndForget should be able to do the same as
| |
268 BrowserThread::DB, | |
269 FROM_HERE, | |
270 base::Bind(&FullStreamUIPolicy::DoRemoveURLs, | |
271 base::Unretained(this), | |
272 restrict_urls)); | |
273 } | |
274 | |
219 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( | 275 scoped_refptr<Action> FullStreamUIPolicy::ProcessArguments( |
220 scoped_refptr<Action> action) const { | 276 scoped_refptr<Action> action) const { |
221 return action; | 277 return action; |
222 } | 278 } |
223 | 279 |
224 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { | 280 void FullStreamUIPolicy::ProcessAction(scoped_refptr<Action> action) { |
225 // TODO(mvrable): Right now this argument stripping updates the Action object | 281 // TODO(mvrable): Right now this argument stripping updates the Action object |
226 // in place, which isn't good if there are other users of the object. When | 282 // in place, which isn't good if there are other users of the object. When |
227 // database writing is moved to policy class, the modifications should be | 283 // database writing is moved to policy class, the modifications should be |
228 // made locally. | 284 // made locally. |
229 action = ProcessArguments(action); | 285 action = ProcessArguments(action); |
230 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); | 286 ScheduleAndForget(this, &FullStreamUIPolicy::QueueAction, action); |
231 } | 287 } |
232 | 288 |
233 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { | 289 void FullStreamUIPolicy::QueueAction(scoped_refptr<Action> action) { |
234 if (activity_database()->is_db_valid()) { | 290 if (activity_database()->is_db_valid()) { |
235 queued_actions_.push_back(action); | 291 queued_actions_.push_back(action); |
236 activity_database()->AdviseFlush(queued_actions_.size()); | 292 activity_database()->AdviseFlush(queued_actions_.size()); |
237 } | 293 } |
238 } | 294 } |
239 | 295 |
240 } // namespace extensions | 296 } // namespace extensions |
OLD | NEW |