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

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

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 #if defined(OS_CHROMEOS) 453 #if defined(OS_CHROMEOS)
454 // On Chrome OS using multi profile we want to switch the content of the shelf 454 // On Chrome OS using multi profile we want to switch the content of the shelf
455 // with a user change. Note that for unit tests the instance can be NULL. 455 // with a user change. Note that for unit tests the instance can be NULL.
456 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != 456 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
457 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) { 457 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) {
458 user_switch_observer_.reset( 458 user_switch_observer_.reset(
459 new ChromeLauncherControllerUserSwitchObserver(this)); 459 new ChromeLauncherControllerUserSwitchObserver(this));
460 } 460 }
461 461
462 scoped_ptr<AppWindowLauncherController> extension_app_window_controller; 462 std::unique_ptr<AppWindowLauncherController> extension_app_window_controller;
463 // Create our v1/v2 application / browser monitors which will inform the 463 // Create our v1/v2 application / browser monitors which will inform the
464 // launcher of status changes. 464 // launcher of status changes.
465 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == 465 if (chrome::MultiUserWindowManager::GetMultiProfileMode() ==
466 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { 466 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) {
467 // If running in separated destkop mode, we create the multi profile version 467 // If running in separated destkop mode, we create the multi profile version
468 // of status monitor. 468 // of status monitor.
469 browser_status_monitor_.reset(new MultiProfileBrowserStatusMonitor(this)); 469 browser_status_monitor_.reset(new MultiProfileBrowserStatusMonitor(this));
470 extension_app_window_controller.reset( 470 extension_app_window_controller.reset(
471 new MultiProfileAppWindowLauncherController(this)); 471 new MultiProfileAppWindowLauncherController(this));
472 } else { 472 } else {
473 // Create our v1/v2 application / browser monitors which will inform the 473 // Create our v1/v2 application / browser monitors which will inform the
474 // launcher of status changes. 474 // launcher of status changes.
475 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); 475 browser_status_monitor_.reset(new BrowserStatusMonitor(this));
476 extension_app_window_controller.reset( 476 extension_app_window_controller.reset(
477 new ExtensionAppWindowLauncherController(this)); 477 new ExtensionAppWindowLauncherController(this));
478 } 478 }
479 app_window_controllers_.push_back(std::move(extension_app_window_controller)); 479 app_window_controllers_.push_back(std::move(extension_app_window_controller));
480 480
481 scoped_ptr<AppWindowLauncherController> arc_app_window_controller; 481 std::unique_ptr<AppWindowLauncherController> arc_app_window_controller;
482 arc_app_window_controller.reset(new ArcAppWindowLauncherController(this)); 482 arc_app_window_controller.reset(new ArcAppWindowLauncherController(this));
483 app_window_controllers_.push_back(std::move(arc_app_window_controller)); 483 app_window_controllers_.push_back(std::move(arc_app_window_controller));
484 #else 484 #else
485 // Create our v1/v2 application / browser monitors which will inform the 485 // Create our v1/v2 application / browser monitors which will inform the
486 // launcher of status changes. 486 // launcher of status changes.
487 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); 487 browser_status_monitor_.reset(new BrowserStatusMonitor(this));
488 scoped_ptr<AppWindowLauncherController> extension_app_window_controller; 488 std::unique_ptr<AppWindowLauncherController> extension_app_window_controller;
489 extension_app_window_controller.reset( 489 extension_app_window_controller.reset(
490 new ExtensionAppWindowLauncherController(this)); 490 new ExtensionAppWindowLauncherController(this));
491 app_window_controllers_.push_back(std::move(extension_app_window_controller)); 491 app_window_controllers_.push_back(std::move(extension_app_window_controller));
492 #endif 492 #endif
493 493
494 // Right now ash::Shell isn't created for tests. 494 // Right now ash::Shell isn't created for tests.
495 // TODO(mukai): Allows it to observe display change and write tests. 495 // TODO(mukai): Allows it to observe display change and write tests.
496 if (ash::Shell::HasInstance()) { 496 if (ash::Shell::HasInstance()) {
497 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 497 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
498 // If it got already set, we remove the observer first again and swap the 498 // If it got already set, we remove the observer first again and swap the
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 // If there is an existing non-shortcut controller for this app, open it. 811 // If there is an existing non-shortcut controller for this app, open it.
812 ash::ShelfID id = GetShelfIDForAppID(app_id); 812 ash::ShelfID id = GetShelfIDForAppID(app_id);
813 if (id) { 813 if (id) {
814 LauncherItemController* controller = GetLauncherItemController(id); 814 LauncherItemController* controller = GetLauncherItemController(id);
815 controller->Activate(source); 815 controller->Activate(source);
816 return; 816 return;
817 } 817 }
818 818
819 // Create a temporary application launcher item and use it to see if there are 819 // Create a temporary application launcher item and use it to see if there are
820 // running instances. 820 // running instances.
821 scoped_ptr<AppShortcutLauncherItemController> app_controller( 821 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
822 new AppShortcutLauncherItemController(app_id, this)); 822 new AppShortcutLauncherItemController(app_id, this));
823 if (!app_controller->GetRunningApplications().empty()) 823 if (!app_controller->GetRunningApplications().empty())
824 app_controller->Activate(source); 824 app_controller->Activate(source);
825 else 825 else
826 LaunchApp(app_id, source, event_flags); 826 LaunchApp(app_id, source, event_flags);
827 } 827 }
828 828
829 extensions::LaunchType ChromeLauncherController::GetLaunchType( 829 extensions::LaunchType ChromeLauncherController::GetLaunchType(
830 ash::ShelfID id) { 830 ash::ShelfID id) {
831 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id)); 831 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 if (ignore_persist_pinned_state_change_) 968 if (ignore_persist_pinned_state_change_)
969 return; 969 return;
970 // It is a coding error to call PersistPinnedState() if the pinned apps are 970 // It is a coding error to call PersistPinnedState() if the pinned apps are
971 // not user-editable. The code should check earlier and not perform any 971 // not user-editable. The code should check earlier and not perform any
972 // modification actions that trigger persisting the state. 972 // modification actions that trigger persisting the state.
973 // Mutating kPinnedLauncherApps is going to notify us and trigger us to 973 // Mutating kPinnedLauncherApps is going to notify us and trigger us to
974 // process the change. We don't want that to happen so remove ourselves as a 974 // process the change. We don't want that to happen so remove ourselves as a
975 // listener. 975 // listener.
976 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps); 976 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps);
977 { 977 {
978 scoped_ptr<const base::ListValue> pinned_apps_pref = 978 std::unique_ptr<const base::ListValue> pinned_apps_pref =
979 profile_->GetPrefs() 979 profile_->GetPrefs()
980 ->GetList(prefs::kPinnedLauncherApps) 980 ->GetList(prefs::kPinnedLauncherApps)
981 ->CreateDeepCopy(); 981 ->CreateDeepCopy();
982 982
983 const base::ListValue* policy_pinned_apps_pref = 983 const base::ListValue* policy_pinned_apps_pref =
984 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); 984 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
985 985
986 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); 986 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
987 updater->Clear(); 987 updater->Clear();
988 for (size_t i = 0; i < model_->items().size(); ++i) { 988 for (size_t i = 0; i < model_->items().size(); ++i) {
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 return CreateAppShortcutLauncherItemWithType(app_id, 1458 return CreateAppShortcutLauncherItemWithType(app_id,
1459 index, 1459 index,
1460 ash::TYPE_APP_SHORTCUT); 1460 ash::TYPE_APP_SHORTCUT);
1461 } 1461 }
1462 1462
1463 void ChromeLauncherController::SetAppTabHelperForTest(AppTabHelper* helper) { 1463 void ChromeLauncherController::SetAppTabHelperForTest(AppTabHelper* helper) {
1464 app_tab_helper_.reset(helper); 1464 app_tab_helper_.reset(helper);
1465 } 1465 }
1466 1466
1467 void ChromeLauncherController::SetAppIconLoadersForTest( 1467 void ChromeLauncherController::SetAppIconLoadersForTest(
1468 std::vector<scoped_ptr<AppIconLoader>>& loaders) { 1468 std::vector<std::unique_ptr<AppIconLoader>>& loaders) {
1469 app_icon_loaders_.clear(); 1469 app_icon_loaders_.clear();
1470 for (auto& loader : loaders) 1470 for (auto& loader : loaders)
1471 app_icon_loaders_.push_back(std::move(loader)); 1471 app_icon_loaders_.push_back(std::move(loader));
1472 } 1472 }
1473 1473
1474 const std::string& ChromeLauncherController::GetAppIdFromShelfIdForTest( 1474 const std::string& ChromeLauncherController::GetAppIdFromShelfIdForTest(
1475 ash::ShelfID id) { 1475 ash::ShelfID id) {
1476 return id_to_item_controller_map_[id]->app_id(); 1476 return id_to_item_controller_map_[id]->app_id();
1477 } 1477 }
1478 1478
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 } 2141 }
2142 } 2142 }
2143 2143
2144 void ChromeLauncherController::SetShelfItemDelegate( 2144 void ChromeLauncherController::SetShelfItemDelegate(
2145 ash::ShelfID id, 2145 ash::ShelfID id,
2146 ash::ShelfItemDelegate* item_delegate) { 2146 ash::ShelfItemDelegate* item_delegate) {
2147 DCHECK_GT(id, 0); 2147 DCHECK_GT(id, 0);
2148 DCHECK(item_delegate); 2148 DCHECK(item_delegate);
2149 DCHECK(item_delegate_manager_); 2149 DCHECK(item_delegate_manager_);
2150 item_delegate_manager_->SetShelfItemDelegate( 2150 item_delegate_manager_->SetShelfItemDelegate(
2151 id, scoped_ptr<ash::ShelfItemDelegate>(item_delegate)); 2151 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate));
2152 } 2152 }
2153 2153
2154 void ChromeLauncherController::AttachProfile(Profile* profile) { 2154 void ChromeLauncherController::AttachProfile(Profile* profile) {
2155 profile_ = profile; 2155 profile_ = profile;
2156 // Either add the profile to the list of known profiles and make it the active 2156 // Either add the profile to the list of known profiles and make it the active
2157 // one for some functions of AppTabHelper or create a new one. 2157 // one for some functions of AppTabHelper or create a new one.
2158 if (!app_tab_helper_.get()) 2158 if (!app_tab_helper_.get())
2159 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); 2159 app_tab_helper_.reset(new LauncherAppTabHelper(profile_));
2160 else 2160 else
2161 app_tab_helper_->SetCurrentUser(profile_); 2161 app_tab_helper_->SetCurrentUser(profile_);
2162 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded 2162 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
2163 // image is associated with a profile (it's loader requires the profile). 2163 // image is associated with a profile (it's loader requires the profile).
2164 // Since icon size changes are possible, the icon could be requested to be 2164 // Since icon size changes are possible, the icon could be requested to be
2165 // reloaded. However - having it not multi profile aware would cause problems 2165 // reloaded. However - having it not multi profile aware would cause problems
2166 // if the icon cache gets deleted upon user switch. 2166 // if the icon cache gets deleted upon user switch.
2167 scoped_ptr<AppIconLoader> extension_app_icon_loader( 2167 std::unique_ptr<AppIconLoader> extension_app_icon_loader(
2168 new extensions::ExtensionAppIconLoader( 2168 new extensions::ExtensionAppIconLoader(
2169 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); 2169 profile_, extension_misc::EXTENSION_ICON_SMALL, this));
2170 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); 2170 app_icon_loaders_.push_back(std::move(extension_app_icon_loader));
2171 2171
2172 #if defined(OS_CHROMEOS) 2172 #if defined(OS_CHROMEOS)
2173 scoped_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( 2173 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader(
2174 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); 2174 profile_, extension_misc::EXTENSION_ICON_SMALL, this));
2175 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); 2175 app_icon_loaders_.push_back(std::move(arc_app_icon_loader));
2176 #endif 2176 #endif
2177 2177
2178 pref_change_registrar_.Init(profile_->GetPrefs()); 2178 pref_change_registrar_.Init(profile_->GetPrefs());
2179 pref_change_registrar_.Add( 2179 pref_change_registrar_.Add(
2180 prefs::kPinnedLauncherApps, 2180 prefs::kPinnedLauncherApps,
2181 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, 2181 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
2182 base::Unretained(this))); 2182 base::Unretained(this)));
2183 pref_change_registrar_.Add( 2183 pref_change_registrar_.Add(
(...skipping 13 matching lines...) Expand all
2197 prefs::kShelfPreferences, 2197 prefs::kShelfPreferences,
2198 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, 2198 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
2199 base::Unretained(this))); 2199 base::Unretained(this)));
2200 #if defined(OS_CHROMEOS) 2200 #if defined(OS_CHROMEOS)
2201 pref_change_registrar_.Add( 2201 pref_change_registrar_.Add(
2202 prefs::kTouchVirtualKeyboardEnabled, 2202 prefs::kTouchVirtualKeyboardEnabled,
2203 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs, 2203 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs,
2204 base::Unretained(this))); 2204 base::Unretained(this)));
2205 #endif // defined(OS_CHROMEOS) 2205 #endif // defined(OS_CHROMEOS)
2206 2206
2207 scoped_ptr<LauncherAppUpdater> extension_app_updater( 2207 std::unique_ptr<LauncherAppUpdater> extension_app_updater(
2208 new LauncherExtensionAppUpdater(this, profile_)); 2208 new LauncherExtensionAppUpdater(this, profile_));
2209 app_updaters_.push_back(std::move(extension_app_updater)); 2209 app_updaters_.push_back(std::move(extension_app_updater));
2210 2210
2211 #if defined(OS_CHROMEOS) 2211 #if defined(OS_CHROMEOS)
2212 scoped_ptr<LauncherAppUpdater> arc_app_updater( 2212 std::unique_ptr<LauncherAppUpdater> arc_app_updater(
2213 new LauncherArcAppUpdater(this, profile_)); 2213 new LauncherArcAppUpdater(this, profile_));
2214 app_updaters_.push_back(std::move(arc_app_updater)); 2214 app_updaters_.push_back(std::move(arc_app_updater));
2215 #endif 2215 #endif
2216 } 2216 }
2217 2217
2218 void ChromeLauncherController::ReleaseProfile() { 2218 void ChromeLauncherController::ReleaseProfile() {
2219 if (app_sync_ui_state_) 2219 if (app_sync_ui_state_)
2220 app_sync_ui_state_->RemoveObserver(this); 2220 app_sync_ui_state_->RemoveObserver(this);
2221 2221
2222 app_updaters_.clear(); 2222 app_updaters_.clear();
2223 2223
2224 PrefServiceSyncableFromProfile(profile_)->RemoveObserver(this); 2224 PrefServiceSyncableFromProfile(profile_)->RemoveObserver(this);
2225 2225
2226 pref_change_registrar_.RemoveAll(); 2226 pref_change_registrar_.RemoveAll();
2227 } 2227 }
2228 2228
2229 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( 2229 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp(
2230 const std::string& app_id) { 2230 const std::string& app_id) {
2231 for (const auto& app_icon_loader : app_icon_loaders_) { 2231 for (const auto& app_icon_loader : app_icon_loaders_) {
2232 if (app_icon_loader->CanLoadImageForApp(app_id)) 2232 if (app_icon_loader->CanLoadImageForApp(app_id))
2233 return app_icon_loader.get(); 2233 return app_icon_loader.get();
2234 } 2234 }
2235 2235
2236 return nullptr; 2236 return nullptr;
2237 } 2237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698