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