| 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_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { | 46 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { |
| 47 return prefs->GetInteger(prefs::kNTPShownSections); | 47 return prefs->GetInteger(prefs::kNTPShownSections); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static |
| 51 void ShownSectionsHandler::SetShownSection(PrefService* prefs, |
| 52 Section section) { |
| 53 int shown_sections = GetShownSections(prefs); |
| 54 shown_sections &= ~ALL_SECTIONS_MASK; |
| 55 shown_sections |= section; |
| 56 prefs->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 57 } |
| 58 |
| 50 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) | 59 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) |
| 51 : pref_service_(pref_service) { | 60 : pref_service_(pref_service) { |
| 52 pref_registrar_.Init(pref_service); | 61 pref_registrar_.Init(pref_service); |
| 53 pref_registrar_.Add(prefs::kNTPShownSections, this); | 62 pref_registrar_.Add(prefs::kNTPShownSections, this); |
| 54 } | 63 } |
| 55 | 64 |
| 56 void ShownSectionsHandler::RegisterMessages() { | 65 void ShownSectionsHandler::RegisterMessages() { |
| 57 dom_ui_->RegisterMessageCallback("getShownSections", | 66 dom_ui_->RegisterMessageCallback("getShownSections", |
| 58 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); | 67 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); |
| 59 dom_ui_->RegisterMessageCallback("setShownSections", | 68 dom_ui_->RegisterMessageCallback("setShownSections", |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 151 |
| 143 // Hide any open sections. | 152 // Hide any open sections. |
| 144 mode &= ~ALL_SECTIONS_MASK; | 153 mode &= ~ALL_SECTIONS_MASK; |
| 145 | 154 |
| 146 // Show the apps section. | 155 // Show the apps section. |
| 147 mode |= APPS; | 156 mode |= APPS; |
| 148 | 157 |
| 149 prefs->SetInteger(prefs::kNTPShownSections, mode); | 158 prefs->SetInteger(prefs::kNTPShownSections, mode); |
| 150 } | 159 } |
| 151 } | 160 } |
| OLD | NEW |