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

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: respond to comments 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 RGBAColor color; 375 RGBAColor color;
375 color.r = SkColorGetR(sKColor); 376 color.r = SkColorGetR(sKColor);
376 color.g = SkColorGetG(sKColor); 377 color.g = SkColorGetG(sKColor);
377 color.b = SkColorGetB(sKColor); 378 color.b = SkColorGetB(sKColor);
378 color.a = SkColorGetA(sKColor); 379 color.a = SkColorGetA(sKColor);
379 return color; 380 return color;
380 } 381 }
381 382
382 } // namespace 383 } // namespace
383 384
384 void InstantService::OnThemeChanged(ThemeService* theme_service) { 385 void InstantService::OnThemeChanged() {
385 if (!theme_service) {
386 DCHECK(theme_info_.get());
387 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
388 ThemeInfoChanged(*theme_info_));
389 return;
390 }
391
392 // Get theme information from theme service. 386 // Get theme information from theme service.
393 theme_info_.reset(new ThemeBackgroundInfo()); 387 theme_info_.reset(new ThemeBackgroundInfo());
394 388
395 // Get if the current theme is the default theme. 389 // Get if the current theme is the default theme.
390 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
396 theme_info_->using_default_theme = theme_service->UsingDefaultTheme(); 391 theme_info_->using_default_theme = theme_service->UsingDefaultTheme();
397 392
398 // Get theme colors. 393 // Get theme colors.
394 const ui::ThemeProvider& theme_provider =
395 ThemeService::GetThemeProviderForProfile(profile_);
399 SkColor background_color = 396 SkColor background_color =
400 theme_service->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND); 397 theme_provider.GetColor(ThemeProperties::COLOR_NTP_BACKGROUND);
401 SkColor text_color = 398 SkColor text_color = theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT);
402 theme_service->GetColor(ThemeProperties::COLOR_NTP_TEXT); 399 SkColor link_color = theme_provider.GetColor(ThemeProperties::COLOR_NTP_LINK);
403 SkColor link_color =
404 theme_service->GetColor(ThemeProperties::COLOR_NTP_LINK);
405 SkColor text_color_light = 400 SkColor text_color_light =
406 theme_service->GetColor(ThemeProperties::COLOR_NTP_TEXT_LIGHT); 401 theme_provider.GetColor(ThemeProperties::COLOR_NTP_TEXT_LIGHT);
407 SkColor header_color = 402 SkColor header_color =
408 theme_service->GetColor(ThemeProperties::COLOR_NTP_HEADER); 403 theme_provider.GetColor(ThemeProperties::COLOR_NTP_HEADER);
409 // Generate section border color from the header color. 404 // Generate section border color from the header color.
410 SkColor section_border_color = 405 SkColor section_border_color =
411 SkColorSetARGB(kSectionBorderAlphaTransparency, 406 SkColorSetARGB(kSectionBorderAlphaTransparency,
412 SkColorGetR(header_color), 407 SkColorGetR(header_color),
413 SkColorGetG(header_color), 408 SkColorGetG(header_color),
414 SkColorGetB(header_color)); 409 SkColorGetB(header_color));
415 410
416 // Invert colors if needed. 411 // Invert colors if needed.
417 if (color_utils::IsInvertedColorScheme()) { 412 if (color_utils::IsInvertedColorScheme()) {
418 background_color = color_utils::InvertColor(background_color); 413 background_color = color_utils::InvertColor(background_color);
419 text_color = color_utils::InvertColor(text_color); 414 text_color = color_utils::InvertColor(text_color);
420 link_color = color_utils::InvertColor(link_color); 415 link_color = color_utils::InvertColor(link_color);
421 text_color_light = color_utils::InvertColor(text_color_light); 416 text_color_light = color_utils::InvertColor(text_color_light);
422 header_color = color_utils::InvertColor(header_color); 417 header_color = color_utils::InvertColor(header_color);
423 section_border_color = color_utils::InvertColor(section_border_color); 418 section_border_color = color_utils::InvertColor(section_border_color);
424 } 419 }
425 420
426 // Set colors. 421 // Set colors.
427 theme_info_->background_color = SkColorToRGBAColor(background_color); 422 theme_info_->background_color = SkColorToRGBAColor(background_color);
428 theme_info_->text_color = SkColorToRGBAColor(text_color); 423 theme_info_->text_color = SkColorToRGBAColor(text_color);
429 theme_info_->link_color = SkColorToRGBAColor(link_color); 424 theme_info_->link_color = SkColorToRGBAColor(link_color);
430 theme_info_->text_color_light = SkColorToRGBAColor(text_color_light); 425 theme_info_->text_color_light = SkColorToRGBAColor(text_color_light);
431 theme_info_->header_color = SkColorToRGBAColor(header_color); 426 theme_info_->header_color = SkColorToRGBAColor(header_color);
432 theme_info_->section_border_color = SkColorToRGBAColor(section_border_color); 427 theme_info_->section_border_color = SkColorToRGBAColor(section_border_color);
433 428
434 int logo_alternate = theme_service->GetDisplayProperty( 429 int logo_alternate =
435 ThemeProperties::NTP_LOGO_ALTERNATE); 430 theme_provider.GetDisplayProperty(ThemeProperties::NTP_LOGO_ALTERNATE);
436 theme_info_->logo_alternate = logo_alternate == 1; 431 theme_info_->logo_alternate = logo_alternate == 1;
437 432
438 if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { 433 if (theme_provider.HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
439 // Set theme id for theme background image url. 434 // Set theme id for theme background image url.
440 theme_info_->theme_id = theme_service->GetThemeID(); 435 theme_info_->theme_id = theme_service->GetThemeID();
441 436
442 // Set theme background image horizontal alignment. 437 // Set theme background image horizontal alignment.
443 int alignment = theme_service->GetDisplayProperty( 438 int alignment = theme_provider.GetDisplayProperty(
444 ThemeProperties::NTP_BACKGROUND_ALIGNMENT); 439 ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
445 if (alignment & ThemeProperties::ALIGN_LEFT) 440 if (alignment & ThemeProperties::ALIGN_LEFT)
446 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT; 441 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT;
447 else if (alignment & ThemeProperties::ALIGN_RIGHT) 442 else if (alignment & ThemeProperties::ALIGN_RIGHT)
448 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT; 443 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT;
449 else 444 else
450 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; 445 theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
451 446
452 // Set theme background image vertical alignment. 447 // Set theme background image vertical alignment.
453 if (alignment & ThemeProperties::ALIGN_TOP) 448 if (alignment & ThemeProperties::ALIGN_TOP)
454 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP; 449 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP;
455 else if (alignment & ThemeProperties::ALIGN_BOTTOM) 450 else if (alignment & ThemeProperties::ALIGN_BOTTOM)
456 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM; 451 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM;
457 else 452 else
458 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; 453 theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
459 454
460 // Set theme backgorund image tiling. 455 // Set theme backgorund image tiling.
461 int tiling = theme_service->GetDisplayProperty( 456 int tiling = theme_provider.GetDisplayProperty(
462 ThemeProperties::NTP_BACKGROUND_TILING); 457 ThemeProperties::NTP_BACKGROUND_TILING);
463 switch (tiling) { 458 switch (tiling) {
464 case ThemeProperties::NO_REPEAT: 459 case ThemeProperties::NO_REPEAT:
465 theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT; 460 theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT;
466 break; 461 break;
467 case ThemeProperties::REPEAT_X: 462 case ThemeProperties::REPEAT_X:
468 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_X; 463 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_X;
469 break; 464 break;
470 case ThemeProperties::REPEAT_Y: 465 case ThemeProperties::REPEAT_Y:
471 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y; 466 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y;
472 break; 467 break;
473 case ThemeProperties::REPEAT: 468 case ThemeProperties::REPEAT:
474 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT; 469 theme_info_->image_tiling = THEME_BKGRND_IMAGE_REPEAT;
475 break; 470 break;
476 } 471 }
477 472
478 // Set theme background image height. 473 // Set theme background image height.
479 gfx::ImageSkia* image = theme_service->GetImageSkiaNamed( 474 gfx::ImageSkia* image =
480 IDR_THEME_NTP_BACKGROUND); 475 theme_provider.GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND);
481 DCHECK(image); 476 DCHECK(image);
482 theme_info_->image_height = image->height(); 477 theme_info_->image_height = image->height();
483 478
484 theme_info_->has_attribution = 479 theme_info_->has_attribution =
485 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); 480 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION);
486 } 481 }
487 482
488 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, 483 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
489 ThemeInfoChanged(*theme_info_)); 484 ThemeInfoChanged(*theme_info_));
490 } 485 }
491 #endif // defined(ENABLE_THEMES) 486 #endif // defined(ENABLE_THEMES)
492 487
493 void InstantService::OnTemplateURLServiceChanged() { 488 void InstantService::OnTemplateURLServiceChanged() {
494 // Check whether the default search provider was changed. 489 // Check whether the default search provider was changed.
495 const TemplateURL* template_url = 490 const TemplateURL* template_url =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 533 }
539 534
540 void InstantService::ResetInstantSearchPrerenderer() { 535 void InstantService::ResetInstantSearchPrerenderer() {
541 if (!search::ShouldPrefetchSearchResults()) 536 if (!search::ShouldPrefetchSearchResults())
542 return; 537 return;
543 538
544 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); 539 GURL url(search::GetSearchResultPrefetchBaseURL(profile_));
545 instant_prerenderer_.reset( 540 instant_prerenderer_.reset(
546 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 541 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
547 } 542 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698