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

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

Issue 2812953002: Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: Rebased Created 3 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/app_launcher_handler.h" 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
jdoerrie 2017/04/13 09:08:52 #include <utility>
vabr (Chromium) 2017/04/13 12:03:14 Done.
10 10
11 #include "apps/metrics_names.h" 11 #include "apps/metrics_names.h"
12 #include "base/auto_reset.h" 12 #include "base/auto_reset.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/extensions/crx_installer.h" 25 #include "chrome/browser/extensions/crx_installer.h"
25 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/extensions/extension_ui_util.h" 27 #include "chrome/browser/extensions/extension_ui_util.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 content::BrowserContext* browser_context, 353 content::BrowserContext* browser_context,
353 const Extension* extension, 354 const Extension* extension,
354 extensions::UninstallReason reason) { 355 extensions::UninstallReason reason) {
355 AppRemoved(extension, true); 356 AppRemoved(extension, true);
356 } 357 }
357 358
358 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { 359 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) {
359 // CreateAppInfo and ClearOrdinals can change the extension prefs. 360 // CreateAppInfo and ClearOrdinals can change the extension prefs.
360 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 361 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
361 362
362 base::ListValue* list = new base::ListValue(); 363 auto installed_extensions = base::MakeUnique<base::ListValue>();
363 Profile* profile = Profile::FromWebUI(web_ui()); 364 Profile* profile = Profile::FromWebUI(web_ui());
364 PrefService* prefs = profile->GetPrefs(); 365 PrefService* prefs = profile->GetPrefs();
365 366
366 for (std::set<std::string>::iterator it = visible_apps_.begin(); 367 for (std::set<std::string>::iterator it = visible_apps_.begin();
367 it != visible_apps_.end(); ++it) { 368 it != visible_apps_.end(); ++it) {
368 const Extension* extension = extension_service_->GetInstalledExtension(*it); 369 const Extension* extension = extension_service_->GetInstalledExtension(*it);
369 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage( 370 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage(
370 extension, profile)) { 371 extension, profile)) {
371 list->Append(GetAppInfo(extension)); 372 installed_extensions->Append(GetAppInfo(extension));
372 } 373 }
373 } 374 }
374 375
375 dictionary->Set("apps", list); 376 dictionary->Set("apps", std::move(installed_extensions));
376 377
377 const base::ListValue* app_page_names = 378 const base::ListValue* app_page_names =
378 prefs->GetList(prefs::kNtpAppPageNames); 379 prefs->GetList(prefs::kNtpAppPageNames);
379 if (!app_page_names || !app_page_names->GetSize()) { 380 if (!app_page_names || !app_page_names->GetSize()) {
380 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 381 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
381 base::ListValue* list = update.Get(); 382 base::ListValue* list = update.Get();
382 list->Set(0, new base::Value( 383 list->Set(0, base::MakeUnique<base::Value>(
383 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); 384 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)));
jdoerrie 2017/04/13 09:08:52 SetString
vabr (Chromium) 2017/04/13 12:03:14 There is no SetString in ListValue.
384 dictionary->Set("appPageNames", 385 dictionary->Set("appPageNames", base::MakeUnique<base::Value>(*list));
385 static_cast<base::ListValue*>(list->DeepCopy()));
386 } else { 386 } else {
387 dictionary->Set("appPageNames", 387 dictionary->Set("appPageNames",
388 static_cast<base::ListValue*>(app_page_names->DeepCopy())); 388 base::MakeUnique<base::Value>(*app_page_names));
389 } 389 }
390 } 390 }
391 391
392 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo( 392 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo(
393 const Extension* extension) { 393 const Extension* extension) {
394 std::unique_ptr<base::DictionaryValue> app_info(new base::DictionaryValue()); 394 std::unique_ptr<base::DictionaryValue> app_info(new base::DictionaryValue());
395 // CreateAppInfo can change the extension prefs. 395 // CreateAppInfo can change the extension prefs.
396 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 396 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
397 CreateAppInfo(extension, extension_service_, app_info.get()); 397 CreateAppInfo(extension, extension_service_, app_info.get());
398 return app_info; 398 return app_info;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 base::string16 name; 684 base::string16 name;
685 CHECK(args->GetString(0, &name)); 685 CHECK(args->GetString(0, &name));
686 686
687 double page_index; 687 double page_index;
688 CHECK(args->GetDouble(1, &page_index)); 688 CHECK(args->GetDouble(1, &page_index));
689 689
690 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 690 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
691 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 691 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
692 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 692 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
693 base::ListValue* list = update.Get(); 693 base::ListValue* list = update.Get();
694 list->Set(static_cast<size_t>(page_index), new base::Value(name)); 694 list->Set(static_cast<size_t>(page_index),
695 base::MakeUnique<base::Value>(name));
jdoerrie 2017/04/13 09:08:52 SetString
vabr (Chromium) 2017/04/13 12:03:14 There is no SetString in ListValue. But I at least
jdoerrie 2017/04/13 12:09:41 True, my bad. I saw 'Set' and immediately assumed
695 } 696 }
696 697
697 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) { 698 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) {
698 std::string url; 699 std::string url;
699 CHECK(args->GetString(0, &url)); 700 CHECK(args->GetString(0, &url));
700 GURL launch_url(url); 701 GURL launch_url(url);
701 702
702 base::string16 title; 703 base::string16 title;
703 CHECK(args->GetString(1, &title)); 704 CHECK(args->GetString(1, &title));
704 705
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 base::Value(!extension_id_prompting_.empty())); 881 base::Value(!extension_id_prompting_.empty()));
881 } 882 }
882 883
883 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { 884 bool AppLauncherHandler::ShouldShow(const Extension* extension) const {
884 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) 885 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app())
885 return false; 886 return false;
886 887
887 Profile* profile = Profile::FromWebUI(web_ui()); 888 Profile* profile = Profile::FromWebUI(web_ui());
888 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); 889 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile);
889 } 890 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698