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

Side by Side Diff: chrome/browser/history/history_service.cc

Issue 164703002: Don't leak WebHistoryService::Request on HistoryService shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/history_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 11 matching lines...) Expand all
22 22
23 #include "base/bind_helpers.h" 23 #include "base/bind_helpers.h"
24 #include "base/callback.h" 24 #include "base/callback.h"
25 #include "base/command_line.h" 25 #include "base/command_line.h"
26 #include "base/compiler_specific.h" 26 #include "base/compiler_specific.h"
27 #include "base/location.h" 27 #include "base/location.h"
28 #include "base/memory/ref_counted.h" 28 #include "base/memory/ref_counted.h"
29 #include "base/message_loop/message_loop.h" 29 #include "base/message_loop/message_loop.h"
30 #include "base/path_service.h" 30 #include "base/path_service.h"
31 #include "base/prefs/pref_service.h" 31 #include "base/prefs/pref_service.h"
32 #include "base/stl_util.h"
32 #include "base/thread_task_runner_handle.h" 33 #include "base/thread_task_runner_handle.h"
33 #include "base/threading/thread.h" 34 #include "base/threading/thread.h"
34 #include "base/time/time.h" 35 #include "base/time/time.h"
35 #include "chrome/browser/autocomplete/history_url_provider.h" 36 #include "chrome/browser/autocomplete/history_url_provider.h"
36 #include "chrome/browser/bookmarks/bookmark_model.h" 37 #include "chrome/browser/bookmarks/bookmark_model.h"
37 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 38 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
38 #include "chrome/browser/browser_process.h" 39 #include "chrome/browser/browser_process.h"
39 #include "chrome/browser/chrome_notification_types.h" 40 #include "chrome/browser/chrome_notification_types.h"
40 #include "chrome/browser/history/download_row.h" 41 #include "chrome/browser/history/download_row.h"
41 #include "chrome/browser/history/history_backend.h" 42 #include "chrome/browser/history/history_backend.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return itr_ != end_; 108 return itr_ != end_;
108 } 109 }
109 110
110 private: 111 private:
111 history::URLRows::const_iterator itr_; 112 history::URLRows::const_iterator itr_;
112 history::URLRows::const_iterator end_; 113 history::URLRows::const_iterator end_;
113 114
114 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows); 115 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows);
115 }; 116 };
116 117
117 // Callback from WebHistoryService::ExpireWebHistory().
118 void ExpireWebHistoryComplete(
119 history::WebHistoryService::Request* request,
120 bool success) {
121 // Ignore the result and delete the request.
122 delete request;
123 }
124
125 } // namespace 118 } // namespace
126 119
127 // Sends messages from the backend to us on the main thread. This must be a 120 // Sends messages from the backend to us on the main thread. This must be a
128 // separate class from the history service so that it can hold a reference to 121 // separate class from the history service so that it can hold a reference to
129 // the history service (otherwise we would have to manually AddRef and 122 // the history service (otherwise we would have to manually AddRef and
130 // Release when the Backend has a reference to us). 123 // Release when the Backend has a reference to us).
131 class HistoryService::BackendDelegate : public HistoryBackend::Delegate { 124 class HistoryService::BackendDelegate : public HistoryBackend::Delegate {
132 public: 125 public:
133 BackendDelegate( 126 BackendDelegate(
134 const base::WeakPtr<HistoryService>& history_service, 127 const base::WeakPtr<HistoryService>& history_service,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); 279 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr);
287 } 280 }
288 281
289 void HistoryService::Cleanup() { 282 void HistoryService::Cleanup() {
290 DCHECK(thread_checker_.CalledOnValidThread()); 283 DCHECK(thread_checker_.CalledOnValidThread());
291 if (!thread_) { 284 if (!thread_) {
292 // We've already cleaned up. 285 // We've already cleaned up.
293 return; 286 return;
294 } 287 }
295 288
289 // Cancel all pending WebHistoryService requests.
290 STLDeleteElements(&pending_web_history_service_requests_);
291
296 weak_ptr_factory_.InvalidateWeakPtrs(); 292 weak_ptr_factory_.InvalidateWeakPtrs();
297 293
298 // Unload the backend. 294 // Unload the backend.
299 UnloadBackend(); 295 UnloadBackend();
300 296
301 // Delete the thread, which joins with the background thread. We defensively 297 // Delete the thread, which joins with the background thread. We defensively
302 // NULL the pointer before deleting it in case somebody tries to use it 298 // NULL the pointer before deleting it in case somebody tries to use it
303 // during shutdown, but this shouldn't happen. 299 // during shutdown, but this shouldn't happen.
304 base::Thread* thread = thread_; 300 base::Thread* thread = thread_;
305 thread_ = NULL; 301 thread_ = NULL;
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 988
993 void HistoryService::ScheduleTask(SchedulePriority priority, 989 void HistoryService::ScheduleTask(SchedulePriority priority,
994 const base::Closure& task) { 990 const base::Closure& task) {
995 DCHECK(thread_checker_.CalledOnValidThread()); 991 DCHECK(thread_checker_.CalledOnValidThread());
996 CHECK(thread_); 992 CHECK(thread_);
997 CHECK(thread_->message_loop()); 993 CHECK(thread_->message_loop());
998 // TODO(brettw): Do prioritization. 994 // TODO(brettw): Do prioritization.
999 thread_->message_loop()->PostTask(FROM_HERE, task); 995 thread_->message_loop()->PostTask(FROM_HERE, task);
1000 } 996 }
1001 997
998 // Callback from WebHistoryService::ExpireWebHistory().
999 void HistoryService::WebHistoryServiceRequestComplete(
1000 history::WebHistoryService::Request* request,
1001 bool success) {
1002 // Ignore the result and delete the request.
1003 pending_web_history_service_requests_.erase(request);
1004 delete request;
1005 }
1006
1002 // static 1007 // static
1003 bool HistoryService::CanAddURL(const GURL& url) { 1008 bool HistoryService::CanAddURL(const GURL& url) {
1004 if (!url.is_valid()) 1009 if (!url.is_valid())
1005 return false; 1010 return false;
1006 1011
1007 // TODO: We should allow kChromeUIScheme URLs if they have been explicitly 1012 // TODO: We should allow kChromeUIScheme URLs if they have been explicitly
1008 // typed. Right now, however, these are marked as typed even when triggered 1013 // typed. Right now, however, these are marked as typed even when triggered
1009 // by a shortcut or menu action. 1014 // by a shortcut or menu action.
1010 if (url.SchemeIs(content::kJavaScriptScheme) || 1015 if (url.SchemeIs(content::kJavaScriptScheme) ||
1011 url.SchemeIs(chrome::kChromeDevToolsScheme) || 1016 url.SchemeIs(chrome::kChromeDevToolsScheme) ||
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 if (web_history) { 1162 if (web_history) {
1158 // TODO(dubroy): This API does not yet support deletion of specific URLs. 1163 // TODO(dubroy): This API does not yet support deletion of specific URLs.
1159 DCHECK(restrict_urls.empty()); 1164 DCHECK(restrict_urls.empty());
1160 1165
1161 delete_directive_handler_.CreateDeleteDirectives( 1166 delete_directive_handler_.CreateDeleteDirectives(
1162 std::set<int64>(), begin_time, end_time); 1167 std::set<int64>(), begin_time, end_time);
1163 1168
1164 // Attempt online deletion from the history server, but ignore the result. 1169 // Attempt online deletion from the history server, but ignore the result.
1165 // Deletion directives ensure that the results will eventually be deleted. 1170 // Deletion directives ensure that the results will eventually be deleted.
1166 // Pass ownership of the request to the callback. 1171 // Pass ownership of the request to the callback.
1167 scoped_ptr<history::WebHistoryService::Request> request = 1172 scoped_ptr<history::WebHistoryService::Request> request =
sky 2014/02/19 17:33:21 This seems like a hack to me. Expiring history doe
1168 web_history->ExpireHistoryBetween( 1173 web_history->ExpireHistoryBetween(
1169 restrict_urls, begin_time, end_time, 1174 restrict_urls, begin_time, end_time,
1170 base::Bind(&ExpireWebHistoryComplete)); 1175 base::Bind(&HistoryService::WebHistoryServiceRequestComplete,
1176 weak_ptr_factory_.GetWeakPtr()));
1171 1177
1172 // The request will be freed when the callback is called. 1178 // The request will be freed when the callback is called, or on
1173 CHECK(request.release()); 1179 // HistoryService shutdown.
1180 pending_web_history_service_requests_.insert(request.release());
1174 } 1181 }
1175 ExpireHistoryBetween(restrict_urls, begin_time, end_time, callback, tracker); 1182 ExpireHistoryBetween(restrict_urls, begin_time, end_time, callback, tracker);
1176 } 1183 }
1177 1184
1178 void HistoryService::BroadcastNotificationsHelper( 1185 void HistoryService::BroadcastNotificationsHelper(
1179 int type, 1186 int type,
1180 history::HistoryDetails* details) { 1187 history::HistoryDetails* details) {
1181 DCHECK(thread_checker_.CalledOnValidThread()); 1188 DCHECK(thread_checker_.CalledOnValidThread());
1182 // TODO(evanm): this is currently necessitated by generate_profile, which 1189 // TODO(evanm): this is currently necessitated by generate_profile, which
1183 // runs without a browser process. generate_profile should really create 1190 // runs without a browser process. generate_profile should really create
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 DCHECK(thread_checker_.CalledOnValidThread()); 1262 DCHECK(thread_checker_.CalledOnValidThread());
1256 visit_database_observers_.RemoveObserver(observer); 1263 visit_database_observers_.RemoveObserver(observer);
1257 } 1264 }
1258 1265
1259 void HistoryService::NotifyVisitDBObserversOnAddVisit( 1266 void HistoryService::NotifyVisitDBObserversOnAddVisit(
1260 const history::BriefVisitInfo& info) { 1267 const history::BriefVisitInfo& info) {
1261 DCHECK(thread_checker_.CalledOnValidThread()); 1268 DCHECK(thread_checker_.CalledOnValidThread());
1262 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, 1269 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_,
1263 OnAddVisit(info)); 1270 OnAddVisit(info));
1264 } 1271 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698