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

Unified Diff: chrome/browser/search/instant_service.cc

Issue 16413002: Moved theme related state from BrowserInstantController to InstantService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 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/search/instant_service.h ('k') | chrome/browser/search/instant_service_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/instant_service.cc
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index ccf8c885a79f398e1e5b9fddd4c1820be384928f..33b9ee5697d2fe0c6688853b28ea5910b0630e41 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -14,10 +14,14 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_io_context.h"
#include "chrome/browser/search/instant_service_factory.h"
+#include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/search/local_ntp_source.h"
#include "chrome/browser/search/most_visited_iframe_source.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search/suggestion_iframe_source.h"
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/themes/theme_service.h"
+#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_instant_controller.h"
#include "chrome/browser/ui/browser_list.h"
@@ -33,7 +37,11 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h"
#include "googleurl/src/gurl.h"
+#include "grit/theme_resources.h"
#include "net/url_request/url_request.h"
+#include "ui/gfx/color_utils.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/sys_color_change_listener.h"
using content::BrowserThread;
@@ -65,8 +73,14 @@ InstantService::InstantService(Profile* profile)
// Set up the data sources that Instant uses on the NTP.
#if defined(ENABLE_THEMES)
+ // Listen for theme installation.
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
+ content::Source<ThemeService>(
+ ThemeServiceFactory::GetForProfile(profile_)));
+
content::URLDataSource::Add(profile, new ThemeSource(profile));
-#endif
+#endif // defined(ENABLE_THEMES)
+
content::URLDataSource::Add(profile, new ThumbnailSource(profile));
content::URLDataSource::Add(profile, new FaviconSource(
profile, FaviconSource::FAVICON));
@@ -94,6 +108,14 @@ bool InstantService::IsInstantProcess(int process_id) const {
return process_ids_.find(process_id) != process_ids_.end();
}
+void InstantService::AddObserver(InstantServiceObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void InstantService::RemoveObserver(InstantServiceObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
void InstantService::DeleteMostVisitedItem(const GURL& url) {
history::TopSites* top_sites = profile_->GetTopSites();
if (!top_sites)
@@ -123,6 +145,15 @@ void InstantService::GetCurrentMostVisitedItems(
*items = most_visited_items_;
}
+void InstantService::UpdateThemeInfo() {
+ // Update theme background info.
+ // Initialize |theme_info| if necessary.
+ if (!theme_info_)
+ OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_));
+ else
+ OnThemeChanged(NULL);
+}
+
void InstantService::Shutdown() {
process_ids_.clear();
@@ -164,6 +195,12 @@ void InstantService::Observe(int type,
}
break;
}
+#if defined(ENABLE_THEMES)
+ case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
+ OnThemeChanged(content::Source<ThemeService>(source).ptr());
+ break;
+ }
+#endif // defined(ENABLE_THEMES)
default:
NOTREACHED() << "Unexpected notification type in InstantService.";
}
@@ -208,3 +245,81 @@ void InstantService::OnMostVisitedItemsReceived(
}
#endif
}
+
+void InstantService::OnThemeChanged(ThemeService* theme_service) {
+ if (!theme_service) {
+ DCHECK(theme_info_.get());
+ FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
+ ThemeInfoChanged(*theme_info_));
+ return;
+ }
+
+ // Get theme information from theme service.
+ theme_info_.reset(new ThemeBackgroundInfo());
+
+ // Set theme background color.
+ SkColor background_color =
+ theme_service->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND);
+ if (gfx::IsInvertedColorScheme())
+ background_color = color_utils::InvertColor(background_color);
+
+ theme_info_->color_r = SkColorGetR(background_color);
+ theme_info_->color_g = SkColorGetG(background_color);
+ theme_info_->color_b = SkColorGetB(background_color);
+ theme_info_->color_a = SkColorGetA(background_color);
+
+ if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
+ // Set theme id for theme background image url.
+ theme_info_->theme_id = theme_service->GetThemeID();
+
+ // Set theme background image horizontal alignment.
+ int alignment = 0;
+ theme_service->GetDisplayProperty(
+ ThemeProperties::NTP_BACKGROUND_ALIGNMENT, &alignment);
+ if (alignment & ThemeProperties::ALIGN_LEFT)
+ theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT;
+ else if (alignment & ThemeProperties::ALIGN_RIGHT)
+ theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT;
+ else
+ theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
+
+ // Set theme background image vertical alignment.
+ if (alignment & ThemeProperties::ALIGN_TOP)
+ theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP;
+ else if (alignment & ThemeProperties::ALIGN_BOTTOM)
+ theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM;
+ else
+ theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
+
+ // Set theme backgorund image tiling.
+ int tiling = 0;
+ theme_service->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING,
+ &tiling);
+ switch (tiling) {
+ case ThemeProperties::NO_REPEAT:
+ theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT;
+ break;
+ case ThemeProperties::REPEAT_X:
+ theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_X;
+ break;
+ case ThemeProperties::REPEAT_Y:
+ theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y;
+ break;
+ case ThemeProperties::REPEAT:
+ theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT;
+ break;
+ }
+
+ // Set theme background image height.
+ gfx::ImageSkia* image = theme_service->GetImageSkiaNamed(
+ IDR_THEME_NTP_BACKGROUND);
+ DCHECK(image);
+ theme_info_->image_height = image->height();
+
+ theme_info_->has_attribution =
+ theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION);
+ }
+
+ FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
+ ThemeInfoChanged(*theme_info_));
+}
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/instant_service_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698