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 "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/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> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/debug/dump_without_crashing.h" | |
19 #include "base/feature_list.h" | |
18 #include "base/files/file_enumerator.h" | 20 #include "base/files/file_enumerator.h" |
19 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
20 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
21 #include "base/rand_util.h" | 23 #include "base/rand_util.h" |
22 #include "base/sequenced_task_runner.h" | 24 #include "base/sequenced_task_runner.h" |
23 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
26 #include "base/time/time.h" | 28 #include "base/time/time.h" |
27 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
28 #include "build/build_config.h" | 30 #include "build/build_config.h" |
29 #include "components/favicon_base/favicon_util.h" | 31 #include "components/favicon_base/favicon_util.h" |
30 #include "components/favicon_base/select_favicon_frames.h" | 32 #include "components/favicon_base/select_favicon_frames.h" |
31 #include "components/history/core/browser/download_constants.h" | 33 #include "components/history/core/browser/download_constants.h" |
32 #include "components/history/core/browser/download_row.h" | 34 #include "components/history/core/browser/download_row.h" |
33 #include "components/history/core/browser/history_backend_client.h" | 35 #include "components/history/core/browser/history_backend_client.h" |
34 #include "components/history/core/browser/history_backend_observer.h" | 36 #include "components/history/core/browser/history_backend_observer.h" |
35 #include "components/history/core/browser/history_constants.h" | 37 #include "components/history/core/browser/history_constants.h" |
36 #include "components/history/core/browser/history_database.h" | 38 #include "components/history/core/browser/history_database.h" |
37 #include "components/history/core/browser/history_database_params.h" | 39 #include "components/history/core/browser/history_database_params.h" |
38 #include "components/history/core/browser/history_db_task.h" | 40 #include "components/history/core/browser/history_db_task.h" |
39 #include "components/history/core/browser/in_memory_history_backend.h" | 41 #include "components/history/core/browser/in_memory_history_backend.h" |
40 #include "components/history/core/browser/keyword_search_term.h" | 42 #include "components/history/core/browser/keyword_search_term.h" |
41 #include "components/history/core/browser/page_usage_data.h" | 43 #include "components/history/core/browser/page_usage_data.h" |
44 #include "components/history/core/browser/typed_url_sync_bridge.h" | |
42 #include "components/history/core/browser/typed_url_syncable_service.h" | 45 #include "components/history/core/browser/typed_url_syncable_service.h" |
43 #include "components/history/core/browser/url_utils.h" | 46 #include "components/history/core/browser/url_utils.h" |
47 #include "components/sync/driver/sync_driver_switches.h" | |
44 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 48 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
45 #include "sql/error_delegate_util.h" | 49 #include "sql/error_delegate_util.h" |
46 #include "third_party/skia/include/core/SkBitmap.h" | 50 #include "third_party/skia/include/core/SkBitmap.h" |
47 #include "ui/gfx/codec/png_codec.h" | 51 #include "ui/gfx/codec/png_codec.h" |
48 #include "url/gurl.h" | 52 #include "url/gurl.h" |
49 #include "url/url_constants.h" | 53 #include "url/url_constants.h" |
50 | 54 |
51 #if defined(OS_IOS) | 55 #if defined(OS_IOS) |
52 #include "base/ios/scoped_critical_action.h" | 56 #include "base/ios/scoped_critical_action.h" |
53 #endif | 57 #endif |
54 | 58 |
59 using base::debug::DumpWithoutCrashing; | |
55 using base::Time; | 60 using base::Time; |
56 using base::TimeDelta; | 61 using base::TimeDelta; |
57 using base::TimeTicks; | 62 using base::TimeTicks; |
63 using syncer::ModelTypeChangeProcessor; | |
58 | 64 |
59 /* The HistoryBackend consists of two components: | 65 /* The HistoryBackend consists of two components: |
60 | 66 |
61 HistoryDatabase (stores past 3 months of history) | 67 HistoryDatabase (stores past 3 months of history) |
62 URLDatabase (stores a list of URLs) | 68 URLDatabase (stores a list of URLs) |
63 DownloadDatabase (stores a list of downloads) | 69 DownloadDatabase (stores a list of downloads) |
64 VisitDatabase (stores a list of visits for the URLs) | 70 VisitDatabase (stores a list of visits for the URLs) |
65 VisitSegmentDatabase (stores groups of URLs for the most visited view). | 71 VisitSegmentDatabase (stores groups of URLs for the most visited view). |
66 | 72 |
67 ExpireHistoryBackend (manages deleting things older than 3 months) | 73 ExpireHistoryBackend (manages deleting things older than 3 months) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 bool force_fail, | 210 bool force_fail, |
205 const HistoryDatabaseParams& history_database_params) { | 211 const HistoryDatabaseParams& history_database_params) { |
206 // HistoryBackend is created on the UI thread by HistoryService, then the | 212 // HistoryBackend is created on the UI thread by HistoryService, then the |
207 // HistoryBackend::Init() method is called on the DB thread. Create the | 213 // HistoryBackend::Init() method is called on the DB thread. Create the |
208 // base::SupportsUserData on the DB thread since it is not thread-safe. | 214 // base::SupportsUserData on the DB thread since it is not thread-safe. |
209 supports_user_data_helper_.reset(new HistoryBackendHelper); | 215 supports_user_data_helper_.reset(new HistoryBackendHelper); |
210 | 216 |
211 if (!force_fail) | 217 if (!force_fail) |
212 InitImpl(history_database_params); | 218 InitImpl(history_database_params); |
213 delegate_->DBLoaded(); | 219 delegate_->DBLoaded(); |
214 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | 220 if (base::FeatureList::IsEnabled(switches::kSyncUSSTypedURL)) { |
221 typed_url_sync_bridge_ = base::MakeUnique<TypedURLSyncBridge>( | |
222 this, | |
223 base::BindRepeating( | |
224 &ModelTypeChangeProcessor::Create, | |
225 base::BindRepeating(base::IgnoreResult(&DumpWithoutCrashing)))); | |
skym
2017/03/07 18:08:04
Ugh. Okay, this is kind of a land mine that we're
Gang Wu
2017/03/31 19:35:58
Done.
| |
226 } else { | |
227 typed_url_syncable_service_ = | |
228 base::MakeUnique<TypedUrlSyncableService>(this); | |
229 } | |
230 | |
215 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 231 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
216 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); | 232 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); |
217 } | 233 } |
218 | 234 |
219 void HistoryBackend::SetOnBackendDestroyTask( | 235 void HistoryBackend::SetOnBackendDestroyTask( |
220 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 236 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
221 const base::Closure& task) { | 237 const base::Closure& task) { |
222 if (!backend_destroy_task_.is_null()) | 238 if (!backend_destroy_task_.is_null()) |
223 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 239 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
224 backend_destroy_task_runner_ = std::move(task_runner); | 240 backend_destroy_task_runner_ = std::move(task_runner); |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 result->success = db_ && db_->GetRowForURL(url, &result->row); | 1040 result->success = db_ && db_->GetRowForURL(url, &result->row); |
1025 // Optionally query the visits. | 1041 // Optionally query the visits. |
1026 if (result->success && want_visits) | 1042 if (result->success && want_visits) |
1027 db_->GetVisitsForURL(result->row.id(), &result->visits); | 1043 db_->GetVisitsForURL(result->row.id(), &result->visits); |
1028 } | 1044 } |
1029 | 1045 |
1030 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const { | 1046 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const { |
1031 return typed_url_syncable_service_.get(); | 1047 return typed_url_syncable_service_.get(); |
1032 } | 1048 } |
1033 | 1049 |
1050 TypedURLSyncBridge* HistoryBackend::GetTypedURLSyncBridge() const { | |
1051 return typed_url_sync_bridge_.get(); | |
1052 } | |
1053 | |
1034 // Statistics ------------------------------------------------------------------ | 1054 // Statistics ------------------------------------------------------------------ |
1035 | 1055 |
1036 HistoryCountResult HistoryBackend::GetHistoryCount(const Time& begin_time, | 1056 HistoryCountResult HistoryBackend::GetHistoryCount(const Time& begin_time, |
1037 const Time& end_time) { | 1057 const Time& end_time) { |
1038 HistoryCountResult result; | 1058 HistoryCountResult result; |
1039 result.count = 0; | 1059 result.count = 0; |
1040 result.success = | 1060 result.success = |
1041 db_ && db_->GetHistoryCount(begin_time, end_time, &result.count); | 1061 db_ && db_->GetHistoryCount(begin_time, end_time, &result.count); |
1042 return result; | 1062 return result; |
1043 } | 1063 } |
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2601 // transaction is currently open. | 2621 // transaction is currently open. |
2602 db_->CommitTransaction(); | 2622 db_->CommitTransaction(); |
2603 db_->Vacuum(); | 2623 db_->Vacuum(); |
2604 db_->BeginTransaction(); | 2624 db_->BeginTransaction(); |
2605 db_->GetStartDate(&first_recorded_time_); | 2625 db_->GetStartDate(&first_recorded_time_); |
2606 | 2626 |
2607 return true; | 2627 return true; |
2608 } | 2628 } |
2609 | 2629 |
2610 } // namespace history | 2630 } // namespace history |
OLD | NEW |