| 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/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "content/browser/user_metrics.h" | 18 #include "content/browser/user_metrics.h" |
| 18 #include "content/common/notification_details.h" | 19 #include "content/common/notification_details.h" |
| 19 #include "content/common/notification_type.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 & MENU_THUMB); | 28 bool old_had_it = (old_mode & THUMB) && !(old_mode & MENU_THUMB); |
| 29 bool new_has_it = (new_mode & THUMB) && !(new_mode & MENU_THUMB); | 29 bool new_has_it = (new_mode & THUMB) && !(new_mode & MENU_THUMB); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 pref_registrar_.Add(prefs::kNTPShownSections, this); | 61 pref_registrar_.Add(prefs::kNTPShownSections, this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ShownSectionsHandler::RegisterMessages() { | 64 void ShownSectionsHandler::RegisterMessages() { |
| 65 web_ui_->RegisterMessageCallback("getShownSections", | 65 web_ui_->RegisterMessageCallback("getShownSections", |
| 66 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); | 66 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); |
| 67 web_ui_->RegisterMessageCallback("setShownSections", | 67 web_ui_->RegisterMessageCallback("setShownSections", |
| 68 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); | 68 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ShownSectionsHandler::Observe(NotificationType type, | 71 void ShownSectionsHandler::Observe(int type, |
| 72 const NotificationSource& source, | 72 const NotificationSource& source, |
| 73 const NotificationDetails& details) { | 73 const NotificationDetails& details) { |
| 74 if (type == NotificationType::PREF_CHANGED) { | 74 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 75 std::string* pref_name = Details<std::string>(details).ptr(); | 75 std::string* pref_name = Details<std::string>(details).ptr(); |
| 76 DCHECK(*pref_name == prefs::kNTPShownSections); | 76 DCHECK(*pref_name == prefs::kNTPShownSections); |
| 77 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); | 77 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 78 FundamentalValue sections_value(sections); | 78 FundamentalValue sections_value(sections); |
| 79 web_ui_->CallJavascriptFunction("setShownSections", sections_value); | 79 web_ui_->CallJavascriptFunction("setShownSections", sections_value); |
| 80 } else { | 80 } else { |
| 81 NOTREACHED(); | 81 NOTREACHED(); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // Hide any open sections. | 155 // Hide any open sections. |
| 156 mode &= ~ALL_SECTIONS_MASK; | 156 mode &= ~ALL_SECTIONS_MASK; |
| 157 | 157 |
| 158 // Show the apps section. | 158 // Show the apps section. |
| 159 mode |= APPS; | 159 mode |= APPS; |
| 160 | 160 |
| 161 prefs->SetInteger(prefs::kNTPShownSections, mode); | 161 prefs->SetInteger(prefs::kNTPShownSections, mode); |
| 162 } | 162 } |
| 163 } | 163 } |
| OLD | NEW |