| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { | 45 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { |
| 46 return prefs->GetInteger(prefs::kNTPShownSections); | 46 return prefs->GetInteger(prefs::kNTPShownSections); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) | 49 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) |
| 50 : pref_service_(pref_service) { | 50 : pref_service_(pref_service) { |
| 51 pref_service_->AddPrefObserver(prefs::kNTPShownSections, this); | 51 registrar_.Init(pref_service); |
| 52 } | 52 registrar_.Add(prefs::kNTPShownSections, this); |
| 53 | |
| 54 ShownSectionsHandler::~ShownSectionsHandler() { | |
| 55 pref_service_->RemovePrefObserver(prefs::kNTPShownSections, this); | |
| 56 } | 53 } |
| 57 | 54 |
| 58 void ShownSectionsHandler::RegisterMessages() { | 55 void ShownSectionsHandler::RegisterMessages() { |
| 59 dom_ui_->RegisterMessageCallback("getShownSections", | 56 dom_ui_->RegisterMessageCallback("getShownSections", |
| 60 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); | 57 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); |
| 61 dom_ui_->RegisterMessageCallback("setShownSections", | 58 dom_ui_->RegisterMessageCallback("setShownSections", |
| 62 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); | 59 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); |
| 63 } | 60 } |
| 64 | 61 |
| 65 void ShownSectionsHandler::Observe(NotificationType type, | 62 void ShownSectionsHandler::Observe(NotificationType type, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 shown_sections = APPS; | 108 shown_sections = APPS; |
| 112 else | 109 else |
| 113 shown_sections = THUMB; | 110 shown_sections = THUMB; |
| 114 | 111 |
| 115 changed = true; | 112 changed = true; |
| 116 } | 113 } |
| 117 | 114 |
| 118 if (changed) | 115 if (changed) |
| 119 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 116 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 120 } | 117 } |
| OLD | NEW |