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/shown_sections_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
19 #include "content/common/notification_details.h" | 20 #include "content/common/notification_details.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Will cause an UMA notification if the mode of the new tab page | 24 // Will cause an UMA notification if the mode of the new tab page |
24 // was changed to hide/show the most visited thumbnails. | 25 // was changed to hide/show the most visited thumbnails. |
25 // TODO(aa): Needs to be updated to match newest NTP - http://crbug.com/57440 | 26 // TODO(aa): Needs to be updated to match newest NTP - http://crbug.com/57440 |
26 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { | 27 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { |
27 // If the oldmode HAD either thumbs or lists visible. | 28 // If the oldmode HAD either thumbs or lists visible. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) { | 84 void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) { |
84 double mode_double; | 85 double mode_double; |
85 CHECK(args->GetDouble(0, &mode_double)); | 86 CHECK(args->GetDouble(0, &mode_double)); |
86 int mode = static_cast<int>(mode_double); | 87 int mode = static_cast<int>(mode_double); |
87 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); | 88 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); |
88 | 89 |
89 if (old_mode != mode) { | 90 if (old_mode != mode) { |
90 NotifySectionDisabled(mode, old_mode, web_ui_->GetProfile()); | 91 Profile* profile = |
| 92 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 93 NotifySectionDisabled(mode, old_mode, profile); |
91 pref_service_->SetInteger(prefs::kNTPShownSections, mode); | 94 pref_service_->SetInteger(prefs::kNTPShownSections, mode); |
92 } | 95 } |
93 } | 96 } |
94 | 97 |
95 // static | 98 // static |
96 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { | 99 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { |
97 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
98 // Default to have expanded APPS and all other sections are minimized. | 101 // Default to have expanded APPS and all other sections are minimized. |
99 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, | 102 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, |
100 APPS | MENU_THUMB | MENU_RECENT, | 103 APPS | MENU_THUMB | MENU_RECENT, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 149 |
147 // Hide any open sections. | 150 // Hide any open sections. |
148 mode &= ~ALL_SECTIONS_MASK; | 151 mode &= ~ALL_SECTIONS_MASK; |
149 | 152 |
150 // Show the apps section. | 153 // Show the apps section. |
151 mode |= APPS; | 154 mode |= APPS; |
152 | 155 |
153 prefs->SetInteger(prefs::kNTPShownSections, mode); | 156 prefs->SetInteger(prefs::kNTPShownSections, mode); |
154 } | 157 } |
155 } | 158 } |
OLD | NEW |