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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
25 #include "base/location.h" | 25 #include "base/location.h" |
26 #include "base/memory/ref_counted.h" | 26 #include "base/memory/ref_counted.h" |
27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
28 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
29 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
31 #include "chrome/browser/history/history_backend.h" | 31 #include "chrome/browser/history/history_backend.h" |
32 #include "chrome/browser/history/in_memory_history_backend.h" | 32 #include "chrome/browser/history/in_memory_history_backend.h" |
33 #include "chrome/browser/history/in_memory_url_index.h" | 33 #include "chrome/browser/history/in_memory_url_index.h" |
34 #include "chrome/browser/history/web_history_service.h" | |
35 #include "chrome/browser/history/web_history_service_factory.h" | |
36 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/common/importer/imported_favicon_usage.h" | 35 #include "chrome/common/importer/imported_favicon_usage.h" |
38 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
39 #include "components/dom_distiller/core/url_constants.h" | 37 #include "components/dom_distiller/core/url_constants.h" |
40 #include "components/history/core/browser/download_row.h" | 38 #include "components/history/core/browser/download_row.h" |
41 #include "components/history/core/browser/history_client.h" | 39 #include "components/history/core/browser/history_client.h" |
42 #include "components/history/core/browser/history_database_params.h" | 40 #include "components/history/core/browser/history_database_params.h" |
43 #include "components/history/core/browser/history_service_observer.h" | 41 #include "components/history/core/browser/history_service_observer.h" |
44 #include "components/history/core/browser/history_types.h" | 42 #include "components/history/core/browser/history_types.h" |
45 #include "components/history/core/browser/in_memory_database.h" | 43 #include "components/history/core/browser/in_memory_database.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 95 |
98 bool HasNextURL() const override { return itr_ != end_; } | 96 bool HasNextURL() const override { return itr_ != end_; } |
99 | 97 |
100 private: | 98 private: |
101 history::URLRows::const_iterator itr_; | 99 history::URLRows::const_iterator itr_; |
102 history::URLRows::const_iterator end_; | 100 history::URLRows::const_iterator end_; |
103 | 101 |
104 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows); | 102 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows); |
105 }; | 103 }; |
106 | 104 |
107 // Callback from WebHistoryService::ExpireWebHistory(). | |
108 void ExpireWebHistoryComplete(bool success) { | |
109 // Ignore the result. | |
110 // | |
111 // TODO(davidben): ExpireLocalAndRemoteHistoryBetween callback should not fire | |
112 // until this completes. | |
113 } | |
114 | |
115 } // namespace | 105 } // namespace |
116 | 106 |
117 // Sends messages from the backend to us on the main thread. This must be a | 107 // Sends messages from the backend to us on the main thread. This must be a |
118 // separate class from the history service so that it can hold a reference to | 108 // separate class from the history service so that it can hold a reference to |
119 // the history service (otherwise we would have to manually AddRef and | 109 // the history service (otherwise we would have to manually AddRef and |
120 // Release when the Backend has a reference to us). | 110 // Release when the Backend has a reference to us). |
121 class HistoryService::BackendDelegate : public HistoryBackend::Delegate { | 111 class HistoryService::BackendDelegate : public HistoryBackend::Delegate { |
122 public: | 112 public: |
123 BackendDelegate( | 113 BackendDelegate( |
124 const base::WeakPtr<HistoryService>& history_service, | 114 const base::WeakPtr<HistoryService>& history_service, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 const base::WeakPtr<HistoryService> history_service_; | 200 const base::WeakPtr<HistoryService> history_service_; |
211 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 201 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
212 }; | 202 }; |
213 | 203 |
214 // The history thread is intentionally not a BrowserThread because the | 204 // The history thread is intentionally not a BrowserThread because the |
215 // sync integration unit tests depend on being able to create more than one | 205 // sync integration unit tests depend on being able to create more than one |
216 // history thread. | 206 // history thread. |
217 HistoryService::HistoryService() | 207 HistoryService::HistoryService() |
218 : thread_(new base::Thread(kHistoryThreadName)), | 208 : thread_(new base::Thread(kHistoryThreadName)), |
219 history_client_(NULL), | 209 history_client_(NULL), |
220 profile_(NULL), | |
221 backend_loaded_(false), | 210 backend_loaded_(false), |
222 no_db_(false), | 211 no_db_(false), |
223 weak_ptr_factory_(this) { | 212 weak_ptr_factory_(this) { |
224 } | 213 } |
225 | 214 |
226 HistoryService::HistoryService( | 215 HistoryService::HistoryService( |
227 history::HistoryClient* history_client, Profile* profile) | 216 history::HistoryClient* history_client, Profile* profile) |
228 : thread_(new base::Thread(kHistoryThreadName)), | 217 : thread_(new base::Thread(kHistoryThreadName)), |
229 history_client_(history_client), | 218 history_client_(history_client), |
230 profile_(profile), | |
231 visitedlink_master_(new visitedlink::VisitedLinkMaster( | 219 visitedlink_master_(new visitedlink::VisitedLinkMaster( |
232 profile, this, true)), | 220 profile, this, true)), |
233 backend_loaded_(false), | 221 backend_loaded_(false), |
234 no_db_(false), | 222 no_db_(false), |
235 weak_ptr_factory_(this) { | 223 weak_ptr_factory_(this) { |
236 } | 224 } |
237 | 225 |
238 HistoryService::~HistoryService() { | 226 HistoryService::~HistoryService() { |
239 DCHECK(thread_checker_.CalledOnValidThread()); | 227 DCHECK(thread_checker_.CalledOnValidThread()); |
240 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 228 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 base::CancelableTaskTracker* tracker) { | 1134 base::CancelableTaskTracker* tracker) { |
1147 DCHECK(thread_) << "History service being called after cleanup"; | 1135 DCHECK(thread_) << "History service being called after cleanup"; |
1148 DCHECK(thread_checker_.CalledOnValidThread()); | 1136 DCHECK(thread_checker_.CalledOnValidThread()); |
1149 tracker->PostTaskAndReply( | 1137 tracker->PostTaskAndReply( |
1150 thread_->message_loop_proxy().get(), | 1138 thread_->message_loop_proxy().get(), |
1151 FROM_HERE, | 1139 FROM_HERE, |
1152 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list), | 1140 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list), |
1153 callback); | 1141 callback); |
1154 } | 1142 } |
1155 | 1143 |
1156 void HistoryService::ExpireLocalAndRemoteHistoryBetween( | |
1157 const std::set<GURL>& restrict_urls, | |
1158 Time begin_time, | |
1159 Time end_time, | |
1160 const base::Closure& callback, | |
1161 base::CancelableTaskTracker* tracker) { | |
1162 // TODO(dubroy): This should be factored out into a separate class that | |
1163 // dispatches deletions to the proper places. | |
1164 | |
1165 history::WebHistoryService* web_history = | |
1166 WebHistoryServiceFactory::GetForProfile(profile_); | |
1167 if (web_history) { | |
1168 // TODO(dubroy): This API does not yet support deletion of specific URLs. | |
1169 DCHECK(restrict_urls.empty()); | |
1170 | |
1171 delete_directive_handler_.CreateDeleteDirectives( | |
1172 std::set<int64>(), begin_time, end_time); | |
1173 | |
1174 // Attempt online deletion from the history server, but ignore the result. | |
1175 // Deletion directives ensure that the results will eventually be deleted. | |
1176 // | |
1177 // TODO(davidben): |callback| should not run until this operation completes | |
1178 // too. | |
1179 web_history->ExpireHistoryBetween( | |
1180 restrict_urls, begin_time, end_time, | |
1181 base::Bind(&ExpireWebHistoryComplete)); | |
1182 } | |
1183 ExpireHistoryBetween(restrict_urls, begin_time, end_time, callback, tracker); | |
1184 } | |
1185 | |
1186 void HistoryService::OnDBLoaded() { | 1144 void HistoryService::OnDBLoaded() { |
1187 DCHECK(thread_checker_.CalledOnValidThread()); | 1145 DCHECK(thread_checker_.CalledOnValidThread()); |
1188 backend_loaded_ = true; | 1146 backend_loaded_ = true; |
1189 NotifyHistoryServiceLoaded(); | 1147 NotifyHistoryServiceLoaded(); |
1190 } | 1148 } |
1191 | 1149 |
1192 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { | 1150 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { |
1193 DCHECK(thread_checker_.CalledOnValidThread()); | 1151 DCHECK(thread_checker_.CalledOnValidThread()); |
1194 history::URLDatabase* db = InMemoryDatabase(); | 1152 history::URLDatabase* db = InMemoryDatabase(); |
1195 return db && (db->GetRowForURL(url, url_row) != 0); | 1153 return db && (db->GetRowForURL(url, url_row) != 0); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 const HistoryService::OnFaviconChangedCallback& callback) { | 1239 const HistoryService::OnFaviconChangedCallback& callback) { |
1282 DCHECK(thread_checker_.CalledOnValidThread()); | 1240 DCHECK(thread_checker_.CalledOnValidThread()); |
1283 return favicon_changed_callback_list_.Add(callback); | 1241 return favicon_changed_callback_list_.Add(callback); |
1284 } | 1242 } |
1285 | 1243 |
1286 void HistoryService::NotifyFaviconChanged( | 1244 void HistoryService::NotifyFaviconChanged( |
1287 const std::set<GURL>& changed_favicons) { | 1245 const std::set<GURL>& changed_favicons) { |
1288 DCHECK(thread_checker_.CalledOnValidThread()); | 1246 DCHECK(thread_checker_.CalledOnValidThread()); |
1289 favicon_changed_callback_list_.Notify(changed_favicons); | 1247 favicon_changed_callback_list_.Notify(changed_favicons); |
1290 } | 1248 } |
OLD | NEW |