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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 22 matching lines...) Expand all
33 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" 33 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
34 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" 34 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
35 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 35 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
36 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" 36 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
37 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" 37 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
40 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" 40 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
41 #include "chrome/browser/ui/webui/ntp/value_helper.h" 41 #include "chrome/browser/ui/webui/ntp/value_helper.h"
42 #include "chrome/browser/ui/webui/theme_source.h" 42 #include "chrome/browser/ui/webui/theme_source.h"
43 #include "chrome/common/chrome_notification_types.h"
43 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/extensions/extension.h" 45 #include "chrome/common/extensions/extension.h"
45 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
46 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
47 #include "content/browser/browser_thread.h" 48 #include "content/browser/browser_thread.h"
48 #include "content/browser/renderer_host/render_view_host.h" 49 #include "content/browser/renderer_host/render_view_host.h"
49 #include "content/browser/tab_contents/tab_contents.h" 50 #include "content/browser/tab_contents/tab_contents.h"
50 #include "content/browser/user_metrics.h" 51 #include "content/browser/user_metrics.h"
51 #include "content/common/notification_service.h" 52 #include "content/common/notification_service.h"
52 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } else if (event_name == "Tab.NewTabDOMContentLoaded") { 260 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
260 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); 261 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
261 } else if (event_name == "Tab.NewTabOnload") { 262 } else if (event_name == "Tab.NewTabOnload") {
262 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); 263 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
263 // The new tab page has finished loading; reset it. 264 // The new tab page has finished loading; reset it.
264 tab->set_new_tab_start_time(base::TimeTicks()); 265 tab->set_new_tab_start_time(base::TimeTicks());
265 } else { 266 } else {
266 NOTREACHED(); 267 NOTREACHED();
267 } 268 }
268 NotificationService::current()->Notify( 269 NotificationService::current()->Notify(
269 NotificationType::METRIC_EVENT_DURATION, 270 chrome::NOTIFICATION_METRIC_EVENT_DURATION,
270 Source<TabContents>(tab), 271 Source<TabContents>(tab),
271 Details<MetricEventDurationDetails>(&details)); 272 Details<MetricEventDurationDetails>(&details));
272 } 273 }
273 274
274 /////////////////////////////////////////////////////////////////////////////// 275 ///////////////////////////////////////////////////////////////////////////////
275 // NewTabPageSetHomePageHandler 276 // NewTabPageSetHomePageHandler
276 277
277 // Sets the new tab page as home page when user clicks on "make this my home 278 // Sets the new tab page as home page when user clicks on "make this my home
278 // page" link. 279 // page" link.
279 class NewTabPageSetHomePageHandler : public WebUIMessageHandler { 280 class NewTabPageSetHomePageHandler : public WebUIMessageHandler {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 333
333 void NewTabPageClosePromoHandler::RegisterMessages() { 334 void NewTabPageClosePromoHandler::RegisterMessages() {
334 web_ui_->RegisterMessageCallback("closePromo", NewCallback( 335 web_ui_->RegisterMessageCallback("closePromo", NewCallback(
335 this, &NewTabPageClosePromoHandler::HandleClosePromo)); 336 this, &NewTabPageClosePromoHandler::HandleClosePromo));
336 } 337 }
337 338
338 void NewTabPageClosePromoHandler::HandleClosePromo( 339 void NewTabPageClosePromoHandler::HandleClosePromo(
339 const ListValue* args) { 340 const ListValue* args) {
340 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); 341 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true);
341 NotificationService* service = NotificationService::current(); 342 NotificationService* service = NotificationService::current();
342 service->Notify(NotificationType::PROMO_RESOURCE_STATE_CHANGED, 343 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
343 Source<NewTabPageClosePromoHandler>(this), 344 Source<NewTabPageClosePromoHandler>(this),
344 NotificationService::NoDetails()); 345 NotificationService::NoDetails());
345 } 346 }
346 347
347 } // namespace 348 } // namespace
348 349
349 /////////////////////////////////////////////////////////////////////////////// 350 ///////////////////////////////////////////////////////////////////////////////
350 // NewTabUI 351 // NewTabUI
351 352
352 NewTabUI::NewTabUI(TabContents* contents) 353 NewTabUI::NewTabUI(TabContents* contents)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 403
403 // Initializing the CSS and HTML can require some CPU, so do it after 404 // Initializing the CSS and HTML can require some CPU, so do it after
404 // we've hooked up the most visited handler. This allows the DB query 405 // we've hooked up the most visited handler. This allows the DB query
405 // for the new tab thumbs to happen earlier. 406 // for the new tab thumbs to happen earlier.
406 InitializeCSSCaches(); 407 InitializeCSSCaches();
407 NewTabHTMLSource* html_source = 408 NewTabHTMLSource* html_source =
408 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); 409 new NewTabHTMLSource(GetProfile()->GetOriginalProfile());
409 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 410 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
410 411
411 // Listen for theme installation. 412 // Listen for theme installation.
412 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, 413 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
413 Source<ThemeService>( 414 Source<ThemeService>(
414 ThemeServiceFactory::GetForProfile(GetProfile()))); 415 ThemeServiceFactory::GetForProfile(GetProfile())));
415 // Listen for bookmark bar visibility changes. 416 // Listen for bookmark bar visibility changes.
416 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 417 registrar_.Add(this,
418 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
417 NotificationService::AllSources()); 419 NotificationService::AllSources());
418 } 420 }
419 421
420 NewTabUI::~NewTabUI() { 422 NewTabUI::~NewTabUI() {
421 } 423 }
422 424
423 // The timer callback. If enough time has elapsed since the last paint 425 // The timer callback. If enough time has elapsed since the last paint
424 // message, we say we're done painting; otherwise, we keep waiting. 426 // message, we say we're done painting; otherwise, we keep waiting.
425 void NewTabUI::PaintTimeout() { 427 void NewTabUI::PaintTimeout() {
426 // The amount of time there must be no painting for us to consider painting 428 // The amount of time there must be no painting for us to consider painting
427 // finished. Observed times are in the ~1200ms range on Windows. 429 // finished. Observed times are in the ~1200ms range on Windows.
428 base::TimeTicks now = base::TimeTicks::Now(); 430 base::TimeTicks now = base::TimeTicks::Now();
429 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) { 431 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) {
430 // Painting has quieted down. Log this as the full time to run. 432 // Painting has quieted down. Log this as the full time to run.
431 base::TimeDelta load_time = last_paint_ - start_; 433 base::TimeDelta load_time = last_paint_ - start_;
432 int load_time_ms = static_cast<int>(load_time.InMilliseconds()); 434 int load_time_ms = static_cast<int>(load_time.InMilliseconds());
433 NotificationService::current()->Notify( 435 NotificationService::current()->Notify(
434 NotificationType::INITIAL_NEW_TAB_UI_LOAD, 436 chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD,
435 NotificationService::AllSources(), 437 NotificationService::AllSources(),
436 Details<int>(&load_time_ms)); 438 Details<int>(&load_time_ms));
437 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time); 439 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time);
438 } else { 440 } else {
439 // Not enough quiet time has elapsed. 441 // Not enough quiet time has elapsed.
440 // Some more paints must've occurred since we set the timeout. 442 // Some more paints must've occurred since we set the timeout.
441 // Wait some more. 443 // Wait some more.
442 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this, 444 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this,
443 &NewTabUI::PaintTimeout); 445 &NewTabUI::PaintTimeout);
444 } 446 }
445 } 447 }
446 448
447 void NewTabUI::StartTimingPaint(RenderViewHost* render_view_host) { 449 void NewTabUI::StartTimingPaint(RenderViewHost* render_view_host) {
448 start_ = base::TimeTicks::Now(); 450 start_ = base::TimeTicks::Now();
449 last_paint_ = start_; 451 last_paint_ = start_;
450 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, 452 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
451 Source<RenderWidgetHost>(render_view_host)); 453 Source<RenderWidgetHost>(render_view_host));
452 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this, 454 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this,
453 &NewTabUI::PaintTimeout); 455 &NewTabUI::PaintTimeout);
454 456
455 } 457 }
456 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { 458 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) {
457 StartTimingPaint(render_view_host); 459 StartTimingPaint(render_view_host);
458 } 460 }
459 461
460 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { 462 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) {
461 StartTimingPaint(render_view_host); 463 StartTimingPaint(render_view_host);
462 } 464 }
463 465
464 void NewTabUI::Observe(NotificationType type, 466 void NewTabUI::Observe(int type,
465 const NotificationSource& source, 467 const NotificationSource& source,
466 const NotificationDetails& details) { 468 const NotificationDetails& details) {
467 switch (type.value) { 469 switch (type) {
468 case NotificationType::BROWSER_THEME_CHANGED: { 470 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
469 InitializeCSSCaches(); 471 InitializeCSSCaches();
470 ListValue args; 472 ListValue args;
471 args.Append(Value::CreateStringValue( 473 args.Append(Value::CreateStringValue(
472 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( 474 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage(
473 IDR_THEME_NTP_ATTRIBUTION) ? 475 IDR_THEME_NTP_ATTRIBUTION) ?
474 "true" : "false")); 476 "true" : "false"));
475 CallJavascriptFunction("themeChanged", args); 477 CallJavascriptFunction("themeChanged", args);
476 break; 478 break;
477 } 479 }
478 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: { 480 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: {
479 if (GetProfile()->GetPrefs()->IsManagedPreference( 481 if (GetProfile()->GetPrefs()->IsManagedPreference(
480 prefs::kEnableBookmarkBar)) { 482 prefs::kEnableBookmarkBar)) {
481 break; 483 break;
482 } 484 }
483 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) 485 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar))
484 CallJavascriptFunction("bookmarkBarAttached"); 486 CallJavascriptFunction("bookmarkBarAttached");
485 else 487 else
486 CallJavascriptFunction("bookmarkBarDetached"); 488 CallJavascriptFunction("bookmarkBarDetached");
487 break; 489 break;
488 } 490 }
489 case NotificationType::RENDER_WIDGET_HOST_DID_PAINT: { 491 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: {
490 last_paint_ = base::TimeTicks::Now(); 492 last_paint_ = base::TimeTicks::Now();
491 break; 493 break;
492 } 494 }
493 default: 495 default:
494 CHECK(false) << "Unexpected notification: " << type.value; 496 CHECK(false) << "Unexpected notification: " << type;
495 } 497 }
496 } 498 }
497 499
498 void NewTabUI::InitializeCSSCaches() { 500 void NewTabUI::InitializeCSSCaches() {
499 Profile* profile = GetProfile(); 501 Profile* profile = GetProfile();
500 ThemeSource* theme = new ThemeSource(profile); 502 ThemeSource* theme = new ThemeSource(profile);
501 profile->GetChromeURLDataManager()->AddDataSource(theme); 503 profile->GetChromeURLDataManager()->AddDataSource(theme);
502 } 504 }
503 505
504 // static 506 // static
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 SendResponse(request_id, html_bytes); 672 SendResponse(request_id, html_bytes);
671 } 673 }
672 674
673 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { 675 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
674 return "text/html"; 676 return "text/html";
675 } 677 }
676 678
677 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 679 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
678 return false; 680 return false;
679 } 681 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_ui.h ('k') | chrome/browser/ui/webui/ntp/ntp_login_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698