summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 22:14:46 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 22:14:46 +0000
commit520cdd71da6f80dfffdd384645792de9a61abc94 (patch)
tree9c299ddab2d1bc22f0cceb9a361cd5b00952d08a
parentc4a9b44a974e39f23100e9ef1e122648b84470e3 (diff)
downloadchromium_src-520cdd71da6f80dfffdd384645792de9a61abc94.zip
chromium_src-520cdd71da6f80dfffdd384645792de9a61abc94.tar.gz
chromium_src-520cdd71da6f80dfffdd384645792de9a61abc94.tar.bz2
Introduce a notification to trigger memory purging on the IO thread and use it in ChromeAppCacheService.
TEST=manual BUG=none Review URL: http://codereview.chromium.org/547016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36181 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/memory_purger.cc7
-rw-r--r--chrome/common/appcache/chrome_appcache_service.cc11
-rw-r--r--chrome/common/appcache/chrome_appcache_service.h11
-rw-r--r--chrome/common/notification_type.h6
-rw-r--r--webkit/appcache/appcache_service.h5
5 files changed, 39 insertions, 1 deletions
diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc
index d230e45..fa85c66 100644
--- a/chrome/browser/memory_purger.cc
+++ b/chrome/browser/memory_purger.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
#include "net/proxy/proxy_resolver.h"
#include "net/url_request/url_request_context.h"
@@ -67,6 +68,12 @@ void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() {
// Close the Safe Browsing database, freeing memory used to cache sqlite as
// well as a number of in-memory structures.
safe_browsing_service_->CloseDatabase();
+
+ // The appcache service listens for this notification.
+ NotificationService::current()->Notify(
+ NotificationType::PURGE_MEMORY,
+ Source<void>(NULL),
+ NotificationService::NoDetails());
}
// -----------------------------------------------------------------------------
diff --git a/chrome/common/appcache/chrome_appcache_service.cc b/chrome/common/appcache/chrome_appcache_service.cc
index c1016cb..cb1f7a3 100644
--- a/chrome/common/appcache/chrome_appcache_service.cc
+++ b/chrome/common/appcache/chrome_appcache_service.cc
@@ -7,6 +7,7 @@
#include "base/file_path.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/notification_service.h"
#include "webkit/appcache/appcache_thread.h"
static bool has_initialized_thread_ids;
@@ -20,12 +21,22 @@ ChromeAppCacheService::ChromeAppCacheService(const FilePath& data_directory,
}
Initialize(is_incognito ? FilePath()
: data_directory.Append(chrome::kAppCacheDirname));
+
+ registrar_.Add(
+ this, NotificationType::PURGE_MEMORY, NotificationService::AllSources());
}
ChromeAppCacheService::~ChromeAppCacheService() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
}
+void ChromeAppCacheService::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::PURGE_MEMORY);
+ PurgeMemory();
+}
+
static ChromeThread::ID ToChromeThreadID(int id) {
DCHECK(has_initialized_thread_ids);
DCHECK(id == ChromeThread::DB || id == ChromeThread::IO);
diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h
index 509afd2..a202601 100644
--- a/chrome/common/appcache/chrome_appcache_service.h
+++ b/chrome/common/appcache/chrome_appcache_service.h
@@ -6,6 +6,7 @@
#define CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
#include "base/ref_counted.h"
+#include "chrome/common/notification_registrar.h"
#include "webkit/appcache/appcache_service.h"
class FilePath;
@@ -20,13 +21,21 @@ class FilePath;
// the IO thread.
class ChromeAppCacheService
: public base::RefCounted<ChromeAppCacheService>,
- public appcache::AppCacheService {
+ public appcache::AppCacheService,
+ public NotificationObserver {
public:
ChromeAppCacheService(const FilePath& data_directory,
bool is_incognito);
private:
friend class base::RefCounted<ChromeAppCacheService>;
virtual ~ChromeAppCacheService();
+
+ // NotificationObserver override
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ NotificationRegistrar registrar_;
};
#endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index d88b97e..d021059 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -794,6 +794,12 @@ class NotificationType {
// key of the entry that was affected.
AUTOFILL_ENTRIES_CHANGED,
+ // Purge Memory ------------------------------------------------------------
+
+ // Sent on the IO thread when the system should try to reduce the amount of
+ // memory in use, no source or details are passed. See memory_purger.h .cc.
+ PURGE_MEMORY,
+
// Count (must be last) ----------------------------------------------------
// Used to determine the number of notification types. Not valid as
// a type parameter when registering for or posting notifications.
diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h
index 05e9329..986e620 100644
--- a/webkit/appcache/appcache_service.h
+++ b/webkit/appcache/appcache_service.h
@@ -26,6 +26,11 @@ class AppCacheService {
void Initialize(const FilePath& cache_directory);
+ void PurgeMemory() {
+ if (storage_.get())
+ storage_->PurgeMemory();
+ }
+
// Context for use during cache updates, should only be accessed
// on the IO thread. We do NOT add a reference to the request context,
// it is the callers responsibility to ensure that the pointer