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

Side by Side Diff: chrome/browser/search/instant_service.cc

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix that unittest Created 5 years 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 | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/local_ntp_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/search/instant_service.h" 5 #include "chrome/browser/search/instant_service.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 suggestions_service_->ClearBlacklist( 229 suggestions_service_->ClearBlacklist(
230 base::Bind(&InstantService::OnSuggestionsAvailable, 230 base::Bind(&InstantService::OnSuggestionsAvailable,
231 weak_ptr_factory_.GetWeakPtr())); 231 weak_ptr_factory_.GetWeakPtr()));
232 } 232 }
233 } 233 }
234 234
235 void InstantService::UpdateThemeInfo() { 235 void InstantService::UpdateThemeInfo() {
236 #if defined(ENABLE_THEMES) 236 #if defined(ENABLE_THEMES)
237 // Update theme background info. 237 // Update theme background info.
238 // Initialize |theme_info| if necessary. 238 // Initialize |theme_info| if necessary.
239 if (!theme_info_) 239 if (!theme_info_) {
240 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); 240 OnThemeChanged();
241 else 241 } else {
242 OnThemeChanged(NULL); 242 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
243 ThemeInfoChanged(*theme_info_));
244 }
243 #endif // defined(ENABLE_THEMES) 245 #endif // defined(ENABLE_THEMES)
244 } 246 }
245 247
246 void InstantService::UpdateMostVisitedItemsInfo() { 248 void InstantService::UpdateMostVisitedItemsInfo() {
247 NotifyAboutMostVisitedItems(); 249 NotifyAboutMostVisitedItems();
248 } 250 }
249 251
250 void InstantService::Shutdown() { 252 void InstantService::Shutdown() {
251 process_ids_.clear(); 253 process_ids_.clear();
252 254
(...skipping 18 matching lines...) Expand all
271 switch (type) { 273 switch (type) {
272 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: 274 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
273 SendSearchURLsToRenderer( 275 SendSearchURLsToRenderer(
274 content::Source<content::RenderProcessHost>(source).ptr()); 276 content::Source<content::RenderProcessHost>(source).ptr());
275 break; 277 break;
276 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: 278 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
277 OnRendererProcessTerminated( 279 OnRendererProcessTerminated(
278 content::Source<content::RenderProcessHost>(source)->GetID()); 280 content::Source<content::RenderProcessHost>(source)->GetID());
279 break; 281 break;
280 #if defined(ENABLE_THEMES) 282 #if defined(ENABLE_THEMES)
281 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 283 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
282 OnThemeChanged(content::Source<ThemeService>(source).ptr()); 284 OnThemeChanged();
283 break; 285 break;
284 }
285 #endif // defined(ENABLE_THEMES) 286 #endif // defined(ENABLE_THEMES)
286 default: 287 default:
287 NOTREACHED() << "Unexpected notification type in InstantService."; 288 NOTREACHED() << "Unexpected notification type in InstantService.";
288 } 289 }
289 } 290 }
290 291
291 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { 292 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) {
292 rph->Send(new ChromeViewMsg_SetSearchURLs( 293 rph->Send(new ChromeViewMsg_SetSearchURLs(
293 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); 294 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_)));
294 } 295 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 RGBAColor color; 377 RGBAColor color;
377 color.r = SkColorGetR(sKColor); 378 color.r = SkColorGetR(sKColor);
378 color.g = SkColorGetG(sKColor); 379 color.g = SkColorGetG(sKColor);
379 color.b = SkColorGetB(sKColor); 380 color.b = SkColorGetB(sKColor);
380 color.a = SkColorGetA(sKColor); 381 color.a = SkColorGetA(sKColor);
381 return color; 382 return color;
382 } 383 }
383 384
384 } // namespace 385 } // namespace
385 386
386 void InstantService::OnThemeChanged(ThemeService* theme_service) { 387 void InstantService::OnThemeChanged() {
387 if (!theme_service) {
388 DCHECK(theme_info_.get());
389 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
390 ThemeInfoChanged(*theme_info_));
391 return;
392 }
393
394 // Get theme information from theme service. 388 // Get theme information from theme service.
395 theme_info_.reset(new ThemeBackgroundInfo()); 389 theme_info_.reset(new ThemeBackgroundInfo());
396 390
397 // Get if the current theme is the default theme. 391 // Get if the current theme is the default theme.
392 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
398 theme_info_->using_default_theme = theme_service->UsingDefaultTheme(); 393 theme_info_->using_default_theme = theme_service->UsingDefaultTheme();
399 394
400 // Get theme colors. 395 // Get theme colors.
396 const ui::ThemeProvider& theme_provider =
397 ThemeService::GetThemeProviderForProfile(profile_);
401 SkColor background_color = 398 SkColor background_color =
402 theme_service->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND); 399 theme_provider.GetColor(ThemeProperties::COLOR_NTP_BACKGROUND);
403 SkColor text_color = 400 SkColor text_color = theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT);
404 theme_service->GetColor(ThemeProperties::COLOR_NTP_TEXT); 401 SkColor link_color = theme_provider.GetColor(ThemeProperties::COLOR_NTP_LINK);
405 SkColor link_color =
406 theme_service->GetColor(ThemeProperties::COLOR_NTP_LINK);
407 SkColor text_color_light = 402 SkColor text_color_light =
408 theme_service->GetColor(ThemeProperties::COLOR_NTP_TEXT_LIGHT); 403 theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT_LIGHT);
409 SkColor header_color = 404 SkColor header_color =
410 theme_service->GetColor(ThemeProperties::COLOR_NTP_HEADER); 405 theme_provider.GetColor(ThemeProperties::COLOR_NTP_HEADER);
411 // Generate section border color from the header color. 406 // Generate section border color from the header color.
412 SkColor section_border_color = 407 SkColor section_border_color =
413 SkColorSetARGB(kSectionBorderAlphaTransparency, 408 SkColorSetARGB(kSectionBorderAlphaTransparency,
414 SkColorGetR(header_color), 409 SkColorGetR(header_color),
415 SkColorGetG(header_color), 410 SkColorGetG(header_color),
416 SkColorGetB(header_color)); 411 SkColorGetB(header_color));
417 412
418 // Invert colors if needed. 413 // Invert colors if needed.
419 if (color_utils::IsInvertedColorScheme()) { 414 if (color_utils::IsInvertedColorScheme()) {
420 background_color = color_utils::InvertColor(background_color); 415 background_color = color_utils::InvertColor(background_color);
421 text_color = color_utils::InvertColor(text_color); 416 text_color = color_utils::InvertColor(text_color);
422 link_color = color_utils::InvertColor(link_color); 417 link_color = color_utils::InvertColor(link_color);
423 text_color_light = color_utils::InvertColor(text_color_light); 418 text_color_light = color_utils::InvertColor(text_color_light);
424 header_color = color_utils::InvertColor(header_color); 419 header_color = color_utils::InvertColor(header_color);
425 section_border_color = color_utils::InvertColor(section_border_color); 420 section_border_color = color_utils::InvertColor(section_border_color);
426 } 421 }
427 422
428 // Set colors. 423 // Set colors.
429 theme_info_->background_color = SkColorToRGBAColor(background_color); 424 theme_info_->background_color = SkColorToRGBAColor(background_color);
430 theme_info_->text_color = SkColorToRGBAColor(text_color); 425 theme_info_->text_color = SkColorToRGBAColor(text_color);
431 theme_info_->link_color = SkColorToRGBAColor(link_color); 426 theme_info_->link_color = SkColorToRGBAColor(link_color);
432 theme_info_->text_color_light = SkColorToRGBAColor(text_color_light); 427 theme_info_->text_color_light = SkColorToRGBAColor(text_color_light);
433 theme_info_->header_color = SkColorToRGBAColor(header_color); 428 theme_info_->header_color = SkColorToRGBAColor(header_color);
434 theme_info_->section_border_color = SkColorToRGBAColor(section_border_color); 429 theme_info_->section_border_color = SkColorToRGBAColor(section_border_color);
435 430
436 int logo_alternate = theme_service->GetDisplayProperty( 431 int logo_alternate =
437 ThemeProperties::NTP_LOGO_ALTERNATE); 432 theme_provider.GetDisplayProperty(ThemeProperties::NTP_LOGO_ALTERNATE);
438 theme_info_->logo_alternate = logo_alternate == 1; 433 theme_info_->logo_alternate = logo_alternate == 1;
439 434
440 if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { 435 if (theme_provider.HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
441 // Set theme id for theme background image url. 436 // Set theme id for theme background image url.
442 theme_info_->theme_id = theme_service->GetThemeID(); 437 theme_info_->theme_id = theme_service->GetThemeID();
443 438
444 // Set theme background image horizontal alignment. 439 // Set theme background image horizontal alignment.
445 int alignment = theme_service->GetDisplayProperty( 440 int alignment = theme_provider.GetDisplayProperty(
446 ThemeProperties::NTP_BACKGROUND_ALIGNMENT); 441 ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
447 if (alignment & ThemeProperties::ALIGN_LEFT) 442 if (alignment & ThemeProperties::ALIGN_LEFT)
448 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT; 443 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT;
449 else if (alignment & ThemeProperties::ALIGN_RIGHT) 444 else if (alignment & ThemeProperties::ALIGN_RIGHT)
450 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT; 445 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT;
451 else 446 else
452 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; 447 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
453 448
454 // Set theme background image vertical alignment. 449 // Set theme background image vertical alignment.
455 if (alignment & ThemeProperties::ALIGN_TOP) 450 if (alignment & ThemeProperties::ALIGN_TOP)
456 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP; 451 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP;
457 else if (alignment & ThemeProperties::ALIGN_BOTTOM) 452 else if (alignment & ThemeProperties::ALIGN_BOTTOM)
458 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM; 453 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM;
459 else 454 else
460 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; 455 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
461 456
462 // Set theme backgorund image tiling. 457 // Set theme backgorund image tiling.
463 int tiling = theme_service->GetDisplayProperty( 458 int tiling = theme_provider.GetDisplayProperty(
464 ThemeProperties::NTP_BACKGROUND_TILING); 459 ThemeProperties::NTP_BACKGROUND_TILING);
465 switch (tiling) { 460 switch (tiling) {
466 case ThemeProperties::NO_REPEAT: 461 case ThemeProperties::NO_REPEAT:
467 theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT; 462 theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT;
468 break; 463 break;
469 case ThemeProperties::REPEAT_X: 464 case ThemeProperties::REPEAT_X:
470 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_X; 465 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_X;
471 break; 466 break;
472 case ThemeProperties::REPEAT_Y: 467 case ThemeProperties::REPEAT_Y:
473 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y; 468 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y;
474 break; 469 break;
475 case ThemeProperties::REPEAT: 470 case ThemeProperties::REPEAT:
476 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT; 471 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT;
477 break; 472 break;
478 } 473 }
479 474
480 // Set theme background image height. 475 // Set theme background image height.
481 gfx::ImageSkia* image = theme_service->GetImageSkiaNamed( 476 gfx::ImageSkia* image =
482 IDR_THEME_NTP_BACKGROUND); 477 theme_provider.GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND);
483 DCHECK(image); 478 DCHECK(image);
484 theme_info_->image_height = image->height(); 479 theme_info_->image_height = image->height();
485 480
486 theme_info_->has_attribution = 481 theme_info_->has_attribution =
487 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); 482 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION);
488 } 483 }
489 484
490 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, 485 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
491 ThemeInfoChanged(*theme_info_)); 486 ThemeInfoChanged(*theme_info_));
492 } 487 }
493 #endif // defined(ENABLE_THEMES) 488 #endif // defined(ENABLE_THEMES)
494 489
495 void InstantService::OnTemplateURLServiceChanged() { 490 void InstantService::OnTemplateURLServiceChanged() {
496 // Check whether the default search provider was changed. 491 // Check whether the default search provider was changed.
497 const TemplateURL* template_url = 492 const TemplateURL* template_url =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 535 }
541 536
542 void InstantService::ResetInstantSearchPrerenderer() { 537 void InstantService::ResetInstantSearchPrerenderer() {
543 if (!search::ShouldPrefetchSearchResults()) 538 if (!search::ShouldPrefetchSearchResults())
544 return; 539 return;
545 540
546 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); 541 GURL url(search::GetSearchResultPrefetchBaseURL(profile_));
547 instant_prerenderer_.reset( 542 instant_prerenderer_.reset(
548 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 543 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
549 } 544 }
OLDNEW
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/local_ntp_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698