OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 virtual int OnError(int error, | 224 virtual int OnError(int error, |
225 sql::Connection* connection, | 225 sql::Connection* connection, |
226 sql::Statement* stmt) OVERRIDE { | 226 sql::Statement* stmt) OVERRIDE { |
227 // Do not schedule killing database more than once. If the first time | 227 // Do not schedule killing database more than once. If the first time |
228 // failed, it is unlikely that a second time will be successful. | 228 // failed, it is unlikely that a second time will be successful. |
229 if (!scheduled_killing_database_ && sql::IsErrorCatastrophic(error)) { | 229 if (!scheduled_killing_database_ && sql::IsErrorCatastrophic(error)) { |
230 scheduled_killing_database_ = true; | 230 scheduled_killing_database_ = true; |
231 | 231 |
232 // Don't just do the close/delete here, as we are being called by |db| and | 232 // Don't just do the close/delete here, as we are being called by |db| and |
233 // that seems dangerous. | 233 // that seems dangerous. |
234 MessageLoop::current()->PostTask( | 234 base::MessageLoop::current()->PostTask( |
235 FROM_HERE, | 235 FROM_HERE, |
236 base::Bind(&HistoryBackend::KillHistoryDatabase, backend_)); | 236 base::Bind(&HistoryBackend::KillHistoryDatabase, backend_)); |
237 } | 237 } |
238 | 238 |
239 return error; | 239 return error; |
240 } | 240 } |
241 | 241 |
242 // Returns true if the delegate has previously scheduled killing the database. | 242 // Returns true if the delegate has previously scheduled killing the database. |
243 bool scheduled_killing_database() const { | 243 bool scheduled_killing_database() const { |
244 return scheduled_killing_database_; | 244 return scheduled_killing_database_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 #endif | 295 #endif |
296 } | 296 } |
297 | 297 |
298 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 298 void HistoryBackend::Init(const std::string& languages, bool force_fail) { |
299 if (!force_fail) | 299 if (!force_fail) |
300 InitImpl(languages); | 300 InitImpl(languages); |
301 delegate_->DBLoaded(id_); | 301 delegate_->DBLoaded(id_); |
302 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 302 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
303 } | 303 } |
304 | 304 |
305 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop, | 305 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
306 const base::Closure& task) { | 306 const base::Closure& task) { |
307 if (!backend_destroy_task_.is_null()) | 307 if (!backend_destroy_task_.is_null()) |
308 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 308 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
309 backend_destroy_message_loop_ = message_loop; | 309 backend_destroy_message_loop_ = message_loop; |
310 backend_destroy_task_ = task; | 310 backend_destroy_task_ = task; |
311 } | 311 } |
312 | 312 |
313 void HistoryBackend::Closing() { | 313 void HistoryBackend::Closing() { |
314 // Any scheduled commit will have a reference to us, we must make it | 314 // Any scheduled commit will have a reference to us, we must make it |
315 // release that reference before we can be destroyed. | 315 // release that reference before we can be destroyed. |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 return; | 1211 return; |
1212 | 1212 |
1213 if (db_) { | 1213 if (db_) { |
1214 db_->QuerySegmentUsage(from_time, max_result_count, &request->value.get()); | 1214 db_->QuerySegmentUsage(from_time, max_result_count, &request->value.get()); |
1215 | 1215 |
1216 // If this is the first time we query segments, invoke | 1216 // If this is the first time we query segments, invoke |
1217 // DeleteOldSegmentData asynchronously. We do this to cleanup old | 1217 // DeleteOldSegmentData asynchronously. We do this to cleanup old |
1218 // entries. | 1218 // entries. |
1219 if (!segment_queried_) { | 1219 if (!segment_queried_) { |
1220 segment_queried_ = true; | 1220 segment_queried_ = true; |
1221 MessageLoop::current()->PostTask( | 1221 base::MessageLoop::current()->PostTask( |
1222 FROM_HERE, | 1222 FROM_HERE, |
1223 base::Bind(&HistoryBackend::DeleteOldSegmentData, this)); | 1223 base::Bind(&HistoryBackend::DeleteOldSegmentData, this)); |
1224 } | 1224 } |
1225 } | 1225 } |
1226 request->ForwardResult(request->handle(), &request->value.get()); | 1226 request->ForwardResult(request->handle(), &request->value.get()); |
1227 } | 1227 } |
1228 | 1228 |
1229 void HistoryBackend::IncreaseSegmentDuration(const GURL& url, | 1229 void HistoryBackend::IncreaseSegmentDuration(const GURL& url, |
1230 base::Time time, | 1230 base::Time time, |
1231 base::TimeDelta delta) { | 1231 base::TimeDelta delta) { |
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2644 if (text_database_) { | 2644 if (text_database_) { |
2645 text_database_->CommitTransaction(); | 2645 text_database_->CommitTransaction(); |
2646 text_database_->BeginTransaction(); | 2646 text_database_->BeginTransaction(); |
2647 } | 2647 } |
2648 } | 2648 } |
2649 | 2649 |
2650 void HistoryBackend::ScheduleCommit() { | 2650 void HistoryBackend::ScheduleCommit() { |
2651 if (scheduled_commit_) | 2651 if (scheduled_commit_) |
2652 return; | 2652 return; |
2653 scheduled_commit_ = new CommitLaterTask(this); | 2653 scheduled_commit_ = new CommitLaterTask(this); |
2654 MessageLoop::current()->PostDelayedTask( | 2654 base::MessageLoop::current()->PostDelayedTask( |
2655 FROM_HERE, | 2655 FROM_HERE, |
2656 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()), | 2656 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()), |
2657 base::TimeDelta::FromSeconds(kCommitIntervalSeconds)); | 2657 base::TimeDelta::FromSeconds(kCommitIntervalSeconds)); |
2658 } | 2658 } |
2659 | 2659 |
2660 void HistoryBackend::CancelScheduledCommit() { | 2660 void HistoryBackend::CancelScheduledCommit() { |
2661 if (scheduled_commit_) { | 2661 if (scheduled_commit_) { |
2662 scheduled_commit_->Cancel(); | 2662 scheduled_commit_->Cancel(); |
2663 scheduled_commit_ = NULL; | 2663 scheduled_commit_ = NULL; |
2664 } | 2664 } |
(...skipping 19 matching lines...) Expand all Loading... |
2684 db_task_requests_.pop_front(); | 2684 db_task_requests_.pop_front(); |
2685 if (request->value->RunOnDBThread(this, db_.get())) { | 2685 if (request->value->RunOnDBThread(this, db_.get())) { |
2686 // The task is done. Notify the callback. | 2686 // The task is done. Notify the callback. |
2687 request->ForwardResult(); | 2687 request->ForwardResult(); |
2688 // We AddRef'd the request before adding, need to release it now. | 2688 // We AddRef'd the request before adding, need to release it now. |
2689 request->Release(); | 2689 request->Release(); |
2690 } else { | 2690 } else { |
2691 // Tasks wants to run some more. Schedule it at the end of current tasks. | 2691 // Tasks wants to run some more. Schedule it at the end of current tasks. |
2692 db_task_requests_.push_back(request); | 2692 db_task_requests_.push_back(request); |
2693 // And process it after an invoke later. | 2693 // And process it after an invoke later. |
2694 MessageLoop::current()->PostTask( | 2694 base::MessageLoop::current()->PostTask( |
2695 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); | 2695 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); |
2696 } | 2696 } |
2697 } | 2697 } |
2698 | 2698 |
2699 void HistoryBackend::ReleaseDBTasks() { | 2699 void HistoryBackend::ReleaseDBTasks() { |
2700 for (std::list<HistoryDBTaskRequest*>::iterator i = | 2700 for (std::list<HistoryDBTaskRequest*>::iterator i = |
2701 db_task_requests_.begin(); i != db_task_requests_.end(); ++i) { | 2701 db_task_requests_.begin(); i != db_task_requests_.end(); ++i) { |
2702 (*i)->Release(); | 2702 (*i)->Release(); |
2703 } | 2703 } |
2704 db_task_requests_.clear(); | 2704 db_task_requests_.clear(); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 info.url_id = visit.url_id; | 3098 info.url_id = visit.url_id; |
3099 info.time = visit.visit_time; | 3099 info.time = visit.visit_time; |
3100 info.transition = visit.transition; | 3100 info.transition = visit.transition; |
3101 // If we don't have a delegate yet during setup or shutdown, we will drop | 3101 // If we don't have a delegate yet during setup or shutdown, we will drop |
3102 // these notifications. | 3102 // these notifications. |
3103 if (delegate_) | 3103 if (delegate_) |
3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3105 } | 3105 } |
3106 | 3106 |
3107 } // namespace history | 3107 } // namespace history |
OLD | NEW |