| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 DCHECK(NotificationType::PREF_CHANGED == type); | 63 DCHECK(NotificationType::PREF_CHANGED == type); |
| 64 std::wstring* pref_name = Details<std::wstring>(details).ptr(); | 64 std::wstring* pref_name = Details<std::wstring>(details).ptr(); |
| 65 DCHECK(*pref_name == prefs::kNTPShownSections); | 65 DCHECK(*pref_name == prefs::kNTPShownSections); |
| 66 | 66 |
| 67 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); | 67 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 68 FundamentalValue sections_value(sections); | 68 FundamentalValue sections_value(sections); |
| 69 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); | 69 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ShownSectionsHandler::HandleGetShownSections(const Value* value) { | 72 void ShownSectionsHandler::HandleGetShownSections(const Value* value) { |
| 73 SetFirstAppLauncherRunPref(pref_service_); | |
| 74 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); | 73 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 75 FundamentalValue sections_value(sections); | 74 FundamentalValue sections_value(sections); |
| 76 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); | 75 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); |
| 77 } | 76 } |
| 78 | 77 |
| 79 void ShownSectionsHandler::HandleSetShownSections(const Value* value) { | 78 void ShownSectionsHandler::HandleSetShownSections(const Value* value) { |
| 80 if (!value->IsType(Value::TYPE_LIST)) { | 79 if (!value->IsType(Value::TYPE_LIST)) { |
| 81 NOTREACHED(); | 80 NOTREACHED(); |
| 82 return; | 81 return; |
| 83 } | 82 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 96 int mode = StringToInt(mode_string); | 95 int mode = StringToInt(mode_string); |
| 97 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); | 96 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 98 | 97 |
| 99 if (old_mode != mode) { | 98 if (old_mode != mode) { |
| 100 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); | 99 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); |
| 101 pref_service_->SetInteger(prefs::kNTPShownSections, mode); | 100 pref_service_->SetInteger(prefs::kNTPShownSections, mode); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 // static | 104 // static |
| 106 void ShownSectionsHandler::SetFirstAppLauncherRunPref( | |
| 107 PrefService* pref_service) { | |
| 108 // If we have turned on Apps we want to hide most visited and recent to give | |
| 109 // more focus to the Apps section. We do not do this in MigrateUserPrefs | |
| 110 // because the pref version should not depend on command line switches. | |
| 111 if (Extension::AppsAreEnabled() && | |
| 112 !pref_service->GetBoolean(prefs::kNTPAppLauncherFirstRun)) { | |
| 113 int sections = pref_service->GetInteger(prefs::kNTPShownSections); | |
| 114 sections &= ~THUMB; | |
| 115 sections &= ~RECENT; | |
| 116 pref_service->SetInteger(prefs::kNTPShownSections, sections); | |
| 117 pref_service->SetBoolean(prefs::kNTPAppLauncherFirstRun, true); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 // static | |
| 122 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { | 105 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 123 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, | 106 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, |
| 124 THUMB | RECENT | TIPS | SYNC); | 107 THUMB | RECENT | TIPS | SYNC); |
| 125 if (Extension::AppsAreEnabled()) { | |
| 126 pref_service->RegisterBooleanPref(prefs::kNTPAppLauncherFirstRun, false); | |
| 127 } | |
| 128 } | 108 } |
| 129 | 109 |
| 130 // static | 110 // static |
| 131 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, | 111 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, |
| 132 int old_pref_version, | 112 int old_pref_version, |
| 133 int new_pref_version) { | 113 int new_pref_version) { |
| 134 bool changed = false; | 114 bool changed = false; |
| 135 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); | 115 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); |
| 136 | 116 |
| 137 if (old_pref_version < 1) { | 117 if (old_pref_version < 1) { |
| 138 // TIPS was used in early builds of the NNTP but since it was removed before | 118 // TIPS was used in early builds of the NNTP but since it was removed before |
| 139 // Chrome 3.0 we want to ensure that it is shown by default. | 119 // Chrome 3.0 we want to ensure that it is shown by default. |
| 140 shown_sections |= TIPS | SYNC; | 120 shown_sections |= TIPS | SYNC; |
| 141 changed = true; | 121 changed = true; |
| 142 } | 122 } |
| 143 | 123 |
| 144 if (old_pref_version < 2) { | 124 if (old_pref_version < 2) { |
| 145 // LIST is no longer used. Change to THUMB. | 125 // LIST is no longer used. Change to THUMB. |
| 146 shown_sections &= ~LIST; | 126 shown_sections &= ~LIST; |
| 147 shown_sections |= THUMB; | 127 shown_sections |= THUMB; |
| 148 changed = true; | 128 changed = true; |
| 149 } | 129 } |
| 150 | 130 |
| 151 if (changed) | 131 if (changed) |
| 152 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 132 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 153 } | 133 } |
| OLD | NEW |