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

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 564353002: [Themes Service] Implement better default value for which Google logo to use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment and style fixes. Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
12 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return color_utils::HSLToSkColor(result, SkColorGetA(color)); 73 return color_utils::HSLToSkColor(result, SkColorGetA(color));
72 } 74 }
73 75
74 // Writes the theme pack to disk on a separate thread. 76 // Writes the theme pack to disk on a separate thread.
75 void WritePackToDiskCallback(BrowserThemePack* pack, 77 void WritePackToDiskCallback(BrowserThemePack* pack,
76 const base::FilePath& path) { 78 const base::FilePath& path) {
77 if (!pack->WriteToDisk(path)) 79 if (!pack->WriteToDisk(path))
78 NOTREACHED() << "Could not write theme pack to disk"; 80 NOTREACHED() << "Could not write theme pack to disk";
79 } 81 }
80 82
83 // Heuristic to determine if color is grayscale. This is used to decide whether
84 // to use the colorful or white logo, if a theme fails to specify which.
85 bool IsColorGrayscale(SkColor color) {
86 const int kChannelTolerance = 9;
87 int r = SkColorGetR(color);
88 int g = SkColorGetG(color);
89 int b = SkColorGetB(color);
90 int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b));
91 return range < kChannelTolerance;
92 }
93
81 } // namespace 94 } // namespace
82 95
83 ThemeService::ThemeService() 96 ThemeService::ThemeService()
84 : ready_(false), 97 : ready_(false),
85 rb_(ResourceBundle::GetSharedInstance()), 98 rb_(ResourceBundle::GetSharedInstance()),
86 profile_(NULL), 99 profile_(NULL),
87 installed_pending_load_id_(kDefaultThemeID), 100 installed_pending_load_id_(kDefaultThemeID),
88 number_of_infobars_(0), 101 number_of_infobars_(0),
89 weak_ptr_factory_(this) { 102 weak_ptr_factory_(this) {
90 } 103 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return Properties::GetDefaultColor(id); 199 return Properties::GetDefaultColor(id);
187 } 200 }
188 201
189 int ThemeService::GetDisplayProperty(int id) const { 202 int ThemeService::GetDisplayProperty(int id) const {
190 int result = 0; 203 int result = 0;
191 if (theme_supplier_.get() && 204 if (theme_supplier_.get() &&
192 theme_supplier_->GetDisplayProperty(id, &result)) { 205 theme_supplier_->GetDisplayProperty(id, &result)) {
193 return result; 206 return result;
194 } 207 }
195 208
196 if (id == Properties::NTP_LOGO_ALTERNATE && 209 if (id == Properties::NTP_LOGO_ALTERNATE) {
197 !UsingDefaultTheme() && 210 if (UsingDefaultTheme() || UsingSystemTheme())
198 !UsingSystemTheme()) { 211 return 0; // Colorful logo.
199 // Use the alternate logo for themes from the web store except for 212
200 // |kDefaultThemeGalleryID|. 213 if (HasCustomImage(IDR_THEME_NTP_BACKGROUND))
201 return 1; 214 return 1; // White logo.
215
216 SkColor background_color = GetColor(Properties::COLOR_NTP_BACKGROUND);
217 return IsColorGrayscale(background_color) ? 0 : 1;
202 } 218 }
203 219
204 return Properties::GetDefaultDisplayProperty(id); 220 return Properties::GetDefaultDisplayProperty(id);
205 } 221 }
206 222
207 bool ThemeService::ShouldUseNativeFrame() const { 223 bool ThemeService::ShouldUseNativeFrame() const {
208 if (HasCustomImage(IDR_THEME_FRAME)) 224 if (HasCustomImage(IDR_THEME_FRAME))
209 return false; 225 return false;
210 #if defined(OS_WIN) 226 #if defined(OS_WIN)
211 return ui::win::IsAeroGlassEnabled(); 227 return ui::win::IsAeroGlassEnabled();
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 void ThemeService::OnInfobarDestroyed() { 619 void ThemeService::OnInfobarDestroyed() {
604 number_of_infobars_--; 620 number_of_infobars_--;
605 621
606 if (number_of_infobars_ == 0) 622 if (number_of_infobars_ == 0)
607 RemoveUnusedThemes(false); 623 RemoveUnusedThemes(false);
608 } 624 }
609 625
610 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 626 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
611 return theme_syncable_service_.get(); 627 return theme_syncable_service_.get();
612 } 628 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698