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

Side by Side Diff: chrome/browser/ui/webui/plural_string_handler.cc

Issue 2898303004: [MD Bookmarks] Add toasts. (Closed)
Patch Set: fix nits Created 3 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/plural_string_handler.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/values.h"
10 #include "content/public/browser/web_ui.h"
11 #include "ui/base/l10n/l10n_util.h"
12
13 PluralStringHandler::PluralStringHandler() {}
14
15 PluralStringHandler::~PluralStringHandler() {}
16
17 void PluralStringHandler::RegisterMessages() {
18 web_ui()->RegisterMessageCallback(
19 "getPluralString", base::Bind(&PluralStringHandler::HandleGetPluralString,
20 base::Unretained(this)));
21 }
22
23 void PluralStringHandler::AddLocalizedString(const std::string& name, int id) {
24 name_to_id_[name] = id;
25 }
26
27 void PluralStringHandler::HandleGetPluralString(const base::ListValue* args) {
28 AllowJavascript();
29 CHECK_EQ(3U, args->GetSize());
30 const base::Value* callback_id;
31 CHECK(args->Get(0, &callback_id));
32
33 std::string message_name;
34 CHECK(args->GetString(1, &message_name));
35
36 int count;
37 CHECK(args->GetInteger(2, &count));
38
39 auto message_id_it = name_to_id_.find(message_name);
40 CHECK(name_to_id_.end() != message_id_it);
41
42 ResolveJavascriptCallback(*callback_id,
43 base::Value(l10n_util::GetPluralStringFUTF8(
44 message_id_it->second, count)));
45 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/plural_string_handler.h ('k') | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698