summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 22:27:00 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 22:27:00 +0000
commit66da08b94cbf0d93fbaff2233d8c358d61f6c088 (patch)
tree0d75faf3ff49e79df085dbc2609551f2099d1519 /chrome
parentd1cd82b9cc7b41756f917e5aa983566136df9174 (diff)
downloadchromium_src-66da08b94cbf0d93fbaff2233d8c358d61f6c088.zip
chromium_src-66da08b94cbf0d93fbaff2233d8c358d61f6c088.tar.gz
chromium_src-66da08b94cbf0d93fbaff2233d8c358d61f6c088.tar.bz2
Delete unused themes from disk on shutdown.
This reduces the size of the Preferences file and frees up some disk space. The smaller Preferences file should help improve startup time for users who have installed lots of themes. BUG=24377 Review URL: http://codereview.chromium.org/303006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_theme_provider.cc24
-rw-r--r--chrome/browser/browser_theme_provider.h3
-rw-r--r--chrome/browser/profile.cc1
-rw-r--r--chrome/common/extensions/extension.h2
4 files changed, 28 insertions, 2 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index 0adfa6b..eb7aeb4 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/theme_resources_util.h"
@@ -299,6 +300,8 @@ BrowserThemeProvider::BrowserThemeProvider()
BrowserThemeProvider::~BrowserThemeProvider() {
ClearCaches();
+
+ RemoveUnusedThemes();
}
void BrowserThemeProvider::Init(Profile* profile) {
@@ -509,6 +512,25 @@ void BrowserThemeProvider::SetTheme(Extension* extension) {
UserMetrics::RecordAction(L"Themes_Installed", profile_);
}
+void BrowserThemeProvider::RemoveUnusedThemes() {
+ if (!profile_)
+ return;
+ ExtensionsService* service = profile_->GetExtensionsService();
+ if (!service)
+ return;
+ std::string current_theme = GetThemeID();
+ std::vector<std::string> remove_list;
+ const ExtensionList* extensions = service->extensions();
+ for (ExtensionList::const_iterator it = extensions->begin();
+ it != extensions->end(); ++it) {
+ if ((*it)->IsTheme() && (*it)->id() != current_theme) {
+ remove_list.push_back((*it)->id());
+ }
+ }
+ for (size_t i = 0; i < remove_list.size(); ++i)
+ service->UninstallExtension(remove_list[i], false);
+}
+
void BrowserThemeProvider::UseDefaultTheme() {
ClearAllThemeData();
NotifyThemeChanged();
@@ -1281,7 +1303,7 @@ void BrowserThemeProvider::SaveCachedImageData() const {
std::string pref_name = resource_names_.find(it->second)->second;
pref_images->SetString(UTF8ToWide(pref_name), WideToUTF8(disk_path));
}
- profile_->GetPrefs()->SavePersistentPrefs();
+ profile_->GetPrefs()->ScheduleSavePersistentPrefs();
}
void BrowserThemeProvider::SaveThemeID(const std::string& id) {
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h
index f54c3ca..af11285 100644
--- a/chrome/browser/browser_theme_provider.h
+++ b/chrome/browser/browser_theme_provider.h
@@ -336,6 +336,9 @@ class BrowserThemeProvider : public NonThreadSafe,
// Frees generated images and clears the image cache.
void ClearCaches();
+ // Remove preference values for themes that are no longer in use.
+ void RemoveUnusedThemes();
+
// Encode image at image_cache_[id] as PNG and write to disk.
void WriteImagesToDisk() const;
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 2c58382..f4e2ed8 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -811,6 +811,7 @@ ProfileImpl::~ProfileImpl() {
if (extensions_service_)
extensions_service_->ProfileDestroyed();
+ // This causes the Preferences file to be written to disk.
MarkAsCleanShutdown();
}
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index eac617f..14258c9 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -237,7 +237,7 @@ class Extension {
DictionaryValue* GetThemeDisplayProperties() const {
return theme_display_properties_.get();
}
- bool IsTheme() { return is_theme_; }
+ bool IsTheme() const { return is_theme_; }
// Returns a list of paths (relative to the extension dir) for images that
// the browser might load (like themes and page action icons).