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

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

Issue 7799008: Fix crash on NTP related to multi-profile extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/web_resource/promo_resource_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 // Tell the client whether to show the promo for this view. We don't do this 435 // Tell the client whether to show the promo for this view. We don't do this
436 // in the case of PREF_CHANGED because: 436 // in the case of PREF_CHANGED because:
437 // 437 //
438 // a) At that point in time, depending on the pref that changed, it can look 438 // a) At that point in time, depending on the pref that changed, it can look
439 // like the set of apps installed has changed, and we will mark the promo 439 // like the set of apps installed has changed, and we will mark the promo
440 // expired. 440 // expired.
441 // b) Conceptually, it doesn't really make sense to count a 441 // b) Conceptually, it doesn't really make sense to count a
442 // prefchange-triggered refresh as a promo 'view'. 442 // prefchange-triggered refresh as a promo 'view'.
443 AppsPromo* apps_promo = extension_service_->apps_promo(); 443 AppsPromo* apps_promo = extension_service_->apps_promo();
444 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 444 Profile* profile = Profile::FromWebUI(web_ui_);
445 PrefService* prefs = profile->GetPrefs();
445 bool apps_promo_just_expired = false; 446 bool apps_promo_just_expired = false;
446 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), 447 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(),
447 &apps_promo_just_expired)) { 448 &apps_promo_just_expired)) {
448 apps_promo->MaximizeAppsIfNecessary(); 449 apps_promo->MaximizeAppsIfNecessary();
449 dictionary.SetBoolean("showPromo", true); 450 dictionary.SetBoolean("showPromo", true);
450 FillPromoDictionary(&dictionary); 451 FillPromoDictionary(&dictionary);
451 promo_active_ = true; 452 promo_active_ = true;
452 } else { 453 } else {
453 dictionary.SetBoolean("showPromo", false); 454 dictionary.SetBoolean("showPromo", false);
454 promo_active_ = false; 455 promo_active_ = false;
455 } 456 }
456 457
457 // If the default apps have just expired (user viewed them too many times with 458 // If the default apps have just expired (user viewed them too many times with
458 // no interaction), then we uninstall them and focus the recent sites section. 459 // no interaction), then we uninstall them and focus the recent sites section.
459 if (apps_promo_just_expired) { 460 if (apps_promo_just_expired) {
460 ignore_changes_ = true; 461 ignore_changes_ = true;
461 UninstallDefaultApps(); 462 UninstallDefaultApps();
462 ignore_changes_ = false; 463 ignore_changes_ = false;
463 ShownSectionsHandler::SetShownSection(prefs, THUMB); 464 ShownSectionsHandler::SetShownSection(prefs, THUMB);
464 } 465 }
465 466
466 FillAppDictionary(&dictionary); 467 FillAppDictionary(&dictionary);
467 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); 468 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary);
468 469
469 // First time we get here we set up the observer so that we can tell update 470 // First time we get here we set up the observer so that we can tell update
470 // the apps as they change. 471 // the apps as they change.
471 if (registrar_.IsEmpty()) { 472 if (registrar_.IsEmpty()) {
472 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, 473 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
Yoyo Zhou 2011/08/29 22:40:46 This looks like it could possibly be sent from an
jstritar 2011/08/30 15:06:31 Done.
473 NotificationService::AllSources()); 474 Source<Profile>(profile));
474 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 475 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
475 NotificationService::AllSources()); 476 Source<Profile>(profile));
476 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 477 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
477 NotificationService::AllSources()); 478 Source<Profile>(profile));
478 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, 479 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
479 NotificationService::AllSources()); 480 Source<ExtensionPrefs>(extension_service_->extension_prefs()));
480 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, 481 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED,
481 NotificationService::AllSources()); 482 Source<Profile>(profile));
482 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 483 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
483 NotificationService::AllSources()); 484 Source<Profile>(profile));
484 } 485 }
485 if (pref_change_registrar_.IsEmpty()) { 486 if (pref_change_registrar_.IsEmpty()) {
486 pref_change_registrar_.Init( 487 pref_change_registrar_.Init(
487 extension_service_->extension_prefs()->pref_service()); 488 extension_service_->extension_prefs()->pref_service());
488 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); 489 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this);
489 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); 490 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this);
490 } 491 }
491 } 492 }
492 493
493 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { 494 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 954
954 void AppLauncherHandler::UninstallDefaultApps() { 955 void AppLauncherHandler::UninstallDefaultApps() {
955 AppsPromo* apps_promo = extension_service_->apps_promo(); 956 AppsPromo* apps_promo = extension_service_->apps_promo();
956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 957 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 958 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
958 iter != app_ids.end(); ++iter) { 959 iter != app_ids.end(); ++iter) {
959 if (extension_service_->GetExtensionById(*iter, true)) 960 if (extension_service_->GetExtensionById(*iter, true))
960 extension_service_->UninstallExtension(*iter, false, NULL); 961 extension_service_->UninstallExtension(*iter, false, NULL);
961 } 962 }
962 } 963 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/web_resource/promo_resource_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698