| 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 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/history/typed_url_syncable_service.h" | 32 #include "chrome/browser/history/typed_url_syncable_service.h" |
| 33 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/importer/imported_favicon_usage.h" | 34 #include "chrome/common/importer/imported_favicon_usage.h" |
| 35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 36 #include "components/favicon_base/select_favicon_frames.h" | 36 #include "components/favicon_base/select_favicon_frames.h" |
| 37 #include "components/history/core/browser/download_constants.h" | 37 #include "components/history/core/browser/download_constants.h" |
| 38 #include "components/history/core/browser/download_row.h" | 38 #include "components/history/core/browser/download_row.h" |
| 39 #include "components/history/core/browser/history_backend_observer.h" | 39 #include "components/history/core/browser/history_backend_observer.h" |
| 40 #include "components/history/core/browser/history_client.h" | 40 #include "components/history/core/browser/history_client.h" |
| 41 #include "components/history/core/browser/history_constants.h" | 41 #include "components/history/core/browser/history_constants.h" |
| 42 #include "components/history/core/browser/history_database.h" |
| 43 #include "components/history/core/browser/history_database_params.h" |
| 42 #include "components/history/core/browser/history_db_task.h" | 44 #include "components/history/core/browser/history_db_task.h" |
| 43 #include "components/history/core/browser/keyword_search_term.h" | 45 #include "components/history/core/browser/keyword_search_term.h" |
| 44 #include "components/history/core/browser/page_usage_data.h" | 46 #include "components/history/core/browser/page_usage_data.h" |
| 45 #include "components/history/core/browser/visit_filter.h" | 47 #include "components/history/core/browser/visit_filter.h" |
| 46 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 48 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 47 #include "sql/error_delegate_util.h" | 49 #include "sql/error_delegate_util.h" |
| 48 #include "third_party/skia/include/core/SkBitmap.h" | 50 #include "third_party/skia/include/core/SkBitmap.h" |
| 49 #include "ui/gfx/codec/png_codec.h" | 51 #include "ui/gfx/codec/png_codec.h" |
| 50 #include "url/gurl.h" | 52 #include "url/gurl.h" |
| 51 | 53 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // Notify an interested party (typically a unit test) that we're done. | 226 // Notify an interested party (typically a unit test) that we're done. |
| 225 DCHECK(backend_destroy_message_loop_); | 227 DCHECK(backend_destroy_message_loop_); |
| 226 backend_destroy_message_loop_->PostTask(FROM_HERE, backend_destroy_task_); | 228 backend_destroy_message_loop_->PostTask(FROM_HERE, backend_destroy_task_); |
| 227 } | 229 } |
| 228 | 230 |
| 229 #if defined(OS_ANDROID) | 231 #if defined(OS_ANDROID) |
| 230 sql::Connection::Delete(GetAndroidCacheFileName()); | 232 sql::Connection::Delete(GetAndroidCacheFileName()); |
| 231 #endif | 233 #endif |
| 232 } | 234 } |
| 233 | 235 |
| 234 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 236 void HistoryBackend::Init( |
| 237 const std::string& languages, |
| 238 bool force_fail, |
| 239 const HistoryDatabaseParams& history_database_params) { |
| 235 if (!force_fail) | 240 if (!force_fail) |
| 236 InitImpl(languages); | 241 InitImpl(languages, history_database_params); |
| 237 delegate_->DBLoaded(); | 242 delegate_->DBLoaded(); |
| 238 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 243 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); |
| 239 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 244 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 240 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | 245 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); |
| 241 } | 246 } |
| 242 | 247 |
| 243 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, | 248 void HistoryBackend::SetOnBackendDestroyTask(base::MessageLoop* message_loop, |
| 244 const base::Closure& task) { | 249 const base::Closure& task) { |
| 245 if (!backend_destroy_task_.is_null()) | 250 if (!backend_destroy_task_.is_null()) |
| 246 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 251 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (stripped_transition != ui::PAGE_TRANSITION_AUTO_SUBFRAME && | 577 if (stripped_transition != ui::PAGE_TRANSITION_AUTO_SUBFRAME && |
| 573 stripped_transition != ui::PAGE_TRANSITION_MANUAL_SUBFRAME && | 578 stripped_transition != ui::PAGE_TRANSITION_MANUAL_SUBFRAME && |
| 574 !is_keyword_generated) { | 579 !is_keyword_generated) { |
| 575 tracker_.AddVisit(request.context_id, request.nav_entry_id, request.url, | 580 tracker_.AddVisit(request.context_id, request.nav_entry_id, request.url, |
| 576 last_ids.second); | 581 last_ids.second); |
| 577 } | 582 } |
| 578 | 583 |
| 579 ScheduleCommit(); | 584 ScheduleCommit(); |
| 580 } | 585 } |
| 581 | 586 |
| 582 void HistoryBackend::InitImpl(const std::string& languages) { | 587 void HistoryBackend::InitImpl( |
| 588 const std::string& languages, |
| 589 const HistoryDatabaseParams& history_database_params) { |
| 583 DCHECK(!db_) << "Initializing HistoryBackend twice"; | 590 DCHECK(!db_) << "Initializing HistoryBackend twice"; |
| 584 // In the rare case where the db fails to initialize a dialog may get shown | 591 // In the rare case where the db fails to initialize a dialog may get shown |
| 585 // the blocks the caller, yet allows other messages through. For this reason | 592 // the blocks the caller, yet allows other messages through. For this reason |
| 586 // we only set db_ to the created database if creation is successful. That | 593 // we only set db_ to the created database if creation is successful. That |
| 587 // way other methods won't do anything as db_ is still NULL. | 594 // way other methods won't do anything as db_ is still NULL. |
| 588 | 595 |
| 589 TimeTicks beginning_time = TimeTicks::Now(); | 596 TimeTicks beginning_time = TimeTicks::Now(); |
| 590 | 597 |
| 591 // Compute the file names. | 598 // Compute the file names. |
| 592 base::FilePath history_name = history_dir_.Append(history::kHistoryFilename); | 599 DCHECK(history_dir_ == history_database_params.history_dir); |
| 600 base::FilePath history_name = |
| 601 history_database_params.history_dir.Append(history::kHistoryFilename); |
| 593 base::FilePath thumbnail_name = GetFaviconsFileName(); | 602 base::FilePath thumbnail_name = GetFaviconsFileName(); |
| 594 base::FilePath archived_name = GetArchivedFileName(); | 603 base::FilePath archived_name = GetArchivedFileName(); |
| 595 | 604 |
| 596 // Delete the old index database files which are no longer used. | 605 // Delete the old index database files which are no longer used. |
| 597 DeleteFTSIndexDatabases(); | 606 DeleteFTSIndexDatabases(); |
| 598 | 607 |
| 599 // History database. | 608 // History database. |
| 600 db_.reset(new HistoryDatabase()); | 609 db_.reset(new HistoryDatabase( |
| 610 history_database_params.download_interrupt_reason_none, |
| 611 history_database_params.download_interrupt_reason_crash)); |
| 601 | 612 |
| 602 // Unretained to avoid a ref loop with db_. | 613 // Unretained to avoid a ref loop with db_. |
| 603 db_->set_error_callback( | 614 db_->set_error_callback( |
| 604 base::Bind(&HistoryBackend::DatabaseErrorCallback, | 615 base::Bind(&HistoryBackend::DatabaseErrorCallback, |
| 605 base::Unretained(this))); | 616 base::Unretained(this))); |
| 606 | 617 |
| 607 sql::InitStatus status = db_->Init(history_name); | 618 sql::InitStatus status = db_->Init(history_name); |
| 608 switch (status) { | 619 switch (status) { |
| 609 case sql::INIT_OK: | 620 case sql::INIT_OK: |
| 610 break; | 621 break; |
| (...skipping 2079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2690 info.url_id = visit.url_id; | 2701 info.url_id = visit.url_id; |
| 2691 info.time = visit.visit_time; | 2702 info.time = visit.visit_time; |
| 2692 info.transition = visit.transition; | 2703 info.transition = visit.transition; |
| 2693 // If we don't have a delegate yet during setup or shutdown, we will drop | 2704 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 2694 // these notifications. | 2705 // these notifications. |
| 2695 if (delegate_) | 2706 if (delegate_) |
| 2696 delegate_->NotifyAddVisit(info); | 2707 delegate_->NotifyAddVisit(info); |
| 2697 } | 2708 } |
| 2698 | 2709 |
| 2699 } // namespace history | 2710 } // namespace history |
| OLD | NEW |