Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: chrome/browser/dom_ui/shown_sections_handler.cc

Issue 155579: Fix leak in ShownSectionsHandler::HandleGetShownSections and... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_favicon_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/string_util.h" 7 #include "base/string_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 11
12 void ShownSectionsHandler::RegisterMessages() { 12 void ShownSectionsHandler::RegisterMessages() {
13 dom_ui_->RegisterMessageCallback("getShownSections", 13 dom_ui_->RegisterMessageCallback("getShownSections",
14 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); 14 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections));
15 dom_ui_->RegisterMessageCallback("setShownSections", 15 dom_ui_->RegisterMessageCallback("setShownSections",
16 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); 16 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections));
17 } 17 }
18 18
19 void ShownSectionsHandler::HandleGetShownSections(const Value* value) { 19 void ShownSectionsHandler::HandleGetShownSections(const Value* value) {
20 const int mode = dom_ui_->GetProfile()->GetPrefs()-> 20 const int mode = dom_ui_->GetProfile()->GetPrefs()->
21 GetInteger(prefs::kNTPShownSections); 21 GetInteger(prefs::kNTPShownSections);
22 FundamentalValue* mode_value = new FundamentalValue(mode); 22 FundamentalValue mode_value(mode);
23 dom_ui_->CallJavascriptFunction(L"onShownSections", *mode_value); 23 dom_ui_->CallJavascriptFunction(L"onShownSections", mode_value);
24 } 24 }
25 25
26 void ShownSectionsHandler::HandleSetShownSections(const Value* value) { 26 void ShownSectionsHandler::HandleSetShownSections(const Value* value) {
27 if (!value->IsType(Value::TYPE_LIST)) { 27 if (!value->IsType(Value::TYPE_LIST)) {
28 NOTREACHED(); 28 NOTREACHED();
29 return; 29 return;
30 } 30 }
31 31
32 const ListValue* list = static_cast<const ListValue*>(value); 32 const ListValue* list = static_cast<const ListValue*>(value);
33 std::string mode_string; 33 std::string mode_string;
34 34
35 if (list->GetSize() < 1) { 35 if (list->GetSize() < 1) {
36 NOTREACHED() << "setShownSections called with too few arguments"; 36 NOTREACHED() << "setShownSections called with too few arguments";
37 return; 37 return;
38 } 38 }
39 39
40 bool r = list->GetString(0, &mode_string); 40 bool r = list->GetString(0, &mode_string);
41 DCHECK(r) << "Missing value in setShownSections from the NTP Most Visited."; 41 DCHECK(r) << "Missing value in setShownSections from the NTP Most Visited.";
42 42
43 dom_ui_->GetProfile()->GetPrefs()->SetInteger( 43 dom_ui_->GetProfile()->GetPrefs()->SetInteger(
44 prefs::kNTPShownSections, StringToInt(mode_string)); 44 prefs::kNTPShownSections, StringToInt(mode_string));
45 } 45 }
46 46
47 // static 47 // static
48 void ShownSectionsHandler::RegisterUserPrefs(PrefService* prefs) { 48 void ShownSectionsHandler::RegisterUserPrefs(PrefService* prefs) {
49 prefs->RegisterIntegerPref(prefs::kNTPShownSections, 49 prefs->RegisterIntegerPref(prefs::kNTPShownSections,
50 THUMB | RECENT | TIPS); 50 THUMB | RECENT | TIPS);
51 } 51 }
52 52
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_favicon_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698