summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_theme_provider.cc
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/browser/browser_theme_provider.cc
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/browser/browser_theme_provider.cc')
-rw-r--r--chrome/browser/browser_theme_provider.cc24
1 files changed, 23 insertions, 1 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) {