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

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

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