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

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

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Profile helper function, rebase Created 9 years, 4 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "content/common/notification_service.h" 13 #include "content/common/notification_service.h"
14 14
15 void NewTabPageHandler::RegisterMessages() { 15 void NewTabPageHandler::RegisterMessages() {
16 web_ui_->RegisterMessageCallback("closePromo", NewCallback( 16 web_ui_->RegisterMessageCallback("closePromo", NewCallback(
17 this, &NewTabPageHandler::HandleClosePromo)); 17 this, &NewTabPageHandler::HandleClosePromo));
18 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( 18 web_ui_->RegisterMessageCallback("pageSelected", NewCallback(
19 this, &NewTabPageHandler::HandlePageSelected)); 19 this, &NewTabPageHandler::HandlePageSelected));
20 } 20 }
21 21
22 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { 22 void NewTabPageHandler::HandleClosePromo(const ListValue* args) {
23 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); 23 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed,
24 true);
24 NotificationService* service = NotificationService::current(); 25 NotificationService* service = NotificationService::current();
25 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 26 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
26 Source<NewTabPageHandler>(this), 27 Source<NewTabPageHandler>(this),
27 NotificationService::NoDetails()); 28 NotificationService::NoDetails());
28 } 29 }
29 30
30 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { 31 void NewTabPageHandler::HandlePageSelected(const ListValue* args) {
31 double page_id_double; 32 double page_id_double;
32 CHECK(args->GetDouble(0, &page_id_double)); 33 CHECK(args->GetDouble(0, &page_id_double));
33 int page_id = static_cast<int>(page_id_double); 34 int page_id = static_cast<int>(page_id_double);
34 35
35 double index_double; 36 double index_double;
36 CHECK(args->GetDouble(1, &index_double)); 37 CHECK(args->GetDouble(1, &index_double));
37 int index = static_cast<int>(index_double); 38 int index = static_cast<int>(index_double);
38 39
39 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 40 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
40 prefs->SetInteger(prefs::kNTPShownPage, page_id | index); 41 prefs->SetInteger(prefs::kNTPShownPage, page_id | index);
41 } 42 }
42 43
43 // static 44 // static
44 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { 45 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) {
45 // TODO(estade): should be syncable. 46 // TODO(estade): should be syncable.
46 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID, 47 prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID,
47 PrefService::UNSYNCABLE_PREF); 48 PrefService::UNSYNCABLE_PREF);
48 } 49 }
49 50
50 // static 51 // static
51 void NewTabPageHandler::GetLocalizedValues(Profile* profile, 52 void NewTabPageHandler::GetLocalizedValues(Profile* profile,
52 DictionaryValue* values) { 53 DictionaryValue* values) {
53 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) 54 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4))
54 return; 55 return;
55 56
56 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); 57 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID);
57 values->SetInteger("apps_page_id", APPS_PAGE_ID); 58 values->SetInteger("apps_page_id", APPS_PAGE_ID);
58 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID); 59 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID);
59 60
60 // TODO(estade) Should respect shown sections pref (i.e. migrate if it 61 // TODO(estade) Should respect shown sections pref (i.e. migrate if it
61 // exists). 62 // exists).
62 PrefService* prefs = profile->GetPrefs(); 63 PrefService* prefs = profile->GetPrefs();
63 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); 64 int shown_page = prefs->GetInteger(prefs::kNTPShownPage);
64 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); 65 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK);
65 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); 66 values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
66 } 67 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/most_visited_handler.cc ('k') | chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698