| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 virtual int OnError(int error, | 221 virtual int OnError(int error, |
| 222 sql::Connection* connection, | 222 sql::Connection* connection, |
| 223 sql::Statement* stmt) OVERRIDE { | 223 sql::Statement* stmt) OVERRIDE { |
| 224 // Do not schedule killing database more than once. If the first time | 224 // Do not schedule killing database more than once. If the first time |
| 225 // failed, it is unlikely that a second time will be successful. | 225 // failed, it is unlikely that a second time will be successful. |
| 226 if (!scheduled_killing_database_ && sql::IsErrorCatastrophic(error)) { | 226 if (!scheduled_killing_database_ && sql::IsErrorCatastrophic(error)) { |
| 227 scheduled_killing_database_ = true; | 227 scheduled_killing_database_ = true; |
| 228 | 228 |
| 229 // Don't just do the close/delete here, as we are being called by |db| and | 229 // Don't just do the close/delete here, as we are being called by |db| and |
| 230 // that seems dangerous. | 230 // that seems dangerous. |
| 231 MessageLoop::current()->PostTask( | 231 base::MessageLoop::current()->PostTask( |
| 232 FROM_HERE, | 232 FROM_HERE, |
| 233 base::Bind(&HistoryBackend::KillHistoryDatabase, backend_)); | 233 base::Bind(&HistoryBackend::KillHistoryDatabase, backend_)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 return error; | 236 return error; |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Returns true if the delegate has previously scheduled killing the database. | 239 // Returns true if the delegate has previously scheduled killing the database. |
| 240 bool scheduled_killing_database() const { | 240 bool scheduled_killing_database() const { |
| 241 return scheduled_killing_database_; | 241 return scheduled_killing_database_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 file_util::Delete(GetAndroidCacheFileName(), false); | 291 file_util::Delete(GetAndroidCacheFileName(), false); |
| 292 #endif | 292 #endif |
| 293 } | 293 } |
| 294 | 294 |
| 295 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 295 void HistoryBackend::Init(const std::string& languages, bool force_fail) { |
| 296 if (!force_fail) | 296 if (!force_fail) |
| 297 InitImpl(languages); | 297 InitImpl(languages); |
| 298 delegate_->DBLoaded(id_); | 298 delegate_->DBLoaded(id_); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop, | 301 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
| 302 const base::Closure& task) { | 302 const base::Closure& task) { |
| 303 if (!backend_destroy_task_.is_null()) | 303 if (!backend_destroy_task_.is_null()) |
| 304 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 304 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
| 305 backend_destroy_message_loop_ = message_loop; | 305 backend_destroy_message_loop_ = message_loop; |
| 306 backend_destroy_task_ = task; | 306 backend_destroy_task_ = task; |
| 307 } | 307 } |
| 308 | 308 |
| 309 void HistoryBackend::Closing() { | 309 void HistoryBackend::Closing() { |
| 310 // Any scheduled commit will have a reference to us, we must make it | 310 // Any scheduled commit will have a reference to us, we must make it |
| 311 // release that reference before we can be destroyed. | 311 // release that reference before we can be destroyed. |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 return; | 1191 return; |
| 1192 | 1192 |
| 1193 if (db_.get()) { | 1193 if (db_.get()) { |
| 1194 db_->QuerySegmentUsage(from_time, max_result_count, &request->value.get()); | 1194 db_->QuerySegmentUsage(from_time, max_result_count, &request->value.get()); |
| 1195 | 1195 |
| 1196 // If this is the first time we query segments, invoke | 1196 // If this is the first time we query segments, invoke |
| 1197 // DeleteOldSegmentData asynchronously. We do this to cleanup old | 1197 // DeleteOldSegmentData asynchronously. We do this to cleanup old |
| 1198 // entries. | 1198 // entries. |
| 1199 if (!segment_queried_) { | 1199 if (!segment_queried_) { |
| 1200 segment_queried_ = true; | 1200 segment_queried_ = true; |
| 1201 MessageLoop::current()->PostTask( | 1201 base::MessageLoop::current()->PostTask( |
| 1202 FROM_HERE, | 1202 FROM_HERE, base::Bind(&HistoryBackend::DeleteOldSegmentData, this)); |
| 1203 base::Bind(&HistoryBackend::DeleteOldSegmentData, this)); | |
| 1204 } | 1203 } |
| 1205 } | 1204 } |
| 1206 request->ForwardResult(request->handle(), &request->value.get()); | 1205 request->ForwardResult(request->handle(), &request->value.get()); |
| 1207 } | 1206 } |
| 1208 | 1207 |
| 1209 void HistoryBackend::IncreaseSegmentDuration(const GURL& url, | 1208 void HistoryBackend::IncreaseSegmentDuration(const GURL& url, |
| 1210 base::Time time, | 1209 base::Time time, |
| 1211 base::TimeDelta delta) { | 1210 base::TimeDelta delta) { |
| 1212 if (!db_.get()) | 1211 if (!db_.get()) |
| 1213 return; | 1212 return; |
| (...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2621 if (text_database_.get()) { | 2620 if (text_database_.get()) { |
| 2622 text_database_->CommitTransaction(); | 2621 text_database_->CommitTransaction(); |
| 2623 text_database_->BeginTransaction(); | 2622 text_database_->BeginTransaction(); |
| 2624 } | 2623 } |
| 2625 } | 2624 } |
| 2626 | 2625 |
| 2627 void HistoryBackend::ScheduleCommit() { | 2626 void HistoryBackend::ScheduleCommit() { |
| 2628 if (scheduled_commit_.get()) | 2627 if (scheduled_commit_.get()) |
| 2629 return; | 2628 return; |
| 2630 scheduled_commit_ = new CommitLaterTask(this); | 2629 scheduled_commit_ = new CommitLaterTask(this); |
| 2631 MessageLoop::current()->PostDelayedTask( | 2630 base::MessageLoop::current()->PostDelayedTask( |
| 2632 FROM_HERE, | 2631 FROM_HERE, |
| 2633 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()), | 2632 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()), |
| 2634 base::TimeDelta::FromSeconds(kCommitIntervalSeconds)); | 2633 base::TimeDelta::FromSeconds(kCommitIntervalSeconds)); |
| 2635 } | 2634 } |
| 2636 | 2635 |
| 2637 void HistoryBackend::CancelScheduledCommit() { | 2636 void HistoryBackend::CancelScheduledCommit() { |
| 2638 if (scheduled_commit_) { | 2637 if (scheduled_commit_) { |
| 2639 scheduled_commit_->Cancel(); | 2638 scheduled_commit_->Cancel(); |
| 2640 scheduled_commit_ = NULL; | 2639 scheduled_commit_ = NULL; |
| 2641 } | 2640 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2661 db_task_requests_.pop_front(); | 2660 db_task_requests_.pop_front(); |
| 2662 if (request->value->RunOnDBThread(this, db_.get())) { | 2661 if (request->value->RunOnDBThread(this, db_.get())) { |
| 2663 // The task is done. Notify the callback. | 2662 // The task is done. Notify the callback. |
| 2664 request->ForwardResult(); | 2663 request->ForwardResult(); |
| 2665 // We AddRef'd the request before adding, need to release it now. | 2664 // We AddRef'd the request before adding, need to release it now. |
| 2666 request->Release(); | 2665 request->Release(); |
| 2667 } else { | 2666 } else { |
| 2668 // Tasks wants to run some more. Schedule it at the end of current tasks. | 2667 // Tasks wants to run some more. Schedule it at the end of current tasks. |
| 2669 db_task_requests_.push_back(request); | 2668 db_task_requests_.push_back(request); |
| 2670 // And process it after an invoke later. | 2669 // And process it after an invoke later. |
| 2671 MessageLoop::current()->PostTask( | 2670 base::MessageLoop::current()->PostTask( |
| 2672 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); | 2671 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); |
| 2673 } | 2672 } |
| 2674 } | 2673 } |
| 2675 | 2674 |
| 2676 void HistoryBackend::ReleaseDBTasks() { | 2675 void HistoryBackend::ReleaseDBTasks() { |
| 2677 for (std::list<HistoryDBTaskRequest*>::iterator i = | 2676 for (std::list<HistoryDBTaskRequest*>::iterator i = |
| 2678 db_task_requests_.begin(); i != db_task_requests_.end(); ++i) { | 2677 db_task_requests_.begin(); i != db_task_requests_.end(); ++i) { |
| 2679 (*i)->Release(); | 2678 (*i)->Release(); |
| 2680 } | 2679 } |
| 2681 db_task_requests_.clear(); | 2680 db_task_requests_.clear(); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3067 info.url_id = visit.url_id; | 3066 info.url_id = visit.url_id; |
| 3068 info.time = visit.visit_time; | 3067 info.time = visit.visit_time; |
| 3069 info.transition = visit.transition; | 3068 info.transition = visit.transition; |
| 3070 // If we don't have a delegate yet during setup or shutdown, we will drop | 3069 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 3071 // these notifications. | 3070 // these notifications. |
| 3072 if (delegate_.get()) | 3071 if (delegate_.get()) |
| 3073 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3072 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
| 3074 } | 3073 } |
| 3075 | 3074 |
| 3076 } // namespace history | 3075 } // namespace history |
| OLD | NEW |