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

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

Issue 25823002: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
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"
48 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 46 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
49 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" 47 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h"
50 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h " 48 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h "
51 #include "chrome/browser/ui/browser.h" 49 #include "chrome/browser/ui/browser.h"
52 #include "chrome/browser/ui/browser_commands.h" 50 #include "chrome/browser/ui/browser_commands.h"
53 #include "chrome/browser/ui/browser_finder.h" 51 #include "chrome/browser/ui/browser_finder.h"
54 #include "chrome/browser/ui/browser_list.h" 52 #include "chrome/browser/ui/browser_list.h"
55 #include "chrome/browser/ui/browser_tabstrip.h" 53 #include "chrome/browser/ui/browser_tabstrip.h"
56 #include "chrome/browser/ui/browser_window.h" 54 #include "chrome/browser/ui/browser_window.h"
57 #include "chrome/browser/ui/extensions/application_launch.h" 55 #include "chrome/browser/ui/extensions/application_launch.h"
(...skipping 18 matching lines...) Expand all
76 #include "grit/generated_resources.h" 74 #include "grit/generated_resources.h"
77 #include "grit/theme_resources.h" 75 #include "grit/theme_resources.h"
78 #include "grit/ui_resources.h" 76 #include "grit/ui_resources.h"
79 #include "net/base/url_util.h" 77 #include "net/base/url_util.h"
80 #include "ui/aura/root_window.h" 78 #include "ui/aura/root_window.h"
81 #include "ui/aura/window.h" 79 #include "ui/aura/window.h"
82 #include "ui/base/l10n/l10n_util.h" 80 #include "ui/base/l10n/l10n_util.h"
83 #include "ui/views/corewm/window_animations.h" 81 #include "ui/views/corewm/window_animations.h"
84 82
85 #if defined(OS_CHROMEOS) 83 #if defined(OS_CHROMEOS)
86 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
87 #include "chrome/browser/chromeos/login/user_manager.h" 84 #include "chrome/browser/chromeos/login/user_manager.h"
88 #include "chrome/browser/chromeos/login/wallpaper_manager.h" 85 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
89 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" 86 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
90 #include "chrome/browser/ui/ash/multi_user_window_manager.h" 87 #include "chrome/browser/ui/ash/multi_user_window_manager.h"
91 #endif 88 #endif
92 89
93 using extensions::Extension; 90 using extensions::Extension;
94 using extension_misc::kGmailAppId; 91 using extension_misc::kGmailAppId;
95 using content::WebContents; 92 using content::WebContents;
96 93
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 // and wallpapers are not synchronized across multiple desktops. 247 // and wallpapers are not synchronized across multiple desktops.
251 if (chromeos::WallpaperManager::Get()) 248 if (chromeos::WallpaperManager::Get())
252 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email); 249 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email);
253 } 250 }
254 #endif 251 #endif
255 252
256 ChromeLauncherController::ChromeLauncherController( 253 ChromeLauncherController::ChromeLauncherController(
257 Profile* profile, 254 Profile* profile,
258 ash::LauncherModel* model) 255 ash::LauncherModel* model)
259 : model_(model), 256 : model_(model),
257 item_delegate_manager_(NULL),
260 profile_(profile), 258 profile_(profile),
261 app_sync_ui_state_(NULL), 259 app_sync_ui_state_(NULL),
262 ignore_persist_pinned_state_change_(false) { 260 ignore_persist_pinned_state_change_(false) {
263 if (!profile_) { 261 if (!profile_) {
264 // Use the original profile as on chromeos we may get a temporary off the 262 // Use the original profile as on chromeos we may get a temporary off the
265 // record profile. 263 // record profile.
266 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); 264 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
267 265
268 app_sync_ui_state_ = AppSyncUIState::Get(profile_); 266 app_sync_ui_state_ = AppSyncUIState::Get(profile_);
269 if (app_sync_ui_state_) 267 if (app_sync_ui_state_)
270 app_sync_ui_state_->AddObserver(this); 268 app_sync_ui_state_->AddObserver(this);
271 } 269 }
272 270
273 // All profile relevant settings get bound to the current profile. 271 // All profile relevant settings get bound to the current profile.
274 AttachProfile(profile_); 272 AttachProfile(profile_);
275 273
276 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); 274 browser_status_monitor_.reset(new BrowserStatusMonitor(this));
277 model_->AddObserver(this); 275 model_->AddObserver(this);
278 // Right now ash::Shell isn't created for tests. 276 // Right now ash::Shell isn't created for tests.
279 // TODO(mukai): Allows it to observe display change and write tests. 277 // TODO(mukai): Allows it to observe display change and write tests.
280 if (ash::Shell::HasInstance()) 278 if (ash::Shell::HasInstance()) {
281 ash::Shell::GetInstance()->display_controller()->AddObserver(this); 279 ash::Shell::GetInstance()->display_controller()->AddObserver(this);
280 item_delegate_manager_ =
281 ash::Shell::GetInstance()->launcher_item_delegate_manager();
282 }
282 // TODO(stevenjb): Find a better owner for shell_window_controller_? 283 // TODO(stevenjb): Find a better owner for shell_window_controller_?
283 shell_window_controller_.reset(new ShellWindowLauncherController(this)); 284 shell_window_controller_.reset(new ShellWindowLauncherController(this));
284 285
285 notification_registrar_.Add(this, 286 notification_registrar_.Add(this,
286 chrome::NOTIFICATION_EXTENSION_LOADED, 287 chrome::NOTIFICATION_EXTENSION_LOADED,
287 content::Source<Profile>(profile_)); 288 content::Source<Profile>(profile_));
288 notification_registrar_.Add(this, 289 notification_registrar_.Add(this,
289 chrome::NOTIFICATION_EXTENSION_UNLOADED, 290 chrome::NOTIFICATION_EXTENSION_UNLOADED,
290 content::Source<Profile>(profile_)); 291 content::Source<Profile>(profile_));
291 292
292 // This check is needed for win7_aura. Without this, all tests in
293 // ChromeLauncherControllerTest will fail by win7_aura.
294 if (ash::Shell::HasInstance())
295 RegisterLauncherItemDelegate();
296
297 #if defined(OS_CHROMEOS) 293 #if defined(OS_CHROMEOS)
298 // On Chrome OS using multi profile we want to switch the content of the shelf 294 // On Chrome OS using multi profile we want to switch the content of the shelf
299 // with a user change. Note that for unit tests the instance can be NULL. 295 // with a user change. Note that for unit tests the instance can be NULL.
300 if (ChromeShellDelegate::instance() && 296 if (ChromeShellDelegate::instance() &&
301 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) { 297 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) {
302 user_switch_observer_.reset( 298 user_switch_observer_.reset(
303 new ChromeLauncherControllerUserSwitchObserverChromeOS(this)); 299 new ChromeLauncherControllerUserSwitchObserverChromeOS(this));
304 // TODO(skuhne): Find a better place where to instantiate this. Note that 300 // TODO(skuhne): Find a better place where to instantiate this. Note that
305 // once we start using the manager for other operations it will load itself. 301 // once we start using the manager for other operations it will load itself.
306 chrome::MultiUserWindowManager::GetInstance(); 302 chrome::MultiUserWindowManager::GetInstance();
(...skipping 11 matching lines...) Expand all
318 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); 314 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin();
319 iter != launchers_.end(); 315 iter != launchers_.end();
320 ++iter) 316 ++iter)
321 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); 317 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this);
322 318
323 model_->RemoveObserver(this); 319 model_->RemoveObserver(this);
324 if (ash::Shell::HasInstance()) 320 if (ash::Shell::HasInstance())
325 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); 321 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this);
326 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 322 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
327 i != id_to_item_controller_map_.end(); ++i) { 323 i != id_to_item_controller_map_.end(); ++i) {
328 i->second->OnRemoved();
329 int index = model_->ItemIndexByID(i->first); 324 int index = model_->ItemIndexByID(i->first);
330 // A "browser proxy" is not known to the model and this removal does 325 // A "browser proxy" is not known to the model and this removal does
331 // therefore not need to be propagated to the model. 326 // therefore not need to be propagated to the model.
332 if (index != -1 && 327 if (index != -1 &&
333 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) 328 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT)
334 model_->RemoveItemAt(index); 329 model_->RemoveItemAt(index);
335 } 330 }
336 331
337 if (ash::Shell::HasInstance()) 332 if (ash::Shell::HasInstance())
338 ash::Shell::GetInstance()->RemoveShellObserver(this); 333 ash::Shell::GetInstance()->RemoveShellObserver(this);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 model_->Set(index, item); 404 model_->Set(index, item);
410 } 405 }
411 } 406 }
412 407
413 void ChromeLauncherController::SetItemController( 408 void ChromeLauncherController::SetItemController(
414 ash::LauncherID id, 409 ash::LauncherID id,
415 LauncherItemController* controller) { 410 LauncherItemController* controller) {
416 CHECK(controller); 411 CHECK(controller);
417 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 412 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
418 CHECK(iter != id_to_item_controller_map_.end()); 413 CHECK(iter != id_to_item_controller_map_.end());
419 iter->second->OnRemoved(); 414 controller->set_launcher_id(id);
420 iter->second = controller; 415 iter->second = controller;
421 controller->set_launcher_id(id); 416 // Existing controller is destroyed and replaced by registering again.
417 SetLauncherItemDelegate(id, controller);
422 } 418 }
423 419
424 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { 420 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) {
425 CHECK(id); 421 CHECK(id);
426 if (IsPinned(id)) { 422 if (IsPinned(id)) {
427 // Create a new shortcut controller. 423 // Create a new shortcut controller.
428 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 424 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
429 CHECK(iter != id_to_item_controller_map_.end()); 425 CHECK(iter != id_to_item_controller_map_.end());
430 SetItemStatus(id, ash::STATUS_CLOSED); 426 SetItemStatus(id, ash::STATUS_CLOSED);
431 std::string app_id = iter->second->app_id(); 427 std::string app_id = iter->second->app_id();
432 iter->second->OnRemoved();
433 iter->second = new AppShortcutLauncherItemController(app_id, this); 428 iter->second = new AppShortcutLauncherItemController(app_id, this);
434 iter->second->set_launcher_id(id); 429 iter->second->set_launcher_id(id);
430 // Existing controller is destroyed and replaced by registering again.
431 SetLauncherItemDelegate(id, iter->second);
435 } else { 432 } else {
436 LauncherItemClosed(id); 433 LauncherItemClosed(id);
437 } 434 }
438 } 435 }
439 436
440 void ChromeLauncherController::Pin(ash::LauncherID id) { 437 void ChromeLauncherController::Pin(ash::LauncherID id) {
441 DCHECK(HasItemController(id)); 438 DCHECK(HasItemController(id));
442 439
443 int index = model_->ItemIndexByID(id); 440 int index = model_->ItemIndexByID(id);
444 DCHECK_GE(index, 0); 441 DCHECK_GE(index, 0);
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); 945 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
949 } else { 946 } else {
950 window->Minimize(); 947 window->Minimize();
951 } 948 }
952 } else { 949 } else {
953 window->Show(); 950 window->Show();
954 window->Activate(); 951 window->Activate();
955 } 952 }
956 } 953 }
957 954
958 void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item,
959 const ui::Event& event) {
960 DCHECK(HasItemController(item.id));
961 LauncherItemController* item_controller = id_to_item_controller_map_[item.id];
962 #if defined(OS_CHROMEOS)
963 if (!item_controller->app_id().empty()) {
964 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick(
965 item_controller->app_id());
966 }
967 #endif
968 item_controller->Clicked(event);
969 }
970
971 string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) {
972 DCHECK(HasItemController(item.id));
973 return id_to_item_controller_map_[item.id]->GetTitle();
974 }
975
976 ui::MenuModel* ChromeLauncherController::CreateContextMenu(
977 const ash::LauncherItem& item,
978 aura::RootWindow* root_window) {
979 return new LauncherContextMenu(this, &item, root_window);
980 }
981
982 ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu(
983 const ash::LauncherItem& item,
984 int event_flags) {
985 return new LauncherApplicationMenuItemModel(GetApplicationList(item,
986 event_flags));
987 }
988
989 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { 955 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) {
990 int browser_index = ash::GetBrowserItemIndex(*model_); 956 int browser_index = ash::GetBrowserItemIndex(*model_);
991 DCHECK_GE(browser_index, 0); 957 DCHECK_GE(browser_index, 0);
992 ash::LauncherID browser_id = model_->items()[browser_index].id; 958 ash::LauncherID browser_id = model_->items()[browser_index].id;
993 959
994 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); 960 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin();
995 for (; i != id_to_item_controller_map_.end(); ++i) { 961 for (; i != id_to_item_controller_map_.end(); ++i) {
996 // Since a |window| can be used by multiple applications, an explicit 962 // Since a |window| can be used by multiple applications, an explicit
997 // application always gets chosen over the generic browser. 963 // application always gets chosen over the generic browser.
998 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) 964 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window))
999 return i->first; 965 return i->first;
1000 } 966 }
1001 967
1002 if (i == id_to_item_controller_map_.end() && 968 if (i == id_to_item_controller_map_.end() &&
1003 GetBrowserShortcutLauncherItemController()-> 969 GetBrowserShortcutLauncherItemController()->
1004 IsCurrentlyShownInWindow(window)) 970 IsCurrentlyShownInWindow(window))
1005 return browser_id; 971 return browser_id;
1006 972
1007 return 0; 973 return 0;
1008 } 974 }
1009 975
1010 bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) {
1011 return (item.type == ash::TYPE_APP_SHORTCUT ||
1012 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true;
1013 }
1014
1015 bool ChromeLauncherController::ShouldShowTooltip(
1016 const ash::LauncherItem& item) {
1017 if (item.type == ash::TYPE_APP_PANEL &&
1018 id_to_item_controller_map_[item.id]->IsVisible())
1019 return false;
1020 return true;
1021 }
1022
1023 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { 976 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) {
1024 launchers_.insert(launcher); 977 launchers_.insert(launcher);
1025 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); 978 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this);
1026 } 979 }
1027 980
1028 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { 981 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) {
1029 launchers_.erase(launcher); 982 launchers_.erase(launcher);
1030 // RemoveObserver is not called here, since by the time this method is called 983 // RemoveObserver is not called here, since by the time this method is called
1031 // Launcher is already in its destructor. 984 // Launcher is already in its destructor.
1032 } 985 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 void ChromeLauncherController::SetAppIconLoaderForTest( 1245 void ChromeLauncherController::SetAppIconLoaderForTest(
1293 extensions::AppIconLoader* loader) { 1246 extensions::AppIconLoader* loader) {
1294 app_icon_loader_.reset(loader); 1247 app_icon_loader_.reset(loader);
1295 } 1248 }
1296 1249
1297 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( 1250 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest(
1298 ash::LauncherID id) { 1251 ash::LauncherID id) {
1299 return id_to_item_controller_map_[id]->app_id(); 1252 return id_to_item_controller_map_[id]->app_id();
1300 } 1253 }
1301 1254
1255 void ChromeLauncherController::SetLauncherItemDelegateManagerForTest(
1256 ash::LauncherItemDelegateManager* manager) {
1257 item_delegate_manager_ = manager;
1258 }
1259
1302 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( 1260 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType(
1303 const std::string& app_id, 1261 const std::string& app_id,
1304 int index, 1262 int index,
1305 ash::LauncherItemType launcher_item_type) { 1263 ash::LauncherItemType launcher_item_type) {
1306 AppShortcutLauncherItemController* controller = 1264 AppShortcutLauncherItemController* controller =
1307 new AppShortcutLauncherItemController(app_id, this); 1265 new AppShortcutLauncherItemController(app_id, this);
1308 ash::LauncherID launcher_id = InsertAppLauncherItem( 1266 ash::LauncherID launcher_id = InsertAppLauncherItem(
1309 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); 1267 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type);
1310 return launcher_id; 1268 return launcher_id;
1311 } 1269 }
1312 1270
1271 LauncherItemController* ChromeLauncherController::GetLauncherItemController(
1272 const ash::LauncherID id) {
1273 if (!HasItemController(id))
1274 return NULL;
1275 return id_to_item_controller_map_[id];
1276 }
1277
1313 Profile* ChromeLauncherController::GetProfileForNewWindows() { 1278 Profile* ChromeLauncherController::GetProfileForNewWindows() {
1314 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 1279 return ProfileManager::GetDefaultProfileOrOffTheRecord();
1315 } 1280 }
1316 1281
1317 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { 1282 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
1318 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1283 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1319 CHECK(iter != id_to_item_controller_map_.end()); 1284 CHECK(iter != id_to_item_controller_map_.end());
1320 CHECK(iter->second); 1285 CHECK(iter->second);
1321 app_icon_loader_->ClearImage(iter->second->app_id()); 1286 app_icon_loader_->ClearImage(iter->second->app_id());
1322 iter->second->OnRemoved();
1323 id_to_item_controller_map_.erase(iter); 1287 id_to_item_controller_map_.erase(iter);
1324 int index = model_->ItemIndexByID(id); 1288 int index = model_->ItemIndexByID(id);
1325 // A "browser proxy" is not known to the model and this removal does 1289 // A "browser proxy" is not known to the model and this removal does
1326 // therefore not need to be propagated to the model. 1290 // therefore not need to be propagated to the model.
1327 if (index != -1) 1291 if (index != -1)
1328 model_->RemoveItemAt(index); 1292 model_->RemoveItemAt(index);
1329 } 1293 }
1330 1294
1331 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { 1295 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) {
1332 // If there is an item, do nothing and return. 1296 // If there is an item, do nothing and return.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 status = ash::STATUS_ACTIVE; 1594 status = ash::STATUS_ACTIVE;
1631 else 1595 else
1632 status = ash::STATUS_RUNNING; 1596 status = ash::STATUS_RUNNING;
1633 } 1597 }
1634 item.status = status; 1598 item.status = status;
1635 1599
1636 model_->AddAt(index, item); 1600 model_->AddAt(index, item);
1637 1601
1638 app_icon_loader_->FetchImage(app_id); 1602 app_icon_loader_->FetchImage(app_id);
1639 1603
1604 SetLauncherItemDelegate(id, controller);
1605
1640 return id; 1606 return id;
1641 } 1607 }
1642 1608
1643 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { 1609 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const {
1644 return id_to_item_controller_map_.find(id) != 1610 return id_to_item_controller_map_.find(id) !=
1645 id_to_item_controller_map_.end(); 1611 id_to_item_controller_map_.end();
1646 } 1612 }
1647 1613
1648 std::vector<content::WebContents*> 1614 std::vector<content::WebContents*>
1649 ChromeLauncherController::GetV1ApplicationsFromController( 1615 ChromeLauncherController::GetV1ApplicationsFromController(
(...skipping 22 matching lines...) Expand all
1672 } 1638 }
1673 1639
1674 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { 1640 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1675 ash::LauncherItem browser_shortcut; 1641 ash::LauncherItem browser_shortcut;
1676 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1642 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1677 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1643 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1678 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1644 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1679 ash::LauncherID id = model_->next_id(); 1645 ash::LauncherID id = model_->next_id();
1680 size_t index = GetChromeIconIndexForCreation(); 1646 size_t index = GetChromeIconIndexForCreation();
1681 model_->AddAt(index, browser_shortcut); 1647 model_->AddAt(index, browser_shortcut);
1682 browser_item_controller_.reset( 1648 id_to_item_controller_map_[id] =
1683 new BrowserShortcutLauncherItemController(this)); 1649 new BrowserShortcutLauncherItemController(this);
1684 id_to_item_controller_map_[id] = browser_item_controller_.get();
1685 id_to_item_controller_map_[id]->set_launcher_id(id); 1650 id_to_item_controller_map_[id]->set_launcher_id(id);
1651 // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController.
1652 SetLauncherItemDelegate(id, id_to_item_controller_map_[id]);
1686 return id; 1653 return id;
1687 } 1654 }
1688 1655
1689 void ChromeLauncherController::PersistChromeItemIndex(int index) { 1656 void ChromeLauncherController::PersistChromeItemIndex(int index) {
1690 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); 1657 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
1691 } 1658 }
1692 1659
1693 int ChromeLauncherController::GetChromeIconIndexFromPref() const { 1660 int ChromeLauncherController::GetChromeIconIndexFromPref() const {
1694 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); 1661 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex);
1695 const base::ListValue* pinned_apps_pref = 1662 const base::ListValue* pinned_apps_pref =
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 browser_to_close.push_back(browser); 1817 browser_to_close.push_back(browser);
1851 } 1818 }
1852 } 1819 }
1853 while (!browser_to_close.empty()) { 1820 while (!browser_to_close.empty()) {
1854 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 1821 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
1855 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 1822 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
1856 browser_to_close.pop_back(); 1823 browser_to_close.pop_back();
1857 } 1824 }
1858 } 1825 }
1859 1826
1860 void ChromeLauncherController::RegisterLauncherItemDelegate() { 1827 void ChromeLauncherController::SetLauncherItemDelegate(
1861 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate 1828 ash::LauncherID id,
1862 // is created. 1829 ash::LauncherItemDelegate* item_delegate) {
1863 ash::LauncherItemDelegateManager* manager = 1830 DCHECK_GT(id, 0);
1864 ash::Shell::GetInstance()->launcher_item_delegate_manager(); 1831 DCHECK(item_delegate);
1865 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); 1832 DCHECK(item_delegate_manager_);
1866 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); 1833 item_delegate_manager_->SetLauncherItemDelegate(id,
1867 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); 1834 scoped_ptr<ash::LauncherItemDelegate>(item_delegate).Pass());
1868 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
1869 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
1870 } 1835 }
1871 1836
1872 void ChromeLauncherController::AttachProfile(Profile* profile) { 1837 void ChromeLauncherController::AttachProfile(Profile* profile) {
1873 profile_ = profile; 1838 profile_ = profile;
1874 // Either add the profile to the list of known profiles and make it the active 1839 // Either add the profile to the list of known profiles and make it the active
1875 // one for some functions of AppTabHelper or create a new one. 1840 // one for some functions of AppTabHelper or create a new one.
1876 if (!app_tab_helper_.get()) 1841 if (!app_tab_helper_.get())
1877 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); 1842 app_tab_helper_.reset(new LauncherAppTabHelper(profile_));
1878 else 1843 else
1879 app_tab_helper_->SetCurrentUser(profile_); 1844 app_tab_helper_->SetCurrentUser(profile_);
(...skipping 26 matching lines...) Expand all
1906 } 1871 }
1907 1872
1908 void ChromeLauncherController::ReleaseProfile() { 1873 void ChromeLauncherController::ReleaseProfile() {
1909 if (app_sync_ui_state_) 1874 if (app_sync_ui_state_)
1910 app_sync_ui_state_->RemoveObserver(this); 1875 app_sync_ui_state_->RemoveObserver(this);
1911 1876
1912 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 1877 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
1913 1878
1914 pref_change_registrar_.RemoveAll(); 1879 pref_change_registrar_.RemoveAll();
1915 } 1880 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698