| OLD | NEW |
| 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/views/ash/launcher/chrome_launcher_delegate.h" | 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
| 8 #include "ash/launcher/launcher_types.h" | 8 #include "ash/launcher/launcher_types.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 instance_ = this; | 99 instance_ = this; |
| 100 model_->AddObserver(this); | 100 model_->AddObserver(this); |
| 101 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); | 101 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); |
| 102 | 102 |
| 103 registrar_.Add(this, | 103 registrar_.Add(this, |
| 104 chrome::NOTIFICATION_EXTENSION_LOADED, | 104 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 105 content::Source<Profile>(profile_)); | 105 content::Source<Profile>(profile_)); |
| 106 registrar_.Add(this, | 106 registrar_.Add(this, |
| 107 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 107 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 108 content::Source<Profile>(profile_)); | 108 content::Source<Profile>(profile_)); |
| 109 registrar_.Add(this, |
| 110 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 111 content::Source<Profile>(profile_)); |
| 109 } | 112 } |
| 110 | 113 |
| 111 ChromeLauncherDelegate::~ChromeLauncherDelegate() { | 114 ChromeLauncherDelegate::~ChromeLauncherDelegate() { |
| 112 model_->RemoveObserver(this); | 115 model_->RemoveObserver(this); |
| 113 for (IDToItemMap::iterator i = id_to_item_map_.begin(); | 116 for (IDToItemMap::iterator i = id_to_item_map_.begin(); |
| 114 i != id_to_item_map_.end(); ++i) { | 117 i != id_to_item_map_.end(); ++i) { |
| 115 model_->RemoveItemAt(model_->ItemIndexByID(i->first)); | 118 model_->RemoveItemAt(model_->ItemIndexByID(i->first)); |
| 116 } | 119 } |
| 117 if (instance_ == this) | 120 if (instance_ == this) |
| 118 instance_ = NULL; | 121 instance_ = NULL; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 148 DictionaryValue* app = NULL; | 151 DictionaryValue* app = NULL; |
| 149 if (pinned_apps->GetDictionary(i, &app)) { | 152 if (pinned_apps->GetDictionary(i, &app)) { |
| 150 std::string app_id; | 153 std::string app_id; |
| 151 if (app->GetString(kAppIDPath, &app_id)) { | 154 if (app->GetString(kAppIDPath, &app_id)) { |
| 152 if (app_icon_loader_->IsValidID(app_id)) { | 155 if (app_icon_loader_->IsValidID(app_id)) { |
| 153 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); | 156 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); |
| 154 } else { | 157 } else { |
| 155 Item pending_item; | 158 Item pending_item; |
| 156 pending_item.item_type = TYPE_APP; | 159 pending_item.item_type = TYPE_APP; |
| 157 pending_item.app_id = app_id; | 160 pending_item.app_id = app_id; |
| 158 pending_pinned_apps_.push(pending_item); | 161 pending_pinned_apps_.push_back(pending_item); |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 } | 164 } |
| 162 } | 165 } |
| 163 // TODO(sky): update unit test so that this test isn't necessary. | 166 // TODO(sky): update unit test so that this test isn't necessary. |
| 164 if (ash::Shell::HasInstance()) { | 167 if (ash::Shell::HasInstance()) { |
| 165 std::string behavior_value( | 168 std::string behavior_value( |
| 166 profile_->GetPrefs()->GetString(prefs::kShelfAutoHideBehavior)); | 169 profile_->GetPrefs()->GetString(prefs::kShelfAutoHideBehavior)); |
| 167 ash::ShelfAutoHideBehavior behavior = | 170 ash::ShelfAutoHideBehavior behavior = |
| 168 ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT; | 171 ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 const content::NotificationSource& source, | 537 const content::NotificationSource& source, |
| 535 const content::NotificationDetails& details) { | 538 const content::NotificationDetails& details) { |
| 536 switch (type) { | 539 switch (type) { |
| 537 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 540 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 538 ProcessPendingPinnedApps(); | 541 ProcessPendingPinnedApps(); |
| 539 break; | 542 break; |
| 540 } | 543 } |
| 541 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 544 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 542 const Extension* extension = | 545 const Extension* extension = |
| 543 content::Details<UnloadedExtensionInfo>(details)->extension; | 546 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 544 UnpinAppsWithID(extension->id()); | 547 if (IsAppPinned(extension->id())) { |
| 548 // TODO(dpolukhin): also we need to remember index of the app to show |
| 549 // it on the same place when it gets loaded again. |
| 550 Item pending_item; |
| 551 pending_item.item_type = TYPE_APP; |
| 552 pending_item.app_id = extension->id(); |
| 553 pending_pinned_apps_.push_back(pending_item); |
| 554 UnpinAppsWithID(extension->id()); |
| 555 } |
| 556 break; |
| 557 } |
| 558 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 559 std::string id = *content::Details<const std::string>(details).ptr(); |
| 560 for (std::deque<Item>::iterator it = pending_pinned_apps_.begin(); |
| 561 it != pending_pinned_apps_.end(); ++it) { |
| 562 if (it->app_id == id) { |
| 563 pending_pinned_apps_.erase(it); |
| 564 break; |
| 565 } |
| 566 } |
| 545 break; | 567 break; |
| 546 } | 568 } |
| 547 default: | 569 default: |
| 548 NOTREACHED() << "Unexpected notification type=" << type; | 570 NOTREACHED() << "Unexpected notification type=" << type; |
| 549 } | 571 } |
| 550 } | 572 } |
| 551 | 573 |
| 552 void ChromeLauncherDelegate::PersistPinnedState() { | 574 void ChromeLauncherDelegate::PersistPinnedState() { |
| 553 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs | 575 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs |
| 554 // from now on. | 576 // from now on. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 579 } | 601 } |
| 580 | 602 |
| 581 void ChromeLauncherDelegate::ProcessPendingPinnedApps() { | 603 void ChromeLauncherDelegate::ProcessPendingPinnedApps() { |
| 582 while (!pending_pinned_apps_.empty()) { | 604 while (!pending_pinned_apps_.empty()) { |
| 583 const Item& item = pending_pinned_apps_.front(); | 605 const Item& item = pending_pinned_apps_.front(); |
| 584 | 606 |
| 585 if (!app_icon_loader_->IsValidID(item.app_id)) | 607 if (!app_icon_loader_->IsValidID(item.app_id)) |
| 586 return; | 608 return; |
| 587 | 609 |
| 588 PinAppWithID(item.app_id); | 610 PinAppWithID(item.app_id); |
| 589 pending_pinned_apps_.pop(); | 611 pending_pinned_apps_.pop_front(); |
| 590 } | 612 } |
| 591 } | 613 } |
| OLD | NEW |