Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2723953002: [sync] skeleton implementation of TypedURLSyncBridge (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // TODO(gangwu): use ReportUnrecoverableError before launch.
226 base::BindRepeating(base::IgnoreResult(&DumpWithoutCrashing))));
227 } else {
228 typed_url_syncable_service_ =
229 base::MakeUnique<TypedUrlSyncableService>(this);
230 }
231
215 memory_pressure_listener_.reset(new base::MemoryPressureListener( 232 memory_pressure_listener_.reset(new base::MemoryPressureListener(
216 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this)))); 233 base::Bind(&HistoryBackend::OnMemoryPressure, base::Unretained(this))));
217 } 234 }
218 235
219 void HistoryBackend::SetOnBackendDestroyTask( 236 void HistoryBackend::SetOnBackendDestroyTask(
220 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 237 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
221 const base::Closure& task) { 238 const base::Closure& task) {
222 if (!backend_destroy_task_.is_null()) 239 if (!backend_destroy_task_.is_null())
223 DLOG(WARNING) << "Setting more than one destroy task, overriding"; 240 DLOG(WARNING) << "Setting more than one destroy task, overriding";
224 backend_destroy_task_runner_ = std::move(task_runner); 241 backend_destroy_task_runner_ = std::move(task_runner);
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 result->success = db_ && db_->GetRowForURL(url, &result->row); 1046 result->success = db_ && db_->GetRowForURL(url, &result->row);
1030 // Optionally query the visits. 1047 // Optionally query the visits.
1031 if (result->success && want_visits) 1048 if (result->success && want_visits)
1032 db_->GetVisitsForURL(result->row.id(), &result->visits); 1049 db_->GetVisitsForURL(result->row.id(), &result->visits);
1033 } 1050 }
1034 1051
1035 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const { 1052 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const {
1036 return typed_url_syncable_service_.get(); 1053 return typed_url_syncable_service_.get();
1037 } 1054 }
1038 1055
1056 TypedURLSyncBridge* HistoryBackend::GetTypedURLSyncBridge() const {
1057 return typed_url_sync_bridge_.get();
1058 }
1059
1039 // Statistics ------------------------------------------------------------------ 1060 // Statistics ------------------------------------------------------------------
1040 1061
1041 HistoryCountResult HistoryBackend::GetHistoryCount(const Time& begin_time, 1062 HistoryCountResult HistoryBackend::GetHistoryCount(const Time& begin_time,
1042 const Time& end_time) { 1063 const Time& end_time) {
1043 HistoryCountResult result; 1064 HistoryCountResult result;
1044 result.count = 0; 1065 result.count = 0;
1045 result.success = 1066 result.success =
1046 db_ && db_->GetHistoryCount(begin_time, end_time, &result.count); 1067 db_ && db_->GetHistoryCount(begin_time, end_time, &result.count);
1047 return result; 1068 return result;
1048 } 1069 }
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2639 // transaction is currently open. 2660 // transaction is currently open.
2640 db_->CommitTransaction(); 2661 db_->CommitTransaction();
2641 db_->Vacuum(); 2662 db_->Vacuum();
2642 db_->BeginTransaction(); 2663 db_->BeginTransaction();
2643 db_->GetStartDate(&first_recorded_time_); 2664 db_->GetStartDate(&first_recorded_time_);
2644 2665
2645 return true; 2666 return true;
2646 } 2667 }
2647 2668
2648 } // namespace history 2669 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698