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 // The history system runs on a background thread so that potentially slow | 5 // The history system runs on a background thread so that potentially slow |
6 // database operations don't delay the browser. This backend processing is | 6 // database operations don't delay the browser. This backend processing is |
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to | 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to |
8 // that thread. | 8 // that thread. |
9 // | 9 // |
10 // Main thread History thread | 10 // Main thread History thread |
11 // ----------- -------------- | 11 // ----------- -------------- |
12 // HistoryService <----------------> HistoryBackend | 12 // HistoryService <----------------> HistoryBackend |
13 // -> HistoryDatabase | 13 // -> HistoryDatabase |
14 // -> SQLite connection to History | 14 // -> SQLite connection to History |
15 // -> ArchivedDatabase | 15 // -> ArchivedDatabase |
16 // -> SQLite connection to Archived History | 16 // -> SQLite connection to Archived History |
17 // -> TextDatabaseManager | 17 // -> TextDatabaseManager |
18 // -> SQLite connection to one month's data | 18 // -> SQLite connection to one month's data |
19 // -> SQLite connection to one month's data | 19 // -> SQLite connection to one month's data |
20 // ... | 20 // ... |
21 // -> ThumbnailDatabase | 21 // -> ThumbnailDatabase |
22 // -> SQLite connection to Thumbnails | 22 // -> SQLite connection to Thumbnails |
23 // (and favicons) | 23 // (and favicons) |
24 | 24 |
25 #include "chrome/browser/history/history.h" | 25 #include "chrome/browser/history/history.h" |
26 | 26 |
27 #include "base/bind_helpers.h" | |
27 #include "base/callback.h" | 28 #include "base/callback.h" |
28 #include "base/command_line.h" | 29 #include "base/command_line.h" |
29 #include "base/compiler_specific.h" | 30 #include "base/compiler_specific.h" |
31 #include "base/json/json_writer.h" | |
30 #include "base/location.h" | 32 #include "base/location.h" |
31 #include "base/memory/ref_counted.h" | 33 #include "base/memory/ref_counted.h" |
32 #include "base/message_loop.h" | 34 #include "base/message_loop.h" |
33 #include "base/path_service.h" | 35 #include "base/path_service.h" |
34 #include "base/sequenced_task_runner.h" | 36 #include "base/sequenced_task_runner.h" |
35 #include "base/string_util.h" | 37 #include "base/string_util.h" |
36 #include "base/thread_task_runner_handle.h" | 38 #include "base/thread_task_runner_handle.h" |
37 #include "base/threading/thread.h" | 39 #include "base/threading/thread.h" |
38 #include "chrome/browser/autocomplete/history_url_provider.h" | 40 #include "chrome/browser/autocomplete/history_url_provider.h" |
39 #include "chrome/browser/bookmarks/bookmark_model.h" | 41 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
60 #include "chrome/common/pref_names.h" | 62 #include "chrome/common/pref_names.h" |
61 #include "chrome/common/thumbnail_score.h" | 63 #include "chrome/common/thumbnail_score.h" |
62 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
63 #include "content/public/browser/browser_thread.h" | 65 #include "content/public/browser/browser_thread.h" |
64 #include "content/public/browser/notification_service.h" | 66 #include "content/public/browser/notification_service.h" |
65 #include "grit/chromium_strings.h" | 67 #include "grit/chromium_strings.h" |
66 #include "grit/generated_resources.h" | 68 #include "grit/generated_resources.h" |
67 #include "sync/api/sync_change.h" | 69 #include "sync/api/sync_change.h" |
68 #include "sync/api/sync_data.h" | 70 #include "sync/api/sync_data.h" |
69 #include "sync/api/sync_error_factory.h" | 71 #include "sync/api/sync_error_factory.h" |
72 #include "sync/protocol/history_delete_directive_specifics.pb.h" | |
73 #include "sync/protocol/proto_value_conversions.h" | |
70 #include "sync/protocol/sync.pb.h" | 74 #include "sync/protocol/sync.pb.h" |
71 #include "third_party/skia/include/core/SkBitmap.h" | 75 #include "third_party/skia/include/core/SkBitmap.h" |
72 | 76 |
73 using base::Time; | 77 using base::Time; |
74 using history::HistoryBackend; | 78 using history::HistoryBackend; |
75 | 79 |
76 namespace { | 80 namespace { |
77 | 81 |
78 static const char* kHistoryThreadName = "Chrome_HistoryThread"; | 82 static const char* kHistoryThreadName = "Chrome_HistoryThread"; |
79 | 83 |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 return false; | 897 return false; |
894 | 898 |
895 return true; | 899 return true; |
896 } | 900 } |
897 | 901 |
898 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { | 902 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { |
899 DCHECK(thread_checker_.CalledOnValidThread()); | 903 DCHECK(thread_checker_.CalledOnValidThread()); |
900 return weak_ptr_factory_.GetWeakPtr(); | 904 return weak_ptr_factory_.GetWeakPtr(); |
901 } | 905 } |
902 | 906 |
907 void HistoryService::ProcessDeleteDirectiveForTest( | |
908 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | |
909 DCHECK(thread_checker_.CalledOnValidThread()); | |
910 ProcessDeleteDirective(delete_directive); | |
911 } | |
912 | |
903 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( | 913 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( |
904 syncer::ModelType type, | 914 syncer::ModelType type, |
905 const syncer::SyncDataList& initial_sync_data, | 915 const syncer::SyncDataList& initial_sync_data, |
906 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 916 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
907 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 917 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
908 DCHECK(thread_checker_.CalledOnValidThread()); | 918 DCHECK(thread_checker_.CalledOnValidThread()); |
909 DCHECK_EQ(type, syncer::HISTORY_DELETE_DIRECTIVES); | 919 DCHECK_EQ(type, syncer::HISTORY_DELETE_DIRECTIVES); |
910 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); | 920 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); |
911 it != initial_sync_data.end(); ++it) { | 921 it != initial_sync_data.end(); ++it) { |
912 DCHECK_EQ(it->GetDataType(), syncer::HISTORY_DELETE_DIRECTIVES); | 922 DCHECK_EQ(it->GetDataType(), syncer::HISTORY_DELETE_DIRECTIVES); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 visit_database_observers_.RemoveObserver(observer); | 1127 visit_database_observers_.RemoveObserver(observer); |
1118 } | 1128 } |
1119 | 1129 |
1120 void HistoryService::NotifyVisitDBObserversOnAddVisit( | 1130 void HistoryService::NotifyVisitDBObserversOnAddVisit( |
1121 const history::BriefVisitInfo& info) { | 1131 const history::BriefVisitInfo& info) { |
1122 DCHECK(thread_checker_.CalledOnValidThread()); | 1132 DCHECK(thread_checker_.CalledOnValidThread()); |
1123 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, | 1133 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, |
1124 OnAddVisit(info)); | 1134 OnAddVisit(info)); |
1125 } | 1135 } |
1126 | 1136 |
1137 namespace { | |
brettw
2012/11/29 21:29:56
Please put all anon. namespace stuff at the top.
akalin
2012/11/29 23:44:58
Done.
| |
1138 | |
1139 std::string DeleteDirectiveToString( | |
1140 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | |
1141 scoped_ptr<base::DictionaryValue> value( | |
1142 syncer::HistoryDeleteDirectiveSpecificsToValue(delete_directive)); | |
1143 std::string str; | |
1144 base::JSONWriter::Write(value.get(), &str); | |
1145 return str; | |
1146 } | |
1147 | |
1148 } // namespace | |
1149 | |
1127 void HistoryService::ProcessDeleteDirective( | 1150 void HistoryService::ProcessDeleteDirective( |
1128 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | 1151 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { |
1129 DCHECK(thread_checker_.CalledOnValidThread()); | 1152 DCHECK(thread_checker_.CalledOnValidThread()); |
1130 // TODO(akalin): Actually process the delete directive. | 1153 |
1154 VLOG(1) << "Processing delete directive: " | |
1155 << DeleteDirectiveToString(delete_directive); | |
1156 | |
1157 base::Closure done_callback = | |
1158 base::Bind(&HistoryService::OnDeleteDirectiveProcessed, | |
1159 weak_ptr_factory_.GetWeakPtr(), | |
1160 delete_directive); | |
1161 | |
1162 // Execute |done_callback| on return unless we pass it to something | |
1163 // else. | |
1164 base::ScopedClosureRunner scoped_done_callback(done_callback); | |
1165 | |
1166 // Exactly one directive must be filled in. If not, ignore. | |
1167 if (delete_directive.has_global_id_directive() == | |
1168 delete_directive.has_time_range_directive()) { | |
1169 return; | |
1170 } | |
1171 | |
1172 base::Closure backend_task; | |
1173 | |
1174 if (delete_directive.has_global_id_directive()) { | |
1175 const sync_pb::GlobalIdDirective& global_id_directive = | |
1176 delete_directive.global_id_directive(); | |
1177 std::set<base::Time> times; | |
1178 for (int i = 0; i < global_id_directive.global_id_size(); ++i) { | |
1179 int64 global_id = global_id_directive.global_id(i); | |
1180 // The global id is just an internal time value. | |
1181 base::Time time = base::Time::FromInternalValue(global_id); | |
1182 times.insert(time); | |
1183 } | |
1184 | |
1185 if (!times.empty()) { | |
1186 backend_task = | |
1187 base::Bind(&HistoryBackend::ExpireHistoryForTimes, | |
1188 history_backend_, times); | |
1189 } | |
1190 } else if (delete_directive.has_time_range_directive()) { | |
1191 const sync_pb::TimeRangeDirective& time_range_directive = | |
1192 delete_directive.time_range_directive(); | |
1193 // {start,end}_time_usec must both be filled in. If not, ignore. | |
1194 if (!time_range_directive.has_start_time_usec() || | |
1195 !time_range_directive.has_end_time_usec()) { | |
1196 return; | |
1197 } | |
1198 | |
1199 // The directive is for the closed interval [start_time_usec, | |
1200 // end_time_usec], but ExpireHistoryBetween() expects the | |
1201 // half-open interval [begin_time, end_time), so add 1 to | |
1202 // end_time_usec before converting. | |
1203 base::Time begin_time = | |
1204 base::Time::UnixEpoch() + | |
1205 base::TimeDelta::FromMicroseconds( | |
1206 time_range_directive.start_time_usec()); | |
1207 base::Time end_time = | |
1208 base::Time::UnixEpoch() + | |
1209 base::TimeDelta::FromMicroseconds( | |
1210 time_range_directive.end_time_usec() + 1); | |
1211 | |
1212 backend_task = | |
1213 base::Bind(&HistoryBackend::ExpireHistoryBetween, | |
1214 history_backend_, std::set<GURL>(), | |
1215 begin_time, end_time); | |
1216 } | |
1217 | |
1218 if (!backend_task.is_null()) { | |
1219 LoadBackendIfNecessary(); | |
1220 DCHECK(thread_); | |
1221 if (thread_->message_loop_proxy()->PostTaskAndReply( | |
1222 FROM_HERE, | |
1223 backend_task, | |
1224 done_callback)) { | |
1225 ignore_result(scoped_done_callback.Release()); | |
1226 } | |
1227 } | |
1228 } | |
1229 | |
1230 void HistoryService::OnDeleteDirectiveProcessed( | |
1231 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | |
1232 VLOG(1) << "Processed delete directive: " | |
1233 << DeleteDirectiveToString(delete_directive); | |
1131 // TODO(akalin): Keep track of which delete directives we've already | 1234 // TODO(akalin): Keep track of which delete directives we've already |
1132 // processed. | 1235 // processed. |
1133 NOTREACHED(); | |
1134 } | 1236 } |
OLD | NEW |