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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 7313003: Separate memory purger from safe browsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/safe_browsing_service.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index e4564bfec7d8d2d960eb120e4231d4580d088aa0..31b251297cc3c16ac0f8f5509a3ffd7ef69ead74 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -27,6 +27,7 @@
#include "chrome/common/url_constants.h"
#include "content/browser/browser_thread.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "content/common/notification_service.h"
#include "net/base/registry_controlled_domain.h"
#include "net/url_request/url_request_context_getter.h"
@@ -468,37 +469,6 @@ void SafeBrowsingService::RegisterPrefs(PrefService* prefs) {
prefs->RegisterStringPref(prefs::kSafeBrowsingWrappedKey, "");
}
-void SafeBrowsingService::CloseDatabase() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- // Cases to avoid:
- // * If |closing_database_| is true, continuing will queue up a second
- // request, |closing_database_| will be reset after handling the first
- // request, and if any functions on the db thread recreate the database, we
- // could start using it on the IO thread and then have the second request
- // handler delete it out from under us.
- // * If |database_| is NULL, then either no creation request is in flight, in
- // which case we don't need to do anything, or one is in flight, in which
- // case the database will be recreated before our deletion request is
- // handled, and could be used on the IO thread in that time period, leading
- // to the same problem as above.
- // * If |queued_checks_| is non-empty and |database_| is non-NULL, we're
- // about to be called back (in DatabaseLoadComplete()). This will call
- // CheckUrl(), which will want the database. Closing the database here
- // would lead to an infinite loop in DatabaseLoadComplete(), and even if it
- // didn't, it would be pointless since we'd just want to recreate.
- //
- // The first two cases above are handled by checking DatabaseAvailable().
- if (!DatabaseAvailable() || !queued_checks_.empty())
- return;
-
- closing_database_ = true;
- if (safe_browsing_thread_.get()) {
- safe_browsing_thread_->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &SafeBrowsingService::OnCloseDatabase));
- }
-}
-
void SafeBrowsingService::ResetDatabase() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(enabled_);
@@ -523,6 +493,9 @@ void SafeBrowsingService::OnIOInitialize(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
enabled_ = true;
+ registrar_.Add(this, NotificationType::PURGE_MEMORY,
+ NotificationService::AllSources());
+
MakeDatabaseAvailable();
// On Windows, get the safe browsing client name from the browser
@@ -572,6 +545,8 @@ void SafeBrowsingService::OnIOShutdown() {
enabled_ = false;
+ registrar_.RemoveAll();
+
// This cancels all in-flight GetHash requests.
delete protocol_manager_;
protocol_manager_ = NULL;
@@ -642,6 +617,37 @@ bool SafeBrowsingService::MakeDatabaseAvailable() {
return false;
}
+void SafeBrowsingService::CloseDatabase() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ // Cases to avoid:
+ // * If |closing_database_| is true, continuing will queue up a second
+ // request, |closing_database_| will be reset after handling the first
+ // request, and if any functions on the db thread recreate the database, we
+ // could start using it on the IO thread and then have the second request
+ // handler delete it out from under us.
+ // * If |database_| is NULL, then either no creation request is in flight, in
+ // which case we don't need to do anything, or one is in flight, in which
+ // case the database will be recreated before our deletion request is
+ // handled, and could be used on the IO thread in that time period, leading
+ // to the same problem as above.
+ // * If |queued_checks_| is non-empty and |database_| is non-NULL, we're
+ // about to be called back (in DatabaseLoadComplete()). This will call
+ // CheckUrl(), which will want the database. Closing the database here
+ // would lead to an infinite loop in DatabaseLoadComplete(), and even if it
+ // didn't, it would be pointless since we'd just want to recreate.
+ //
+ // The first two cases above are handled by checking DatabaseAvailable().
+ if (!DatabaseAvailable() || !queued_checks_.empty())
+ return;
+
+ closing_database_ = true;
+ if (safe_browsing_thread_.get()) {
+ safe_browsing_thread_->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::OnCloseDatabase));
+ }
+}
+
SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() {
DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
if (database_)
@@ -1202,6 +1208,14 @@ void SafeBrowsingService::UpdateWhitelist(const UnsafeResource& resource) {
white_listed_entries_.push_back(entry);
}
+void SafeBrowsingService::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(type == NotificationType::PURGE_MEMORY);
+ CloseDatabase();
+}
+
bool SafeBrowsingService::IsWhitelisted(const UnsafeResource& resource) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Check if the user has already ignored our warning for this render_view
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698