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

Side by Side Diff: trunk/src/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc

Issue 25716004: Revert 226547 "Refactor LauncherItemController and LauncherItemD..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/desktop_background/desktop_background_controller.h" 10 #include "ash/desktop_background/desktop_background_controller.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/ui/ash/app_sync_ui_state.h" 36 #include "chrome/browser/ui/ash/app_sync_ui_state.h"
37 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 37 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
38 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " 38 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
39 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 39 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
40 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 40 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h " 42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h "
43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" 43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
45 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" 45 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
46 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
47 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
46 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 48 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
47 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" 49 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h"
48 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h " 50 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h "
49 #include "chrome/browser/ui/browser.h" 51 #include "chrome/browser/ui/browser.h"
50 #include "chrome/browser/ui/browser_commands.h" 52 #include "chrome/browser/ui/browser_commands.h"
51 #include "chrome/browser/ui/browser_finder.h" 53 #include "chrome/browser/ui/browser_finder.h"
52 #include "chrome/browser/ui/browser_list.h" 54 #include "chrome/browser/ui/browser_list.h"
53 #include "chrome/browser/ui/browser_tabstrip.h" 55 #include "chrome/browser/ui/browser_tabstrip.h"
54 #include "chrome/browser/ui/browser_window.h" 56 #include "chrome/browser/ui/browser_window.h"
55 #include "chrome/browser/ui/extensions/application_launch.h" 57 #include "chrome/browser/ui/extensions/application_launch.h"
(...skipping 18 matching lines...) Expand all
74 #include "grit/generated_resources.h" 76 #include "grit/generated_resources.h"
75 #include "grit/theme_resources.h" 77 #include "grit/theme_resources.h"
76 #include "grit/ui_resources.h" 78 #include "grit/ui_resources.h"
77 #include "net/base/url_util.h" 79 #include "net/base/url_util.h"
78 #include "ui/aura/root_window.h" 80 #include "ui/aura/root_window.h"
79 #include "ui/aura/window.h" 81 #include "ui/aura/window.h"
80 #include "ui/base/l10n/l10n_util.h" 82 #include "ui/base/l10n/l10n_util.h"
81 #include "ui/views/corewm/window_animations.h" 83 #include "ui/views/corewm/window_animations.h"
82 84
83 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
86 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
84 #include "chrome/browser/chromeos/login/user_manager.h" 87 #include "chrome/browser/chromeos/login/user_manager.h"
85 #include "chrome/browser/chromeos/login/wallpaper_manager.h" 88 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
86 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" 89 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
87 #endif 90 #endif
88 91
89 using extensions::Extension; 92 using extensions::Extension;
90 using extension_misc::kGmailAppId; 93 using extension_misc::kGmailAppId;
91 using content::WebContents; 94 using content::WebContents;
92 95
93 // static 96 // static
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // and wallpapers are not synchronized across multiple desktops. 249 // and wallpapers are not synchronized across multiple desktops.
247 if (chromeos::WallpaperManager::Get()) 250 if (chromeos::WallpaperManager::Get())
248 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email); 251 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email);
249 } 252 }
250 #endif 253 #endif
251 254
252 ChromeLauncherController::ChromeLauncherController( 255 ChromeLauncherController::ChromeLauncherController(
253 Profile* profile, 256 Profile* profile,
254 ash::LauncherModel* model) 257 ash::LauncherModel* model)
255 : model_(model), 258 : model_(model),
256 item_delegate_manager_(NULL),
257 profile_(profile), 259 profile_(profile),
258 app_sync_ui_state_(NULL), 260 app_sync_ui_state_(NULL),
259 ignore_persist_pinned_state_change_(false) { 261 ignore_persist_pinned_state_change_(false) {
260 if (!profile_) { 262 if (!profile_) {
261 // Use the original profile as on chromeos we may get a temporary off the 263 // Use the original profile as on chromeos we may get a temporary off the
262 // record profile. 264 // record profile.
263 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); 265 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
264 266
265 app_sync_ui_state_ = AppSyncUIState::Get(profile_); 267 app_sync_ui_state_ = AppSyncUIState::Get(profile_);
266 if (app_sync_ui_state_) 268 if (app_sync_ui_state_)
267 app_sync_ui_state_->AddObserver(this); 269 app_sync_ui_state_->AddObserver(this);
268 } 270 }
269 271
270 // All profile relevant settings get bound to the current profile. 272 // All profile relevant settings get bound to the current profile.
271 AttachProfile(profile_); 273 AttachProfile(profile_);
272 274
273 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); 275 browser_status_monitor_.reset(new BrowserStatusMonitor(this));
274 model_->AddObserver(this); 276 model_->AddObserver(this);
275 // Right now ash::Shell isn't created for tests. 277 // Right now ash::Shell isn't created for tests.
276 // TODO(mukai): Allows it to observe display change and write tests. 278 // TODO(mukai): Allows it to observe display change and write tests.
277 if (ash::Shell::HasInstance()) { 279 if (ash::Shell::HasInstance())
278 ash::Shell::GetInstance()->display_controller()->AddObserver(this); 280 ash::Shell::GetInstance()->display_controller()->AddObserver(this);
279 item_delegate_manager_ =
280 ash::Shell::GetInstance()->launcher_item_delegate_manager();
281 }
282 // TODO(stevenjb): Find a better owner for shell_window_controller_? 281 // TODO(stevenjb): Find a better owner for shell_window_controller_?
283 shell_window_controller_.reset(new ShellWindowLauncherController(this)); 282 shell_window_controller_.reset(new ShellWindowLauncherController(this));
284 283
285 notification_registrar_.Add(this, 284 notification_registrar_.Add(this,
286 chrome::NOTIFICATION_EXTENSION_LOADED, 285 chrome::NOTIFICATION_EXTENSION_LOADED,
287 content::Source<Profile>(profile_)); 286 content::Source<Profile>(profile_));
288 notification_registrar_.Add(this, 287 notification_registrar_.Add(this,
289 chrome::NOTIFICATION_EXTENSION_UNLOADED, 288 chrome::NOTIFICATION_EXTENSION_UNLOADED,
290 content::Source<Profile>(profile_)); 289 content::Source<Profile>(profile_));
291 290
291 // This check is needed for win7_aura. Without this, all tests in
292 // ChromeLauncherControllerTest will fail by win7_aura.
293 if (ash::Shell::HasInstance())
294 RegisterLauncherItemDelegate();
295
292 #if defined(OS_CHROMEOS) 296 #if defined(OS_CHROMEOS)
293 // On Chrome OS using multi profile we want to switch the content of the shelf 297 // On Chrome OS using multi profile we want to switch the content of the shelf
294 // with a user change. Note that for unit tests the instance can be NULL. 298 // with a user change. Note that for unit tests the instance can be NULL.
295 if (ChromeShellDelegate::instance() && 299 if (ChromeShellDelegate::instance() &&
296 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) { 300 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) {
297 user_switch_observer_.reset( 301 user_switch_observer_.reset(
298 new ChromeLauncherControllerUserSwitchObserverChromeOS(this)); 302 new ChromeLauncherControllerUserSwitchObserverChromeOS(this));
299 } 303 }
300 #endif 304 #endif
301 } 305 }
302 306
303 ChromeLauncherController::~ChromeLauncherController() { 307 ChromeLauncherController::~ChromeLauncherController() {
304 // Reset the BrowserStatusMonitor as it has a weak pointer to this. 308 // Reset the BrowserStatusMonitor as it has a weak pointer to this.
305 browser_status_monitor_.reset(); 309 browser_status_monitor_.reset();
306 310
307 // Reset the shell window controller here since it has a weak pointer to this. 311 // Reset the shell window controller here since it has a weak pointer to this.
308 shell_window_controller_.reset(); 312 shell_window_controller_.reset();
309 313
310 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); 314 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin();
311 iter != launchers_.end(); 315 iter != launchers_.end();
312 ++iter) 316 ++iter)
313 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); 317 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this);
314 318
315 model_->RemoveObserver(this); 319 model_->RemoveObserver(this);
316 if (ash::Shell::HasInstance()) 320 if (ash::Shell::HasInstance())
317 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); 321 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this);
318 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 322 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
319 i != id_to_item_controller_map_.end(); ++i) { 323 i != id_to_item_controller_map_.end(); ++i) {
324 i->second->OnRemoved();
320 int index = model_->ItemIndexByID(i->first); 325 int index = model_->ItemIndexByID(i->first);
321 // A "browser proxy" is not known to the model and this removal does 326 // A "browser proxy" is not known to the model and this removal does
322 // therefore not need to be propagated to the model. 327 // therefore not need to be propagated to the model.
323 if (index != -1 && 328 if (index != -1 &&
324 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) 329 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT)
325 model_->RemoveItemAt(index); 330 model_->RemoveItemAt(index);
326 } 331 }
327 332
328 if (ash::Shell::HasInstance()) 333 if (ash::Shell::HasInstance())
329 ash::Shell::GetInstance()->RemoveShellObserver(this); 334 ash::Shell::GetInstance()->RemoveShellObserver(this);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 model_->Set(index, item); 399 model_->Set(index, item);
395 } 400 }
396 } 401 }
397 402
398 void ChromeLauncherController::SetItemController( 403 void ChromeLauncherController::SetItemController(
399 ash::LauncherID id, 404 ash::LauncherID id,
400 LauncherItemController* controller) { 405 LauncherItemController* controller) {
401 CHECK(controller); 406 CHECK(controller);
402 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 407 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
403 CHECK(iter != id_to_item_controller_map_.end()); 408 CHECK(iter != id_to_item_controller_map_.end());
409 iter->second->OnRemoved();
410 iter->second = controller;
404 controller->set_launcher_id(id); 411 controller->set_launcher_id(id);
405 iter->second = controller;
406 // Existing controller is destroyed and replaced by registering again.
407 SetLauncherItemDelegate(id, controller);
408 } 412 }
409 413
410 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { 414 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) {
411 CHECK(id); 415 CHECK(id);
412 if (IsPinned(id)) { 416 if (IsPinned(id)) {
413 // Create a new shortcut controller. 417 // Create a new shortcut controller.
414 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 418 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
415 CHECK(iter != id_to_item_controller_map_.end()); 419 CHECK(iter != id_to_item_controller_map_.end());
416 SetItemStatus(id, ash::STATUS_CLOSED); 420 SetItemStatus(id, ash::STATUS_CLOSED);
417 std::string app_id = iter->second->app_id(); 421 std::string app_id = iter->second->app_id();
422 iter->second->OnRemoved();
418 iter->second = new AppShortcutLauncherItemController(app_id, this); 423 iter->second = new AppShortcutLauncherItemController(app_id, this);
419 iter->second->set_launcher_id(id); 424 iter->second->set_launcher_id(id);
420 // Existing controller is destroyed and replaced by registering again.
421 SetLauncherItemDelegate(id, iter->second);
422 } else { 425 } else {
423 LauncherItemClosed(id); 426 LauncherItemClosed(id);
424 } 427 }
425 } 428 }
426 429
427 void ChromeLauncherController::Pin(ash::LauncherID id) { 430 void ChromeLauncherController::Pin(ash::LauncherID id) {
428 DCHECK(HasItemController(id)); 431 DCHECK(HasItemController(id));
429 432
430 int index = model_->ItemIndexByID(id); 433 int index = model_->ItemIndexByID(id);
431 DCHECK_GE(index, 0); 434 DCHECK_GE(index, 0);
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); 938 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
936 } else { 939 } else {
937 window->Minimize(); 940 window->Minimize();
938 } 941 }
939 } else { 942 } else {
940 window->Show(); 943 window->Show();
941 window->Activate(); 944 window->Activate();
942 } 945 }
943 } 946 }
944 947
948 void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item,
949 const ui::Event& event) {
950 DCHECK(HasItemController(item.id));
951 LauncherItemController* item_controller = id_to_item_controller_map_[item.id];
952 #if defined(OS_CHROMEOS)
953 if (!item_controller->app_id().empty()) {
954 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick(
955 item_controller->app_id());
956 }
957 #endif
958 item_controller->Clicked(event);
959 }
960
961 string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) {
962 DCHECK(HasItemController(item.id));
963 return id_to_item_controller_map_[item.id]->GetTitle();
964 }
965
966 ui::MenuModel* ChromeLauncherController::CreateContextMenu(
967 const ash::LauncherItem& item,
968 aura::RootWindow* root_window) {
969 return new LauncherContextMenu(this, &item, root_window);
970 }
971
972 ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu(
973 const ash::LauncherItem& item,
974 int event_flags) {
975 return new LauncherApplicationMenuItemModel(GetApplicationList(item,
976 event_flags));
977 }
978
945 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { 979 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) {
946 int browser_index = ash::GetBrowserItemIndex(*model_); 980 int browser_index = ash::GetBrowserItemIndex(*model_);
947 DCHECK_GE(browser_index, 0); 981 DCHECK_GE(browser_index, 0);
948 ash::LauncherID browser_id = model_->items()[browser_index].id; 982 ash::LauncherID browser_id = model_->items()[browser_index].id;
949 983
950 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); 984 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin();
951 for (; i != id_to_item_controller_map_.end(); ++i) { 985 for (; i != id_to_item_controller_map_.end(); ++i) {
952 // Since a |window| can be used by multiple applications, an explicit 986 // Since a |window| can be used by multiple applications, an explicit
953 // application always gets chosen over the generic browser. 987 // application always gets chosen over the generic browser.
954 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) 988 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window))
955 return i->first; 989 return i->first;
956 } 990 }
957 991
958 if (i == id_to_item_controller_map_.end() && 992 if (i == id_to_item_controller_map_.end() &&
959 GetBrowserShortcutLauncherItemController()-> 993 GetBrowserShortcutLauncherItemController()->
960 IsCurrentlyShownInWindow(window)) 994 IsCurrentlyShownInWindow(window))
961 return browser_id; 995 return browser_id;
962 996
963 return 0; 997 return 0;
964 } 998 }
965 999
1000 bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) {
1001 return (item.type == ash::TYPE_APP_SHORTCUT ||
1002 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true;
1003 }
1004
1005 bool ChromeLauncherController::ShouldShowTooltip(
1006 const ash::LauncherItem& item) {
1007 if (item.type == ash::TYPE_APP_PANEL &&
1008 id_to_item_controller_map_[item.id]->IsVisible())
1009 return false;
1010 return true;
1011 }
1012
966 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { 1013 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) {
967 launchers_.insert(launcher); 1014 launchers_.insert(launcher);
968 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); 1015 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this);
969 } 1016 }
970 1017
971 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { 1018 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) {
972 launchers_.erase(launcher); 1019 launchers_.erase(launcher);
973 // RemoveObserver is not called here, since by the time this method is called 1020 // RemoveObserver is not called here, since by the time this method is called
974 // Launcher is already in its destructor. 1021 // Launcher is already in its destructor.
975 } 1022 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 void ChromeLauncherController::SetAppIconLoaderForTest( 1282 void ChromeLauncherController::SetAppIconLoaderForTest(
1236 extensions::AppIconLoader* loader) { 1283 extensions::AppIconLoader* loader) {
1237 app_icon_loader_.reset(loader); 1284 app_icon_loader_.reset(loader);
1238 } 1285 }
1239 1286
1240 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( 1287 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest(
1241 ash::LauncherID id) { 1288 ash::LauncherID id) {
1242 return id_to_item_controller_map_[id]->app_id(); 1289 return id_to_item_controller_map_[id]->app_id();
1243 } 1290 }
1244 1291
1245 void ChromeLauncherController::SetLauncherItemDelegateManagerForTest(
1246 ash::LauncherItemDelegateManager* manager) {
1247 item_delegate_manager_ = manager;
1248 }
1249
1250 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( 1292 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType(
1251 const std::string& app_id, 1293 const std::string& app_id,
1252 int index, 1294 int index,
1253 ash::LauncherItemType launcher_item_type) { 1295 ash::LauncherItemType launcher_item_type) {
1254 AppShortcutLauncherItemController* controller = 1296 AppShortcutLauncherItemController* controller =
1255 new AppShortcutLauncherItemController(app_id, this); 1297 new AppShortcutLauncherItemController(app_id, this);
1256 ash::LauncherID launcher_id = InsertAppLauncherItem( 1298 ash::LauncherID launcher_id = InsertAppLauncherItem(
1257 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); 1299 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type);
1258 return launcher_id; 1300 return launcher_id;
1259 } 1301 }
1260 1302
1261 LauncherItemController* ChromeLauncherController::GetLauncherItemController(
1262 const ash::LauncherID id) {
1263 if (!HasItemController(id))
1264 return NULL;
1265 return id_to_item_controller_map_[id];
1266 }
1267
1268 Profile* ChromeLauncherController::GetProfileForNewWindows() { 1303 Profile* ChromeLauncherController::GetProfileForNewWindows() {
1269 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 1304 return ProfileManager::GetDefaultProfileOrOffTheRecord();
1270 } 1305 }
1271 1306
1272 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { 1307 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
1273 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1308 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1274 CHECK(iter != id_to_item_controller_map_.end()); 1309 CHECK(iter != id_to_item_controller_map_.end());
1275 CHECK(iter->second); 1310 CHECK(iter->second);
1276 app_icon_loader_->ClearImage(iter->second->app_id()); 1311 app_icon_loader_->ClearImage(iter->second->app_id());
1312 iter->second->OnRemoved();
1277 id_to_item_controller_map_.erase(iter); 1313 id_to_item_controller_map_.erase(iter);
1278 int index = model_->ItemIndexByID(id); 1314 int index = model_->ItemIndexByID(id);
1279 // A "browser proxy" is not known to the model and this removal does 1315 // A "browser proxy" is not known to the model and this removal does
1280 // therefore not need to be propagated to the model. 1316 // therefore not need to be propagated to the model.
1281 if (index != -1) 1317 if (index != -1)
1282 model_->RemoveItemAt(index); 1318 model_->RemoveItemAt(index);
1283 } 1319 }
1284 1320
1285 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { 1321 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) {
1286 // If there is an item, do nothing and return. 1322 // If there is an item, do nothing and return.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 status = ash::STATUS_ACTIVE; 1620 status = ash::STATUS_ACTIVE;
1585 else 1621 else
1586 status = ash::STATUS_RUNNING; 1622 status = ash::STATUS_RUNNING;
1587 } 1623 }
1588 item.status = status; 1624 item.status = status;
1589 1625
1590 model_->AddAt(index, item); 1626 model_->AddAt(index, item);
1591 1627
1592 app_icon_loader_->FetchImage(app_id); 1628 app_icon_loader_->FetchImage(app_id);
1593 1629
1594 SetLauncherItemDelegate(id, controller);
1595
1596 return id; 1630 return id;
1597 } 1631 }
1598 1632
1599 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { 1633 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const {
1600 return id_to_item_controller_map_.find(id) != 1634 return id_to_item_controller_map_.find(id) !=
1601 id_to_item_controller_map_.end(); 1635 id_to_item_controller_map_.end();
1602 } 1636 }
1603 1637
1604 std::vector<content::WebContents*> 1638 std::vector<content::WebContents*>
1605 ChromeLauncherController::GetV1ApplicationsFromController( 1639 ChromeLauncherController::GetV1ApplicationsFromController(
(...skipping 22 matching lines...) Expand all
1628 } 1662 }
1629 1663
1630 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { 1664 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1631 ash::LauncherItem browser_shortcut; 1665 ash::LauncherItem browser_shortcut;
1632 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1666 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1633 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1667 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1634 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1668 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1635 ash::LauncherID id = model_->next_id(); 1669 ash::LauncherID id = model_->next_id();
1636 size_t index = GetChromeIconIndexForCreation(); 1670 size_t index = GetChromeIconIndexForCreation();
1637 model_->AddAt(index, browser_shortcut); 1671 model_->AddAt(index, browser_shortcut);
1638 id_to_item_controller_map_[id] = 1672 browser_item_controller_.reset(
1639 new BrowserShortcutLauncherItemController(this); 1673 new BrowserShortcutLauncherItemController(this));
1674 id_to_item_controller_map_[id] = browser_item_controller_.get();
1640 id_to_item_controller_map_[id]->set_launcher_id(id); 1675 id_to_item_controller_map_[id]->set_launcher_id(id);
1641 // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController.
1642 SetLauncherItemDelegate(id, id_to_item_controller_map_[id]);
1643 return id; 1676 return id;
1644 } 1677 }
1645 1678
1646 void ChromeLauncherController::PersistChromeItemIndex(int index) { 1679 void ChromeLauncherController::PersistChromeItemIndex(int index) {
1647 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); 1680 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
1648 } 1681 }
1649 1682
1650 int ChromeLauncherController::GetChromeIconIndexFromPref() const { 1683 int ChromeLauncherController::GetChromeIconIndexFromPref() const {
1651 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); 1684 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex);
1652 const base::ListValue* pinned_apps_pref = 1685 const base::ListValue* pinned_apps_pref =
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 browser_to_close.push_back(browser); 1840 browser_to_close.push_back(browser);
1808 } 1841 }
1809 } 1842 }
1810 while (!browser_to_close.empty()) { 1843 while (!browser_to_close.empty()) {
1811 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 1844 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
1812 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 1845 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
1813 browser_to_close.pop_back(); 1846 browser_to_close.pop_back();
1814 } 1847 }
1815 } 1848 }
1816 1849
1817 void ChromeLauncherController::SetLauncherItemDelegate( 1850 void ChromeLauncherController::RegisterLauncherItemDelegate() {
1818 ash::LauncherID id, 1851 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate
1819 ash::LauncherItemDelegate* item_delegate) { 1852 // is created.
1820 DCHECK_GT(id, 0); 1853 ash::LauncherItemDelegateManager* manager =
1821 DCHECK(item_delegate); 1854 ash::Shell::GetInstance()->launcher_item_delegate_manager();
1822 DCHECK(item_delegate_manager_); 1855 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
1823 item_delegate_manager_->SetLauncherItemDelegate(id, 1856 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
1824 scoped_ptr<ash::LauncherItemDelegate>(item_delegate).Pass()); 1857 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
1858 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
1859 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
1825 } 1860 }
1826 1861
1827 void ChromeLauncherController::AttachProfile(Profile* profile) { 1862 void ChromeLauncherController::AttachProfile(Profile* profile) {
1828 profile_ = profile; 1863 profile_ = profile;
1829 // Either add the profile to the list of known profiles and make it the active 1864 // Either add the profile to the list of known profiles and make it the active
1830 // one for some functions of AppTabHelper or create a new one. 1865 // one for some functions of AppTabHelper or create a new one.
1831 if (!app_tab_helper_.get()) 1866 if (!app_tab_helper_.get())
1832 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); 1867 app_tab_helper_.reset(new LauncherAppTabHelper(profile_));
1833 else 1868 else
1834 app_tab_helper_->SetCurrentUser(profile_); 1869 app_tab_helper_->SetCurrentUser(profile_);
(...skipping 26 matching lines...) Expand all
1861 } 1896 }
1862 1897
1863 void ChromeLauncherController::ReleaseProfile() { 1898 void ChromeLauncherController::ReleaseProfile() {
1864 if (app_sync_ui_state_) 1899 if (app_sync_ui_state_)
1865 app_sync_ui_state_->RemoveObserver(this); 1900 app_sync_ui_state_->RemoveObserver(this);
1866 1901
1867 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 1902 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
1868 1903
1869 pref_change_registrar_.RemoveAll(); 1904 pref_change_registrar_.RemoveAll();
1870 } 1905 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698