Chromium Code Reviews| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 visit_database_observers_.RemoveObserver(observer); | 1126 visit_database_observers_.RemoveObserver(observer); |
| 1117 } | 1127 } |
| 1118 | 1128 |
| 1119 void HistoryService::NotifyVisitDBObserversOnAddVisit( | 1129 void HistoryService::NotifyVisitDBObserversOnAddVisit( |
| 1120 const history::BriefVisitInfo& info) { | 1130 const history::BriefVisitInfo& info) { |
| 1121 DCHECK(thread_checker_.CalledOnValidThread()); | 1131 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1122 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, | 1132 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, |
| 1123 OnAddVisit(info)); | 1133 OnAddVisit(info)); |
| 1124 } | 1134 } |
| 1125 | 1135 |
| 1136 namespace { | |
| 1137 | |
| 1138 std::string DeleteDirectiveToString( | |
| 1139 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | |
| 1140 scoped_ptr<base::DictionaryValue> value( | |
| 1141 syncer::HistoryDeleteDirectiveSpecificsToValue(delete_directive)); | |
| 1142 std::string str; | |
| 1143 base::JSONWriter::Write(value.get(), &str); | |
| 1144 return str; | |
| 1145 } | |
| 1146 | |
| 1147 } // namespace | |
| 1148 | |
| 1126 void HistoryService::ProcessDeleteDirective( | 1149 void HistoryService::ProcessDeleteDirective( |
| 1127 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | 1150 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { |
| 1128 DCHECK(thread_checker_.CalledOnValidThread()); | 1151 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1129 // TODO(akalin): Actually process the delete directive. | 1152 |
| 1153 VLOG(1) << "Processing delete directive: " | |
|
Nicolas Zea
2012/11/29 22:29:43
dvlog? (here and below)
akalin
2012/11/29 23:44:58
Done. Also fixed existing cases above.
| |
| 1154 << DeleteDirectiveToString(delete_directive); | |
| 1155 | |
| 1156 base::Closure done_callback = | |
| 1157 base::Bind(&HistoryService::OnDeleteDirectiveProcessed, | |
| 1158 weak_ptr_factory_.GetWeakPtr(), | |
| 1159 delete_directive); | |
| 1160 | |
| 1161 // Execute |done_callback| on return unless we pass it to something | |
| 1162 // else. | |
| 1163 base::ScopedClosureRunner scoped_done_callback(done_callback); | |
| 1164 | |
| 1165 // Exactly one directive must be filled in. If not, ignore. | |
| 1166 if (delete_directive.has_global_id_directive() == | |
| 1167 delete_directive.has_time_range_directive()) { | |
| 1168 return; | |
| 1169 } | |
| 1170 | |
| 1171 base::Closure backend_task; | |
| 1172 | |
| 1173 if (delete_directive.has_global_id_directive()) { | |
| 1174 const sync_pb::GlobalIdDirective& global_id_directive = | |
| 1175 delete_directive.global_id_directive(); | |
| 1176 std::vector<base::Time> times; | |
| 1177 for (int i = 0; i < global_id_directive.global_id_size(); ++i) { | |
| 1178 int64 global_id = global_id_directive.global_id(i); | |
| 1179 // The global id is just an internal time value. | |
| 1180 base::Time time = base::Time::FromInternalValue(global_id); | |
| 1181 times.push_back(time); | |
| 1182 } | |
| 1183 | |
| 1184 if (!times.empty()) { | |
| 1185 backend_task = | |
| 1186 base::Bind(&HistoryBackend::ExpireHistoryForTimes, | |
| 1187 history_backend_, times); | |
| 1188 } | |
| 1189 } else if (delete_directive.has_time_range_directive()) { | |
| 1190 const sync_pb::TimeRangeDirective& time_range_directive = | |
| 1191 delete_directive.time_range_directive(); | |
| 1192 // {start,end}_time_usec must both be filled in. If not, ignore. | |
| 1193 if (!time_range_directive.has_start_time_usec() || | |
| 1194 !time_range_directive.has_end_time_usec()) { | |
| 1195 return; | |
| 1196 } | |
| 1197 | |
| 1198 // The directive is for the closed interval [start_time_usec, | |
| 1199 // end_time_usec], but ExpireHistoryBetween() expects the | |
| 1200 // half-open interval [begin_time, end_time), so add 1 to | |
| 1201 // end_time_usec before converting. | |
| 1202 base::Time begin_time = | |
| 1203 base::Time::UnixEpoch() + | |
| 1204 base::TimeDelta::FromMicroseconds( | |
| 1205 time_range_directive.start_time_usec()); | |
| 1206 base::Time end_time = | |
| 1207 base::Time::UnixEpoch() + | |
| 1208 base::TimeDelta::FromMicroseconds( | |
| 1209 time_range_directive.end_time_usec() + 1); | |
| 1210 | |
| 1211 backend_task = | |
| 1212 base::Bind(&HistoryBackend::ExpireHistoryBetween, | |
| 1213 history_backend_, std::set<GURL>(), | |
| 1214 begin_time, end_time); | |
| 1215 } | |
| 1216 | |
| 1217 if (!backend_task.is_null()) { | |
| 1218 LoadBackendIfNecessary(); | |
| 1219 DCHECK(thread_); | |
| 1220 if (thread_->message_loop_proxy()->PostTaskAndReply( | |
| 1221 FROM_HERE, | |
| 1222 backend_task, | |
| 1223 done_callback)) { | |
| 1224 ignore_result(scoped_done_callback.Release()); | |
| 1225 } | |
| 1226 } | |
| 1227 } | |
| 1228 | |
| 1229 void HistoryService::OnDeleteDirectiveProcessed( | |
| 1230 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { | |
| 1231 VLOG(1) << "Processed delete directive: " | |
| 1232 << DeleteDirectiveToString(delete_directive); | |
| 1130 // TODO(akalin): Keep track of which delete directives we've already | 1233 // TODO(akalin): Keep track of which delete directives we've already |
| 1131 // processed. | 1234 // processed. |
| 1132 NOTREACHED(); | |
| 1133 } | 1235 } |
| OLD | NEW |