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

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: fix sources for incognito 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
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 252 }
253 253
254 void AppLauncherHandler::Observe(int type, 254 void AppLauncherHandler::Observe(int type,
255 const NotificationSource& source, 255 const NotificationSource& source,
256 const NotificationDetails& details) { 256 const NotificationDetails& details) {
257 if (ignore_changes_) 257 if (ignore_changes_)
258 return; 258 return;
259 259
260 switch (type) { 260 switch (type) {
261 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { 261 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: {
262 Profile* profile = Source<Profile>(source).ptr();
263 if (!Profile::FromWebUI(web_ui_)->IsSameProfile(profile))
264 return;
265
262 const std::string& id = *Details<const std::string>(details).ptr(); 266 const std::string& id = *Details<const std::string>(details).ptr();
263 const AppNotification* notification = 267 const AppNotification* notification =
264 extension_service_->app_notification_manager()->GetLast(id); 268 extension_service_->app_notification_manager()->GetLast(id);
265 ListValue args; 269 ListValue args;
266 args.Append(new StringValue(id)); 270 args.Append(new StringValue(id));
267 if (notification) 271 if (notification)
268 args.Append(SerializeNotification(*notification)); 272 args.Append(SerializeNotification(*notification));
269 web_ui_->CallJavascriptFunction("appNotificationChanged", args); 273 web_ui_->CallJavascriptFunction("appNotificationChanged", args);
270 break; 274 break;
271 } 275 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 438
435 // Tell the client whether to show the promo for this view. We don't do this 439 // Tell the client whether to show the promo for this view. We don't do this
436 // in the case of PREF_CHANGED because: 440 // in the case of PREF_CHANGED because:
437 // 441 //
438 // a) At that point in time, depending on the pref that changed, it can look 442 // 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 443 // like the set of apps installed has changed, and we will mark the promo
440 // expired. 444 // expired.
441 // b) Conceptually, it doesn't really make sense to count a 445 // b) Conceptually, it doesn't really make sense to count a
442 // prefchange-triggered refresh as a promo 'view'. 446 // prefchange-triggered refresh as a promo 'view'.
443 AppsPromo* apps_promo = extension_service_->apps_promo(); 447 AppsPromo* apps_promo = extension_service_->apps_promo();
444 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 448 Profile* profile = Profile::FromWebUI(web_ui_);
449 PrefService* prefs = profile->GetPrefs();
445 bool apps_promo_just_expired = false; 450 bool apps_promo_just_expired = false;
446 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), 451 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(),
447 &apps_promo_just_expired)) { 452 &apps_promo_just_expired)) {
448 apps_promo->MaximizeAppsIfNecessary(); 453 apps_promo->MaximizeAppsIfNecessary();
449 dictionary.SetBoolean("showPromo", true); 454 dictionary.SetBoolean("showPromo", true);
450 FillPromoDictionary(&dictionary); 455 FillPromoDictionary(&dictionary);
451 promo_active_ = true; 456 promo_active_ = true;
452 } else { 457 } else {
453 dictionary.SetBoolean("showPromo", false); 458 dictionary.SetBoolean("showPromo", false);
454 promo_active_ = false; 459 promo_active_ = false;
(...skipping 10 matching lines...) Expand all
465 470
466 FillAppDictionary(&dictionary); 471 FillAppDictionary(&dictionary);
467 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); 472 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary);
468 473
469 // First time we get here we set up the observer so that we can tell update 474 // First time we get here we set up the observer so that we can tell update
470 // the apps as they change. 475 // the apps as they change.
471 if (registrar_.IsEmpty()) { 476 if (registrar_.IsEmpty()) {
472 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, 477 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
473 NotificationService::AllSources()); 478 NotificationService::AllSources());
474 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 479 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
475 NotificationService::AllSources()); 480 Source<Profile>(profile));
476 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 481 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
477 NotificationService::AllSources()); 482 Source<Profile>(profile));
478 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, 483 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
479 NotificationService::AllSources()); 484 Source<ExtensionPrefs>(extension_service_->extension_prefs()));
480 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, 485 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED,
481 NotificationService::AllSources()); 486 Source<Profile>(profile));
482 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 487 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
483 NotificationService::AllSources()); 488 Source<Profile>(profile));
484 } 489 }
485 if (pref_change_registrar_.IsEmpty()) { 490 if (pref_change_registrar_.IsEmpty()) {
486 pref_change_registrar_.Init( 491 pref_change_registrar_.Init(
487 extension_service_->extension_prefs()->pref_service()); 492 extension_service_->extension_prefs()->pref_service());
488 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); 493 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this);
489 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); 494 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this);
490 } 495 }
491 } 496 }
492 497
493 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { 498 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 958
954 void AppLauncherHandler::UninstallDefaultApps() { 959 void AppLauncherHandler::UninstallDefaultApps() {
955 AppsPromo* apps_promo = extension_service_->apps_promo(); 960 AppsPromo* apps_promo = extension_service_->apps_promo();
956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 961 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 962 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
958 iter != app_ids.end(); ++iter) { 963 iter != app_ids.end(); ++iter) {
959 if (extension_service_->GetExtensionById(*iter, true)) 964 if (extension_service_->GetExtensionById(*iter, true))
960 extension_service_->UninstallExtension(*iter, false, NULL); 965 extension_service_->UninstallExtension(*iter, false, NULL);
961 } 966 }
962 } 967 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698