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

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

Issue 97173003: ash: Rename more Launcher classes to Shelf*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: link chrome Created 7 years 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"
11 #include "ash/launcher/launcher.h" 11 #include "ash/launcher/launcher.h"
12 #include "ash/launcher/launcher_item_delegate_manager.h"
13 #include "ash/multi_profile_uma.h" 12 #include "ash/multi_profile_uma.h"
14 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/shelf/shelf_item_delegate_manager.h"
15 #include "ash/shelf/shelf_layout_manager.h" 15 #include "ash/shelf/shelf_layout_manager.h"
16 #include "ash/shelf/shelf_model.h" 16 #include "ash/shelf/shelf_model.h"
17 #include "ash/shelf/shelf_widget.h" 17 #include "ash/shelf/shelf_widget.h"
18 #include "ash/shell.h" 18 #include "ash/shell.h"
19 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
20 #include "base/command_line.h" 20 #include "base/command_line.h"
21 #include "base/prefs/scoped_user_pref_update.h" 21 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/values.h" 24 #include "base/values.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // launcher of status changes. 374 // launcher of status changes.
375 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); 375 browser_status_monitor_.reset(new BrowserStatusMonitor(this));
376 shell_window_controller_.reset(new ShellWindowLauncherController(this)); 376 shell_window_controller_.reset(new ShellWindowLauncherController(this));
377 #endif 377 #endif
378 378
379 // Right now ash::Shell isn't created for tests. 379 // Right now ash::Shell isn't created for tests.
380 // TODO(mukai): Allows it to observe display change and write tests. 380 // TODO(mukai): Allows it to observe display change and write tests.
381 if (ash::Shell::HasInstance()) { 381 if (ash::Shell::HasInstance()) {
382 ash::Shell::GetInstance()->display_controller()->AddObserver(this); 382 ash::Shell::GetInstance()->display_controller()->AddObserver(this);
383 item_delegate_manager_ = 383 item_delegate_manager_ =
384 ash::Shell::GetInstance()->launcher_item_delegate_manager(); 384 ash::Shell::GetInstance()->shelf_item_delegate_manager();
385 } 385 }
386 386
387 notification_registrar_.Add(this, 387 notification_registrar_.Add(this,
388 chrome::NOTIFICATION_EXTENSION_LOADED, 388 chrome::NOTIFICATION_EXTENSION_LOADED,
389 content::Source<Profile>(profile_)); 389 content::Source<Profile>(profile_));
390 notification_registrar_.Add(this, 390 notification_registrar_.Add(this,
391 chrome::NOTIFICATION_EXTENSION_UNLOADED, 391 chrome::NOTIFICATION_EXTENSION_UNLOADED,
392 content::Source<Profile>(profile_)); 392 content::Source<Profile>(profile_));
393 } 393 }
394 394
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 void ChromeLauncherController::SetItemController( 493 void ChromeLauncherController::SetItemController(
494 ash::LauncherID id, 494 ash::LauncherID id,
495 LauncherItemController* controller) { 495 LauncherItemController* controller) {
496 CHECK(controller); 496 CHECK(controller);
497 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 497 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
498 CHECK(iter != id_to_item_controller_map_.end()); 498 CHECK(iter != id_to_item_controller_map_.end());
499 controller->set_launcher_id(id); 499 controller->set_launcher_id(id);
500 iter->second = controller; 500 iter->second = controller;
501 // Existing controller is destroyed and replaced by registering again. 501 // Existing controller is destroyed and replaced by registering again.
502 SetLauncherItemDelegate(id, controller); 502 SetShelfItemDelegate(id, controller);
503 } 503 }
504 504
505 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { 505 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) {
506 CHECK(id); 506 CHECK(id);
507 if (IsPinned(id)) { 507 if (IsPinned(id)) {
508 // Create a new shortcut controller. 508 // Create a new shortcut controller.
509 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 509 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
510 CHECK(iter != id_to_item_controller_map_.end()); 510 CHECK(iter != id_to_item_controller_map_.end());
511 SetItemStatus(id, ash::STATUS_CLOSED); 511 SetItemStatus(id, ash::STATUS_CLOSED);
512 std::string app_id = iter->second->app_id(); 512 std::string app_id = iter->second->app_id();
513 iter->second = new AppShortcutLauncherItemController(app_id, this); 513 iter->second = new AppShortcutLauncherItemController(app_id, this);
514 iter->second->set_launcher_id(id); 514 iter->second->set_launcher_id(id);
515 // Existing controller is destroyed and replaced by registering again. 515 // Existing controller is destroyed and replaced by registering again.
516 SetLauncherItemDelegate(id, iter->second); 516 SetShelfItemDelegate(id, iter->second);
517 } else { 517 } else {
518 LauncherItemClosed(id); 518 LauncherItemClosed(id);
519 } 519 }
520 } 520 }
521 521
522 void ChromeLauncherController::Pin(ash::LauncherID id) { 522 void ChromeLauncherController::Pin(ash::LauncherID id) {
523 DCHECK(HasItemController(id)); 523 DCHECK(HasItemController(id));
524 524
525 int index = model_->ItemIndexByID(id); 525 int index = model_->ItemIndexByID(id);
526 DCHECK_GE(index, 0); 526 DCHECK_GE(index, 0);
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 void ChromeLauncherController::SetAppIconLoaderForTest( 1376 void ChromeLauncherController::SetAppIconLoaderForTest(
1377 extensions::AppIconLoader* loader) { 1377 extensions::AppIconLoader* loader) {
1378 app_icon_loader_.reset(loader); 1378 app_icon_loader_.reset(loader);
1379 } 1379 }
1380 1380
1381 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( 1381 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest(
1382 ash::LauncherID id) { 1382 ash::LauncherID id) {
1383 return id_to_item_controller_map_[id]->app_id(); 1383 return id_to_item_controller_map_[id]->app_id();
1384 } 1384 }
1385 1385
1386 void ChromeLauncherController::SetLauncherItemDelegateManagerForTest( 1386 void ChromeLauncherController::SetShelfItemDelegateManagerForTest(
1387 ash::LauncherItemDelegateManager* manager) { 1387 ash::ShelfItemDelegateManager* manager) {
1388 item_delegate_manager_ = manager; 1388 item_delegate_manager_ = manager;
1389 } 1389 }
1390 1390
1391 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( 1391 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType(
1392 const std::string& app_id, 1392 const std::string& app_id,
1393 int index, 1393 int index,
1394 ash::LauncherItemType launcher_item_type) { 1394 ash::LauncherItemType launcher_item_type) {
1395 AppShortcutLauncherItemController* controller = 1395 AppShortcutLauncherItemController* controller =
1396 new AppShortcutLauncherItemController(app_id, this); 1396 new AppShortcutLauncherItemController(app_id, this);
1397 ash::LauncherID launcher_id = InsertAppLauncherItem( 1397 ash::LauncherID launcher_id = InsertAppLauncherItem(
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 status = ash::STATUS_ACTIVE; 1734 status = ash::STATUS_ACTIVE;
1735 else 1735 else
1736 status = ash::STATUS_RUNNING; 1736 status = ash::STATUS_RUNNING;
1737 } 1737 }
1738 item.status = status; 1738 item.status = status;
1739 1739
1740 model_->AddAt(index, item); 1740 model_->AddAt(index, item);
1741 1741
1742 app_icon_loader_->FetchImage(app_id); 1742 app_icon_loader_->FetchImage(app_id);
1743 1743
1744 SetLauncherItemDelegate(id, controller); 1744 SetShelfItemDelegate(id, controller);
1745 1745
1746 return id; 1746 return id;
1747 } 1747 }
1748 1748
1749 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { 1749 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const {
1750 return id_to_item_controller_map_.find(id) != 1750 return id_to_item_controller_map_.find(id) !=
1751 id_to_item_controller_map_.end(); 1751 id_to_item_controller_map_.end();
1752 } 1752 }
1753 1753
1754 std::vector<content::WebContents*> 1754 std::vector<content::WebContents*>
(...skipping 26 matching lines...) Expand all
1781 ash::LauncherItem browser_shortcut; 1781 ash::LauncherItem browser_shortcut;
1782 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1782 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1783 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1783 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1784 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1784 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1785 ash::LauncherID id = model_->next_id(); 1785 ash::LauncherID id = model_->next_id();
1786 size_t index = GetChromeIconIndexForCreation(); 1786 size_t index = GetChromeIconIndexForCreation();
1787 model_->AddAt(index, browser_shortcut); 1787 model_->AddAt(index, browser_shortcut);
1788 id_to_item_controller_map_[id] = 1788 id_to_item_controller_map_[id] =
1789 new BrowserShortcutLauncherItemController(this); 1789 new BrowserShortcutLauncherItemController(this);
1790 id_to_item_controller_map_[id]->set_launcher_id(id); 1790 id_to_item_controller_map_[id]->set_launcher_id(id);
1791 // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController. 1791 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController.
1792 SetLauncherItemDelegate(id, id_to_item_controller_map_[id]); 1792 SetShelfItemDelegate(id, id_to_item_controller_map_[id]);
1793 return id; 1793 return id;
1794 } 1794 }
1795 1795
1796 void ChromeLauncherController::PersistChromeItemIndex(int index) { 1796 void ChromeLauncherController::PersistChromeItemIndex(int index) {
1797 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); 1797 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
1798 } 1798 }
1799 1799
1800 int ChromeLauncherController::GetChromeIconIndexFromPref() const { 1800 int ChromeLauncherController::GetChromeIconIndexFromPref() const {
1801 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); 1801 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex);
1802 const base::ListValue* pinned_apps_pref = 1802 const base::ListValue* pinned_apps_pref =
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 browser_to_close.push_back(browser); 1957 browser_to_close.push_back(browser);
1958 } 1958 }
1959 } 1959 }
1960 while (!browser_to_close.empty()) { 1960 while (!browser_to_close.empty()) {
1961 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 1961 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
1962 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 1962 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
1963 browser_to_close.pop_back(); 1963 browser_to_close.pop_back();
1964 } 1964 }
1965 } 1965 }
1966 1966
1967 void ChromeLauncherController::SetLauncherItemDelegate( 1967 void ChromeLauncherController::SetShelfItemDelegate(
1968 ash::LauncherID id, 1968 ash::LauncherID id,
1969 ash::LauncherItemDelegate* item_delegate) { 1969 ash::ShelfItemDelegate* item_delegate) {
1970 DCHECK_GT(id, 0); 1970 DCHECK_GT(id, 0);
1971 DCHECK(item_delegate); 1971 DCHECK(item_delegate);
1972 DCHECK(item_delegate_manager_); 1972 DCHECK(item_delegate_manager_);
1973 item_delegate_manager_->SetLauncherItemDelegate(id, 1973 item_delegate_manager_->SetShelfItemDelegate(
1974 scoped_ptr<ash::LauncherItemDelegate>(item_delegate).Pass()); 1974 id, scoped_ptr<ash::ShelfItemDelegate>(item_delegate).Pass());
1975 } 1975 }
1976 1976
1977 void ChromeLauncherController::AttachProfile(Profile* profile) { 1977 void ChromeLauncherController::AttachProfile(Profile* profile) {
1978 profile_ = profile; 1978 profile_ = profile;
1979 // Either add the profile to the list of known profiles and make it the active 1979 // Either add the profile to the list of known profiles and make it the active
1980 // one for some functions of AppTabHelper or create a new one. 1980 // one for some functions of AppTabHelper or create a new one.
1981 if (!app_tab_helper_.get()) 1981 if (!app_tab_helper_.get())
1982 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); 1982 app_tab_helper_.reset(new LauncherAppTabHelper(profile_));
1983 else 1983 else
1984 app_tab_helper_->SetCurrentUser(profile_); 1984 app_tab_helper_->SetCurrentUser(profile_);
(...skipping 26 matching lines...) Expand all
2011 } 2011 }
2012 2012
2013 void ChromeLauncherController::ReleaseProfile() { 2013 void ChromeLauncherController::ReleaseProfile() {
2014 if (app_sync_ui_state_) 2014 if (app_sync_ui_state_)
2015 app_sync_ui_state_->RemoveObserver(this); 2015 app_sync_ui_state_->RemoveObserver(this);
2016 2016
2017 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 2017 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
2018 2018
2019 pref_change_registrar_.RemoveAll(); 2019 pref_change_registrar_.RemoveAll();
2020 } 2020 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698