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

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: No ListValue::SetDouble 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 <string>
10 #include <utility>
9 #include <vector> 11 #include <vector>
10 12
11 #include "apps/metrics_names.h" 13 #include "apps/metrics_names.h"
12 #include "base/auto_reset.h" 14 #include "base/auto_reset.h"
13 #include "base/bind.h" 15 #include "base/bind.h"
14 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
15 #include "base/command_line.h" 17 #include "base/command_line.h"
16 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
19 #include "base/memory/ptr_util.h"
17 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
19 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 24 #include "base/values.h"
22 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/extensions/crx_installer.h" 27 #include "chrome/browser/extensions/crx_installer.h"
25 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/extensions/extension_ui_util.h" 29 #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, 355 content::BrowserContext* browser_context,
353 const Extension* extension, 356 const Extension* extension,
354 extensions::UninstallReason reason) { 357 extensions::UninstallReason reason) {
355 AppRemoved(extension, true); 358 AppRemoved(extension, true);
356 } 359 }
357 360
358 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { 361 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) {
359 // CreateAppInfo and ClearOrdinals can change the extension prefs. 362 // CreateAppInfo and ClearOrdinals can change the extension prefs.
360 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 363 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
361 364
362 base::ListValue* list = new base::ListValue(); 365 auto installed_extensions = base::MakeUnique<base::ListValue>();
363 Profile* profile = Profile::FromWebUI(web_ui()); 366 Profile* profile = Profile::FromWebUI(web_ui());
364 PrefService* prefs = profile->GetPrefs(); 367 PrefService* prefs = profile->GetPrefs();
365 368
366 for (std::set<std::string>::iterator it = visible_apps_.begin(); 369 for (std::set<std::string>::iterator it = visible_apps_.begin();
367 it != visible_apps_.end(); ++it) { 370 it != visible_apps_.end(); ++it) {
368 const Extension* extension = extension_service_->GetInstalledExtension(*it); 371 const Extension* extension = extension_service_->GetInstalledExtension(*it);
369 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage( 372 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage(
370 extension, profile)) { 373 extension, profile)) {
371 list->Append(GetAppInfo(extension)); 374 installed_extensions->Append(GetAppInfo(extension));
372 } 375 }
373 } 376 }
374 377
375 dictionary->Set("apps", list); 378 dictionary->Set("apps", std::move(installed_extensions));
376 379
377 const base::ListValue* app_page_names = 380 const base::ListValue* app_page_names =
378 prefs->GetList(prefs::kNtpAppPageNames); 381 prefs->GetList(prefs::kNtpAppPageNames);
379 if (!app_page_names || !app_page_names->GetSize()) { 382 if (!app_page_names || !app_page_names->GetSize()) {
380 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 383 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
381 base::ListValue* list = update.Get(); 384 base::ListValue* list = update.Get();
382 list->Set(0, new base::Value( 385 list->Set(0, base::MakeUnique<base::Value>(
383 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); 386 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)));
384 dictionary->Set("appPageNames", 387 dictionary->Set("appPageNames", base::MakeUnique<base::Value>(*list));
385 static_cast<base::ListValue*>(list->DeepCopy()));
386 } else { 388 } else {
387 dictionary->Set("appPageNames", 389 dictionary->Set("appPageNames",
388 static_cast<base::ListValue*>(app_page_names->DeepCopy())); 390 base::MakeUnique<base::Value>(*app_page_names));
389 } 391 }
390 } 392 }
391 393
392 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo( 394 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo(
393 const Extension* extension) { 395 const Extension* extension) {
394 std::unique_ptr<base::DictionaryValue> app_info(new base::DictionaryValue()); 396 std::unique_ptr<base::DictionaryValue> app_info(new base::DictionaryValue());
395 // CreateAppInfo can change the extension prefs. 397 // CreateAppInfo can change the extension prefs.
396 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 398 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
397 CreateAppInfo(extension, extension_service_, app_info.get()); 399 CreateAppInfo(extension, extension_service_, app_info.get());
398 return app_info; 400 return app_info;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 CHECK(args->GetDouble(1, &page_index)); 676 CHECK(args->GetDouble(1, &page_index));
675 const syncer::StringOrdinal& page_ordinal = 677 const syncer::StringOrdinal& page_ordinal =
676 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); 678 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index));
677 679
678 // Don't update the page; it already knows the apps have been reordered. 680 // Don't update the page; it already knows the apps have been reordered.
679 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 681 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
680 app_sorting->SetPageOrdinal(extension_id, page_ordinal); 682 app_sorting->SetPageOrdinal(extension_id, page_ordinal);
681 } 683 }
682 684
683 void AppLauncherHandler::HandleSaveAppPageName(const base::ListValue* args) { 685 void AppLauncherHandler::HandleSaveAppPageName(const base::ListValue* args) {
684 base::string16 name; 686 std::string name;
685 CHECK(args->GetString(0, &name)); 687 CHECK(args->GetString(0, &name));
686 688
687 double page_index; 689 double page_index;
688 CHECK(args->GetDouble(1, &page_index)); 690 CHECK(args->GetDouble(1, &page_index));
689 691
690 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 692 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
691 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 693 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
692 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 694 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
693 base::ListValue* list = update.Get(); 695 base::ListValue* list = update.Get();
694 list->Set(static_cast<size_t>(page_index), new base::Value(name)); 696 list->Set(static_cast<size_t>(page_index),
697 base::MakeUnique<base::Value>(name));
695 } 698 }
696 699
697 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) { 700 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) {
698 std::string url; 701 std::string url;
699 CHECK(args->GetString(0, &url)); 702 CHECK(args->GetString(0, &url));
700 GURL launch_url(url); 703 GURL launch_url(url);
701 704
702 base::string16 title; 705 base::string16 title;
703 CHECK(args->GetString(1, &title)); 706 CHECK(args->GetString(1, &title));
704 707
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 base::Value(!extension_id_prompting_.empty())); 883 base::Value(!extension_id_prompting_.empty()));
881 } 884 }
882 885
883 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { 886 bool AppLauncherHandler::ShouldShow(const Extension* extension) const {
884 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) 887 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app())
885 return false; 888 return false;
886 889
887 Profile* profile = Profile::FromWebUI(web_ui()); 890 Profile* profile = Profile::FromWebUI(web_ui());
888 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); 891 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile);
889 } 892 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/nacl_ui.cc ('k') | chrome/browser/ui/webui/options/autofill_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698