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

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::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::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::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, chrome::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
417 NotificationService::AllSources()); 418 NotificationService::AllSources());
418 } 419 }
419 420
420 NewTabUI::~NewTabUI() { 421 NewTabUI::~NewTabUI() {
421 } 422 }
422 423
423 // The timer callback. If enough time has elapsed since the last paint 424 // The timer callback. If enough time has elapsed since the last paint
424 // message, we say we're done painting; otherwise, we keep waiting. 425 // message, we say we're done painting; otherwise, we keep waiting.
425 void NewTabUI::PaintTimeout() { 426 void NewTabUI::PaintTimeout() {
426 // The amount of time there must be no painting for us to consider painting 427 // 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. 428 // finished. Observed times are in the ~1200ms range on Windows.
428 base::TimeTicks now = base::TimeTicks::Now(); 429 base::TimeTicks now = base::TimeTicks::Now();
429 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) { 430 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) {
430 // Painting has quieted down. Log this as the full time to run. 431 // Painting has quieted down. Log this as the full time to run.
431 base::TimeDelta load_time = last_paint_ - start_; 432 base::TimeDelta load_time = last_paint_ - start_;
432 int load_time_ms = static_cast<int>(load_time.InMilliseconds()); 433 int load_time_ms = static_cast<int>(load_time.InMilliseconds());
433 NotificationService::current()->Notify( 434 NotificationService::current()->Notify(
434 NotificationType::INITIAL_NEW_TAB_UI_LOAD, 435 chrome::INITIAL_NEW_TAB_UI_LOAD,
435 NotificationService::AllSources(), 436 NotificationService::AllSources(),
436 Details<int>(&load_time_ms)); 437 Details<int>(&load_time_ms));
437 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time); 438 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time);
438 } else { 439 } else {
439 // Not enough quiet time has elapsed. 440 // Not enough quiet time has elapsed.
440 // Some more paints must've occurred since we set the timeout. 441 // Some more paints must've occurred since we set the timeout.
441 // Wait some more. 442 // Wait some more.
442 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this, 443 timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this,
443 &NewTabUI::PaintTimeout); 444 &NewTabUI::PaintTimeout);
444 } 445 }
(...skipping 13 matching lines...) Expand all
458 } 459 }
459 460
460 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { 461 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) {
461 StartTimingPaint(render_view_host); 462 StartTimingPaint(render_view_host);
462 } 463 }
463 464
464 void NewTabUI::Observe(NotificationType type, 465 void NewTabUI::Observe(NotificationType type,
465 const NotificationSource& source, 466 const NotificationSource& source,
466 const NotificationDetails& details) { 467 const NotificationDetails& details) {
467 switch (type.value) { 468 switch (type.value) {
468 case NotificationType::BROWSER_THEME_CHANGED: { 469 case chrome::BROWSER_THEME_CHANGED: {
469 InitializeCSSCaches(); 470 InitializeCSSCaches();
470 ListValue args; 471 ListValue args;
471 args.Append(Value::CreateStringValue( 472 args.Append(Value::CreateStringValue(
472 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( 473 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage(
473 IDR_THEME_NTP_ATTRIBUTION) ? 474 IDR_THEME_NTP_ATTRIBUTION) ?
474 "true" : "false")); 475 "true" : "false"));
475 CallJavascriptFunction("themeChanged", args); 476 CallJavascriptFunction("themeChanged", args);
476 break; 477 break;
477 } 478 }
478 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: { 479 case chrome::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: {
479 if (GetProfile()->GetPrefs()->IsManagedPreference( 480 if (GetProfile()->GetPrefs()->IsManagedPreference(
480 prefs::kEnableBookmarkBar)) { 481 prefs::kEnableBookmarkBar)) {
481 break; 482 break;
482 } 483 }
483 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) 484 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar))
484 CallJavascriptFunction("bookmarkBarAttached"); 485 CallJavascriptFunction("bookmarkBarAttached");
485 else 486 else
486 CallJavascriptFunction("bookmarkBarDetached"); 487 CallJavascriptFunction("bookmarkBarDetached");
487 break; 488 break;
488 } 489 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 SendResponse(request_id, html_bytes); 670 SendResponse(request_id, html_bytes);
670 } 671 }
671 672
672 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { 673 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
673 return "text/html"; 674 return "text/html";
674 } 675 }
675 676
676 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 677 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
677 return false; 678 return false;
678 } 679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698