| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/shown_sections_handler.h" | 5 #include "chrome/browser/dom_ui/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/metrics/user_metrics.h" | 13 #include "chrome/browser/metrics/user_metrics.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/notification_details.h" | 17 #include "chrome/common/notification_details.h" |
| 18 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Will cause an UMA notification if the mode of the new tab page | 23 // Will cause an UMA notification if the mode of the new tab page |
| 24 // was changed to hide/show the most visited thumbnails. | 24 // was changed to hide/show the most visited thumbnails. |
| 25 // TODO(aa): Needs to be updated to match newest NTP - http://crbug.com/57440 | 25 // 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) { | 26 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { |
| 27 // If the oldmode HAD either thumbs or lists visible. | 27 // If the oldmode HAD either thumbs or lists visible. |
| 28 bool old_had_it = (old_mode & THUMB) && !(old_mode & MINIMIZED_THUMB); | 28 bool old_had_it = (old_mode & THUMB) && !(old_mode & MENU_THUMB); |
| 29 bool new_has_it = (new_mode & THUMB) && !(new_mode & MINIMIZED_THUMB); | 29 bool new_has_it = (new_mode & THUMB) && !(new_mode & MENU_THUMB); |
| 30 | 30 |
| 31 if (old_had_it && !new_has_it) { | 31 if (old_had_it && !new_has_it) { |
| 32 UserMetrics::RecordAction( | 32 UserMetrics::RecordAction( |
| 33 UserMetricsAction("ShowSections_RecentSitesDisabled"), | 33 UserMetricsAction("ShowSections_RecentSitesDisabled"), |
| 34 profile); | 34 profile); |
| 35 } | 35 } |
| 36 | 36 |
| 37 if (new_has_it && !old_had_it) { | 37 if (new_has_it && !old_had_it) { |
| 38 UserMetrics::RecordAction( | 38 UserMetrics::RecordAction( |
| 39 UserMetricsAction("ShowSections_RecentSitesEnabled"), | 39 UserMetricsAction("ShowSections_RecentSitesEnabled"), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); | 99 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); |
| 100 pref_service_->SetInteger(prefs::kNTPShownSections, mode); | 100 pref_service_->SetInteger(prefs::kNTPShownSections, mode); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { | 105 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 106 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 107 // Default to have expanded APPS and all other secions are minimized. | 107 // Default to have expanded APPS and all other secions are minimized. |
| 108 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, | 108 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, |
| 109 APPS | MINIMIZED_THUMB | MINIMIZED_RECENT); | 109 APPS | MENU_THUMB | MENU_RECENT); |
| 110 #else | 110 #else |
| 111 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, THUMB); | 111 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, THUMB); |
| 112 #endif | 112 #endif |
| 113 } | 113 } |
| 114 | 114 |
| 115 // static | 115 // static |
| 116 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, | 116 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, |
| 117 int old_pref_version, | 117 int old_pref_version, |
| 118 int new_pref_version) { | 118 int new_pref_version) { |
| 119 // Nothing to migrate for default kNTPShownSections value. | 119 // Nothing to migrate for default kNTPShownSections value. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 140 if (changed) | 140 if (changed) |
| 141 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 141 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 142 } | 142 } |
| 143 | 143 |
| 144 // static | 144 // static |
| 145 void ShownSectionsHandler::OnExtensionInstalled(PrefService* prefs, | 145 void ShownSectionsHandler::OnExtensionInstalled(PrefService* prefs, |
| 146 const Extension* extension) { | 146 const Extension* extension) { |
| 147 if (extension->is_app()) { | 147 if (extension->is_app()) { |
| 148 int mode = prefs->GetInteger(prefs::kNTPShownSections); | 148 int mode = prefs->GetInteger(prefs::kNTPShownSections); |
| 149 | 149 |
| 150 // De-minimize the apps section. | 150 // De-menu-mode the apps section. |
| 151 mode &= ~MINIMIZED_APPS; | 151 mode &= ~MENU_APPS; |
| 152 | 152 |
| 153 // Hide any open sections. | 153 // Hide any open sections. |
| 154 mode &= ~ALL_SECTIONS_MASK; | 154 mode &= ~ALL_SECTIONS_MASK; |
| 155 | 155 |
| 156 // Show the apps section. | 156 // Show the apps section. |
| 157 mode |= APPS; | 157 mode |= APPS; |
| 158 | 158 |
| 159 prefs->SetInteger(prefs::kNTPShownSections, mode); | 159 prefs->SetInteger(prefs::kNTPShownSections, mode); |
| 160 } | 160 } |
| 161 } | 161 } |
| OLD | NEW |