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

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

Issue 8045012: NotificationPromo (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 9 years, 2 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 "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 "chrome/browser/prefs/pref_service.h" 7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "content/common/notification_service.h" 13 #include "content/common/notification_service.h"
14 #include "grit/chromium_strings.h" 14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 static const int kIntroDisplayMax = 10; 18 static const int kIntroDisplayMax = 10;
19 19
20 // The URL of a knowledge-base article about the new NTP. 20 // The URL of a knowledge-base article about the new NTP.
21 static const char kNTP4IntroURL[] = 21 static const char kNTP4IntroURL[] =
22 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; 22 "http://www.google.com/support/chrome/bin/answer.py?answer=95451";
23 23
24 void NewTabPageHandler::RegisterMessages() { 24 void NewTabPageHandler::RegisterMessages() {
25 web_ui_->RegisterMessageCallback("closePromo", NewCallback( 25 web_ui_->RegisterMessageCallback("closePromoNotification", NewCallback(
26 this, &NewTabPageHandler::HandleClosePromo)); 26 this, &NewTabPageHandler::HandleClosePromoNotification));
27 web_ui_->RegisterMessageCallback("promoNotificationViewed", NewCallback(
28 this, &NewTabPageHandler::HandlePromoNotificationViewed));
27 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( 29 web_ui_->RegisterMessageCallback("pageSelected", NewCallback(
28 this, &NewTabPageHandler::HandlePageSelected)); 30 this, &NewTabPageHandler::HandlePageSelected));
29 web_ui_->RegisterMessageCallback("introMessageDismissed", NewCallback( 31 web_ui_->RegisterMessageCallback("introMessageDismissed", NewCallback(
30 this, &NewTabPageHandler::HandleIntroMessageDismissed)); 32 this, &NewTabPageHandler::HandleIntroMessageDismissed));
31 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback( 33 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback(
32 this, &NewTabPageHandler::HandleIntroMessageSeen)); 34 this, &NewTabPageHandler::HandleIntroMessageSeen));
33 } 35 }
34 36
35 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { 37 void NewTabPageHandler::HandleClosePromoNotification(const ListValue* args) {
36 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, 38 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed,
37 true); 39 true);
38 NotificationService* service = NotificationService::current(); 40 NotificationService* service = NotificationService::current();
39 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 41 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
40 Source<NewTabPageHandler>(this), 42 Source<NewTabPageHandler>(this),
41 NotificationService::NoDetails()); 43 NotificationService::NoDetails());
42 } 44 }
43 45
46 void NewTabPageHandler::HandlePromoNotificationViewed(const ListValue* args) {
47 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
48 const int views = prefs->GetInteger(prefs::kNTPPromoViews) + 1;
49 prefs->SetInteger(prefs::kNTPPromoViews, views);
50 const int max_views = prefs->GetInteger(prefs::kNTPPromoViewsMax);
51
52 if (views >= max_views) {
53 NotificationService* service = NotificationService::current();
54 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
55 Source<NewTabPageHandler>(this),
56 NotificationService::NoDetails());
57 }
Dan Beam 2011/09/27 03:27:55 You might consider making this a different notific
achuithb 2011/09/27 08:03:19 The same notification is sent by the promo_resourc
58 }
59
44 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { 60 void NewTabPageHandler::HandlePageSelected(const ListValue* args) {
45 double page_id_double; 61 double page_id_double;
46 CHECK(args->GetDouble(0, &page_id_double)); 62 CHECK(args->GetDouble(0, &page_id_double));
47 int page_id = static_cast<int>(page_id_double); 63 int page_id = static_cast<int>(page_id_double);
48 64
49 double index_double; 65 double index_double;
50 CHECK(args->GetDouble(1, &index_double)); 66 CHECK(args->GetDouble(1, &index_double));
51 int index = static_cast<int>(index_double); 67 int index = static_cast<int>(index_double);
52 68
53 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 69 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 values->SetString("ntp4_intro_url", kNTP4IntroURL); 112 values->SetString("ntp4_intro_url", kNTP4IntroURL);
97 values->SetString("learn_more", 113 values->SetString("learn_more",
98 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 114 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
99 } 115 }
100 } 116 }
101 117
102 // static 118 // static
103 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { 119 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) {
104 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); 120 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1);
105 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698