| 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/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/extensions/default_apps_trial.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 13 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 13 #include "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
| 14 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 15 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 17 | 20 |
| 18 static const int kIntroDisplayMax = 10; | 21 namespace { |
| 22 const int kIntroDisplayMax = 10; |
| 23 } // anonymous |
| 19 | 24 |
| 20 // The URL of a knowledge-base article about the new NTP. | 25 // The URL of a knowledge-base article about the new NTP. |
| 21 static const char kNTP4IntroURL[] = | 26 static const char kNTP4IntroURL[] = |
| 22 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; | 27 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; |
| 23 | 28 |
| 29 WebUIMessageHandler* NewTabPageHandler::Attach(WebUI* web_ui) { |
| 30 // Record an open of the NTP with its default page type. |
| 31 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); |
| 32 int shown_page_type = prefs->GetInteger(prefs::kNTPShownPage) >> |
| 33 PAGE_ID_OFFSET; |
| 34 UMA_HISTOGRAM_ENUMERATION("NtpHandler.AttachShownPageType", |
| 35 shown_page_type, 4); |
| 36 |
| 37 static bool default_apps_trial_exists = |
| 38 base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name); |
| 39 if (default_apps_trial_exists) { |
| 40 UMA_HISTOGRAM_ENUMERATION( |
| 41 base::FieldTrial::MakeName("NtpHandler.AttachShownPageType", |
| 42 kDefaultAppsTrial_Name), |
| 43 shown_page_type, 4); |
| 44 } |
| 45 |
| 46 return WebUIMessageHandler::Attach(web_ui); |
| 47 } |
| 48 |
| 24 void NewTabPageHandler::RegisterMessages() { | 49 void NewTabPageHandler::RegisterMessages() { |
| 25 web_ui_->RegisterMessageCallback("closePromo", NewCallback( | 50 web_ui()->RegisterMessageCallback("closePromo", NewCallback( |
| 26 this, &NewTabPageHandler::HandleClosePromo)); | 51 this, &NewTabPageHandler::HandleClosePromo)); |
| 27 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( | 52 web_ui()->RegisterMessageCallback("pageSelected", NewCallback( |
| 28 this, &NewTabPageHandler::HandlePageSelected)); | 53 this, &NewTabPageHandler::HandlePageSelected)); |
| 29 web_ui_->RegisterMessageCallback("introMessageDismissed", NewCallback( | 54 web_ui()->RegisterMessageCallback("introMessageDismissed", NewCallback( |
| 30 this, &NewTabPageHandler::HandleIntroMessageDismissed)); | 55 this, &NewTabPageHandler::HandleIntroMessageDismissed)); |
| 31 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback( | 56 web_ui()->RegisterMessageCallback("introMessageSeen", NewCallback( |
| 32 this, &NewTabPageHandler::HandleIntroMessageSeen)); | 57 this, &NewTabPageHandler::HandleIntroMessageSeen)); |
| 33 } | 58 } |
| 34 | 59 |
| 35 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { | 60 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { |
| 36 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, | 61 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, |
| 37 true); | 62 true); |
| 38 NotificationService* service = NotificationService::current(); | 63 NotificationService* service = NotificationService::current(); |
| 39 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 64 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 40 Source<NewTabPageHandler>(this), | 65 Source<NewTabPageHandler>(this), |
| 41 NotificationService::NoDetails()); | 66 NotificationService::NoDetails()); |
| 42 } | 67 } |
| 43 | 68 |
| 44 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { | 69 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { |
| 45 double page_id_double; | 70 double page_id_double; |
| 46 CHECK(args->GetDouble(0, &page_id_double)); | 71 CHECK(args->GetDouble(0, &page_id_double)); |
| 47 int page_id = static_cast<int>(page_id_double); | 72 int page_id = static_cast<int>(page_id_double); |
| 48 | 73 |
| 49 double index_double; | 74 double index_double; |
| 50 CHECK(args->GetDouble(1, &index_double)); | 75 CHECK(args->GetDouble(1, &index_double)); |
| 51 int index = static_cast<int>(index_double); | 76 int index = static_cast<int>(index_double); |
| 52 | 77 |
| 53 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 78 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 54 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); | 79 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); |
| 80 |
| 81 int shown_page_type = page_id >> PAGE_ID_OFFSET; |
| 82 UMA_HISTOGRAM_ENUMERATION("NtpHandler.SelectedShownPageType", |
| 83 shown_page_type, 4); |
| 84 |
| 85 static bool default_apps_trial_exists = |
| 86 base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name); |
| 87 if (default_apps_trial_exists) { |
| 88 UMA_HISTOGRAM_ENUMERATION( |
| 89 base::FieldTrial::MakeName("NtpHandler.SelectedShownPageType", |
| 90 kDefaultAppsTrial_Name), |
| 91 shown_page_type, 4); |
| 92 } |
| 55 } | 93 } |
| 56 | 94 |
| 57 void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) { | 95 void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) { |
| 58 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 96 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 59 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); | 97 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); |
| 60 } | 98 } |
| 61 | 99 |
| 62 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) { | 100 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) { |
| 63 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 101 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 64 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount); | 102 int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount); |
| 65 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1); | 103 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1); |
| 66 } | 104 } |
| 67 | 105 |
| 68 // static | 106 // static |
| 69 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { | 107 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { |
| 70 // TODO(estade): should be syncable. | 108 // TODO(estade): should be syncable. |
| 71 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, | 109 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, |
| 72 PrefService::UNSYNCABLE_PREF); | 110 PrefService::UNSYNCABLE_PREF); |
| 73 prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0, | 111 prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 values->SetString("ntp4_intro_url", kNTP4IntroURL); | 134 values->SetString("ntp4_intro_url", kNTP4IntroURL); |
| 97 values->SetString("learn_more", | 135 values->SetString("learn_more", |
| 98 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 136 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 99 } | 137 } |
| 100 } | 138 } |
| 101 | 139 |
| 102 // static | 140 // static |
| 103 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { | 141 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { |
| 104 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); | 142 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); |
| 105 } | 143 } |
| OLD | NEW |