summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-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
3 files changed, 27 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) {
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();
}