Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/field_trial.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "chrome/browser/extensions/default_apps_trial.h" | |
| 9 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
| 12 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 13 #include "chrome/browser/web_resource/notification_promo.h" | 16 #include "chrome/browser/web_resource/notification_promo.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 16 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
| 17 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 18 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 20 | 23 |
| 21 static const int kIntroDisplayMax = 10; | 24 static const int kIntroDisplayMax = 10; |
| 22 | 25 |
| 23 // The URL of a knowledge-base article about the new NTP. | 26 // The URL of a knowledge-base article about the new NTP. |
| 24 static const char kNTP4IntroURL[] = | 27 static const char kNTP4IntroURL[] = |
| 25 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; | 28 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; |
| 26 | 29 |
| 30 WebUIMessageHandler* NewTabPageHandler::Attach(WebUI* web_ui) { | |
| 31 // Record an open of the NTP with its default page type. | |
| 32 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); | |
| 33 int shown_page_type = prefs->GetInteger(prefs::kNTPShownPage) >> | |
| 34 kPageIdOffset; | |
| 35 UMA_HISTOGRAM_ENUMERATION("NewTabPage.DefaultPageType", | |
| 36 shown_page_type, 4); | |
| 37 | |
| 38 static bool default_apps_trial_exists = | |
| 39 base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name); | |
| 40 if (default_apps_trial_exists) { | |
| 41 UMA_HISTOGRAM_ENUMERATION( | |
| 42 base::FieldTrial::MakeName("NewTabPage.DefaultPageType", | |
| 43 kDefaultAppsTrial_Name), | |
| 44 shown_page_type, 4); | |
|
Evan Stade
2011/10/14 17:05:52
sorry for not being specific enough. My intent was
Roger Tawa OOO till Jul 10th
2011/10/14 19:21:12
Right, I should have done that. Will fix.
| |
| 45 } | |
| 46 | |
| 47 return WebUIMessageHandler::Attach(web_ui); | |
| 48 } | |
| 49 | |
| 27 void NewTabPageHandler::RegisterMessages() { | 50 void NewTabPageHandler::RegisterMessages() { |
| 28 web_ui_->RegisterMessageCallback("closeNotificationPromo", | 51 web_ui()->RegisterMessageCallback("closeNotificationPromo", |
| 29 base::Bind(&NewTabPageHandler::HandleCloseNotificationPromo, | 52 base::Bind(&NewTabPageHandler::HandleCloseNotificationPromo, |
| 30 base::Unretained(this))); | 53 base::Unretained(this))); |
| 31 web_ui_->RegisterMessageCallback("notificationPromoViewed", | 54 web_ui()->RegisterMessageCallback("notificationPromoViewed", |
| 32 base::Bind(&NewTabPageHandler::HandleNotificationPromoViewed, | 55 base::Bind(&NewTabPageHandler::HandleNotificationPromoViewed, |
| 33 base::Unretained(this))); | 56 base::Unretained(this))); |
| 34 web_ui_->RegisterMessageCallback("pageSelected", | 57 web_ui()->RegisterMessageCallback("pageSelected", |
| 35 base::Bind(&NewTabPageHandler::HandlePageSelected, | 58 base::Bind(&NewTabPageHandler::HandlePageSelected, |
| 36 base::Unretained(this))); | 59 base::Unretained(this))); |
| 37 web_ui_->RegisterMessageCallback("introMessageDismissed", | 60 web_ui()->RegisterMessageCallback("introMessageDismissed", |
| 38 base::Bind(&NewTabPageHandler::HandleIntroMessageDismissed, | 61 base::Bind(&NewTabPageHandler::HandleIntroMessageDismissed, |
| 39 base::Unretained(this))); | 62 base::Unretained(this))); |
| 40 web_ui_->RegisterMessageCallback("introMessageSeen", | 63 web_ui()->RegisterMessageCallback("introMessageSeen", |
| 41 base::Bind(&NewTabPageHandler::HandleIntroMessageSeen, | 64 base::Bind(&NewTabPageHandler::HandleIntroMessageSeen, |
| 42 base::Unretained(this))); | 65 base::Unretained(this))); |
| 43 } | 66 } |
| 44 | 67 |
| 45 void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) { | 68 void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) { |
| 46 NotificationPromo notification_promo( | 69 NotificationPromo notification_promo( |
| 47 Profile::FromWebUI(web_ui_)->GetPrefs(), NULL); | 70 Profile::FromWebUI(web_ui())->GetPrefs(), NULL); |
| 48 notification_promo.HandleClosed(); | 71 notification_promo.HandleClosed(); |
| 49 NotifyPromoResourceChanged(); | 72 NotifyPromoResourceChanged(); |
| 50 } | 73 } |
| 51 | 74 |
| 52 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { | 75 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { |
| 53 NotificationPromo notification_promo( | 76 NotificationPromo notification_promo( |
| 54 Profile::FromWebUI(web_ui_)->GetPrefs(), NULL); | 77 Profile::FromWebUI(web_ui_)->GetPrefs(), NULL); |
| 55 if (notification_promo.HandleViewed()) { | 78 if (notification_promo.HandleViewed()) { |
| 56 NotifyPromoResourceChanged(); | 79 NotifyPromoResourceChanged(); |
| 57 } | 80 } |
| 58 } | 81 } |
| 59 | 82 |
| 60 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { | 83 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { |
| 61 double page_id_double; | 84 double page_id_double; |
| 62 CHECK(args->GetDouble(0, &page_id_double)); | 85 CHECK(args->GetDouble(0, &page_id_double)); |
| 63 int page_id = static_cast<int>(page_id_double); | 86 int page_id = static_cast<int>(page_id_double); |
| 64 | 87 |
| 65 double index_double; | 88 double index_double; |
| 66 CHECK(args->GetDouble(1, &index_double)); | 89 CHECK(args->GetDouble(1, &index_double)); |
| 67 int index = static_cast<int>(index_double); | 90 int index = static_cast<int>(index_double); |
| 68 | 91 |
| 69 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 92 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 70 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); | 93 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); |
| 94 | |
| 95 int shown_page_type = page_id >> kPageIdOffset; | |
| 96 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SelectedPageType", | |
| 97 shown_page_type, 4); | |
| 98 | |
| 99 static bool default_apps_trial_exists = | |
| 100 base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name); | |
| 101 if (default_apps_trial_exists) { | |
| 102 UMA_HISTOGRAM_ENUMERATION( | |
| 103 base::FieldTrial::MakeName("NewTabPage.SelectedPageType", | |
| 104 kDefaultAppsTrial_Name), | |
| 105 shown_page_type, 4); | |
| 106 } | |
| 71 } | 107 } |
| 72 | 108 |
| 73 void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) { | 109 void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) { |
| 74 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 110 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 75 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); | 111 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); |
| 76 } | 112 } |
| 77 | 113 |
| 78 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) { | 114 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) { |
| 79 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 115 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 80 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount); | 116 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount); |
| 81 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1); | 117 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1); |
| 82 } | 118 } |
| 83 | 119 |
| 84 // static | 120 // static |
| 85 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { | 121 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { |
| 86 // TODO(estade): should be syncable. | 122 // TODO(estade): should be syncable. |
| 87 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, | 123 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, |
| 88 PrefService::UNSYNCABLE_PREF); | 124 PrefService::UNSYNCABLE_PREF); |
| 89 prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0, | 125 prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 119 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { | 155 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { |
| 120 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); | 156 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); |
| 121 } | 157 } |
| 122 | 158 |
| 123 void NewTabPageHandler::NotifyPromoResourceChanged() { | 159 void NewTabPageHandler::NotifyPromoResourceChanged() { |
| 124 NotificationService* service = NotificationService::current(); | 160 NotificationService* service = NotificationService::current(); |
| 125 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 161 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 126 Source<NewTabPageHandler>(this), | 162 Source<NewTabPageHandler>(this), |
| 127 NotificationService::NoDetails()); | 163 NotificationService::NoDetails()); |
| 128 } | 164 } |
| OLD | NEW |