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

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

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Profile helper function, rebase Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // a desktop. 363 // a desktop.
364 dictionary->SetBoolean("disableCreateAppShortcut", true); 364 dictionary->SetBoolean("disableCreateAppShortcut", true);
365 #endif 365 #endif
366 366
367 dictionary->SetBoolean( 367 dictionary->SetBoolean(
368 "showLauncher", 368 "showLauncher",
369 extension_service_->apps_promo()->ShouldShowAppLauncher( 369 extension_service_->apps_promo()->ShouldShowAppLauncher(
370 extension_service_->GetAppIds())); 370 extension_service_->GetAppIds()));
371 371
372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { 372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) {
373 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 373 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
374 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); 374 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames);
375 if (app_page_names && app_page_names->GetSize()) { 375 if (app_page_names && app_page_names->GetSize()) {
376 dictionary->Set("appPageNames", 376 dictionary->Set("appPageNames",
377 static_cast<ListValue*>(app_page_names->DeepCopy())); 377 static_cast<ListValue*>(app_page_names->DeepCopy()));
378 } 378 }
379 } 379 }
380 } 380 }
381 381
382 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { 382 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) {
383 AppNotificationManager* notification_manager = 383 AppNotificationManager* notification_manager =
(...skipping 19 matching lines...) Expand all
403 403
404 // Tell the client whether to show the promo for this view. We don't do this 404 // Tell the client whether to show the promo for this view. We don't do this
405 // in the case of PREF_CHANGED because: 405 // in the case of PREF_CHANGED because:
406 // 406 //
407 // a) At that point in time, depending on the pref that changed, it can look 407 // a) At that point in time, depending on the pref that changed, it can look
408 // like the set of apps installed has changed, and we will mark the promo 408 // like the set of apps installed has changed, and we will mark the promo
409 // expired. 409 // expired.
410 // b) Conceptually, it doesn't really make sense to count a 410 // b) Conceptually, it doesn't really make sense to count a
411 // prefchange-triggered refresh as a promo 'view'. 411 // prefchange-triggered refresh as a promo 'view'.
412 AppsPromo* apps_promo = extension_service_->apps_promo(); 412 AppsPromo* apps_promo = extension_service_->apps_promo();
413 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 413 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
414 bool apps_promo_just_expired = false; 414 bool apps_promo_just_expired = false;
415 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), 415 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(),
416 &apps_promo_just_expired)) { 416 &apps_promo_just_expired)) {
417 apps_promo->MaximizeAppsIfNecessary(); 417 apps_promo->MaximizeAppsIfNecessary();
418 dictionary.SetBoolean("showPromo", true); 418 dictionary.SetBoolean("showPromo", true);
419 FillPromoDictionary(&dictionary); 419 FillPromoDictionary(&dictionary);
420 promo_active_ = true; 420 promo_active_ = true;
421 } else { 421 } else {
422 dictionary.SetBoolean("showPromo", false); 422 dictionary.SetBoolean("showPromo", false);
423 promo_active_ = false; 423 promo_active_ = false;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 675 }
676 676
677 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { 677 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
678 string16 name; 678 string16 name;
679 CHECK(args->GetString(0, &name)); 679 CHECK(args->GetString(0, &name));
680 680
681 double page_index; 681 double page_index;
682 CHECK(args->GetDouble(1, &page_index)); 682 CHECK(args->GetDouble(1, &page_index));
683 683
684 AutoReset<bool> auto_reset(&ignore_changes_, true); 684 AutoReset<bool> auto_reset(&ignore_changes_, true);
685 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 685 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
686 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); 686 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames);
687 ListValue* list = update.Get(); 687 ListValue* list = update.Get();
688 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); 688 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name));
689 } 689 }
690 690
691 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { 691 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) {
692 std::string url; 692 std::string url;
693 CHECK(args->GetString(0, &url)); 693 CHECK(args->GetString(0, &url));
694 694
695 string16 title; 695 string16 title;
696 CHECK(args->GetString(1, &title)); 696 CHECK(args->GetString(1, &title));
697 697
698 GURL launch_url(url); 698 GURL launch_url(url);
699 699
700 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo); 700 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo);
701 web_app->is_bookmark_app = true; 701 web_app->is_bookmark_app = true;
702 web_app->title = title; 702 web_app->title = title;
703 web_app->app_url = launch_url; 703 web_app->app_url = launch_url;
704 704
705 Profile* profile = web_ui_->GetProfile(); 705 Profile* profile = Profile::FromWebUI(web_ui_);
706 FaviconService* favicon_service = 706 FaviconService* favicon_service =
707 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); 707 profile->GetFaviconService(Profile::EXPLICIT_ACCESS);
708 if (!favicon_service) { 708 if (!favicon_service) {
709 LOG(ERROR) << "No favicon service"; 709 LOG(ERROR) << "No favicon service";
710 scoped_refptr<CrxInstaller> installer( 710 scoped_refptr<CrxInstaller> installer(
711 extension_service_->MakeCrxInstaller(NULL)); 711 extension_service_->MakeCrxInstaller(NULL));
712 installer->InstallWebApp(*web_app); 712 installer->InstallWebApp(*web_app);
713 return; 713 return;
714 } 714 }
715 715
716 FaviconService::Handle h = favicon_service->GetFaviconForURL( 716 FaviconService::Handle h = favicon_service->GetFaviconForURL(
717 launch_url, history::FAVICON, &favicon_consumer_, 717 launch_url, history::FAVICON, &favicon_consumer_,
718 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); 718 NewCallback(this, &AppLauncherHandler::OnFaviconForApp));
719 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); 719 favicon_consumer_.SetClientData(favicon_service, h, web_app.release());
720 } 720 }
721 721
722 void AppLauncherHandler::HandleRecordAppLaunchByURL( 722 void AppLauncherHandler::HandleRecordAppLaunchByURL(
723 const base::ListValue* args) { 723 const base::ListValue* args) {
724 std::string url; 724 std::string url;
725 CHECK(args->GetString(0, &url)); 725 CHECK(args->GetString(0, &url));
726 double source; 726 double source;
727 CHECK(args->GetDouble(1, &source)); 727 CHECK(args->GetDouble(1, &source));
728 728
729 extension_misc::AppLaunchBucket bucket = 729 extension_misc::AppLaunchBucket bucket =
730 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); 730 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source));
731 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 731 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
732 732
733 RecordAppLaunchByURL(web_ui_->GetProfile(), url, bucket); 733 RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket);
734 } 734 }
735 735
736 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, 736 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle,
737 history::FaviconData data) { 737 history::FaviconData data) {
738 scoped_ptr<WebApplicationInfo> web_app( 738 scoped_ptr<WebApplicationInfo> web_app(
739 favicon_consumer_.GetClientDataForCurrentRequest()); 739 favicon_consumer_.GetClientDataForCurrentRequest());
740 WebApplicationInfo::IconInfo icon; 740 WebApplicationInfo::IconInfo icon;
741 web_app->icons.push_back(icon); 741 web_app->icons.push_back(icon);
742 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), 742 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(),
743 data.image_data->size(), 743 data.image_data->size(),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 "Extensions.Permissions_ReEnableAbort"; 890 "Extensions.Permissions_ReEnableAbort";
891 ExtensionService::RecordPermissionMessagesHistogram( 891 ExtensionService::RecordPermissionMessagesHistogram(
892 extension, histogram_name.c_str()); 892 extension, histogram_name.c_str());
893 893
894 ExtensionDialogCanceled(); 894 ExtensionDialogCanceled();
895 } 895 }
896 896
897 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { 897 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() {
898 if (!extension_uninstall_dialog_.get()) { 898 if (!extension_uninstall_dialog_.get()) {
899 extension_uninstall_dialog_.reset( 899 extension_uninstall_dialog_.reset(
900 new ExtensionUninstallDialog(web_ui_->GetProfile())); 900 new ExtensionUninstallDialog(Profile::FromWebUI(web_ui_)));
901 } 901 }
902 return extension_uninstall_dialog_.get(); 902 return extension_uninstall_dialog_.get();
903 } 903 }
904 904
905 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { 905 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() {
906 if (!extension_install_ui_.get()) { 906 if (!extension_install_ui_.get()) {
907 extension_install_ui_.reset( 907 extension_install_ui_.reset(
908 new ExtensionInstallUI(web_ui_->GetProfile())); 908 new ExtensionInstallUI(Profile::FromWebUI(web_ui_)));
909 } 909 }
910 return extension_install_ui_.get(); 910 return extension_install_ui_.get();
911 } 911 }
912 912
913 void AppLauncherHandler::UninstallDefaultApps() { 913 void AppLauncherHandler::UninstallDefaultApps() {
914 AppsPromo* apps_promo = extension_service_->apps_promo(); 914 AppsPromo* apps_promo = extension_service_->apps_promo();
915 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 915 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
916 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 916 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
917 iter != app_ids.end(); ++iter) { 917 iter != app_ids.end(); ++iter) {
918 if (extension_service_->GetExtensionById(*iter, true)) 918 if (extension_service_->GetExtensionById(*iter, true))
919 extension_service_->UninstallExtension(*iter, false, NULL); 919 extension_service_->UninstallExtension(*iter, false, NULL);
920 } 920 }
921 } 921 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/net_internals_ui.cc ('k') | chrome/browser/ui/webui/ntp/favicon_webui_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698