Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/extensions/extension_app_icon_loader.h" | |
| 8 #include "chrome/browser/profiles/profile_manager.h" | |
| 9 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | |
| 10 #include "chrome/browser/ui/ash/ash_util.h" | |
| 11 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | |
| 12 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | |
| 13 #include "content/public/common/service_manager_connection.h" | |
| 14 #include "services/shell/public/cpp/connector.h" | |
| 15 #include "ui/display/display.h" | |
| 16 #include "ui/display/screen.h" | |
| 17 | |
| 7 // static | 18 // static |
| 8 ChromeLauncherController* ChromeLauncherController::instance_ = nullptr; | 19 ChromeLauncherController* ChromeLauncherController::instance_ = nullptr; |
| 9 | 20 |
| 10 ChromeLauncherController::~ChromeLauncherController() { | 21 ChromeLauncherController::~ChromeLauncherController() { |
| 11 if (instance_ == this) | 22 if (instance_ == this) |
| 12 instance_ = nullptr; | 23 instance_ = nullptr; |
| 13 } | 24 } |
| 14 | 25 |
| 15 ChromeLauncherController::ChromeLauncherController() {} | 26 void ChromeLauncherController::LaunchApp(const std::string& app_id, |
| 27 ash::LaunchSource source, | |
| 28 int event_flags) { | |
| 29 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); | |
| 30 } | |
| 31 | |
| 32 ChromeLauncherController::ChromeLauncherController() : observer_binding_(this) { | |
|
sky
2016/10/07 16:10:18
Initialize profile_ to null?
msw
2016/10/07 22:45:58
Done in header.
| |
| 33 // Start observing the shelf controller immediately. | |
| 34 if (ConnectToShelfController()) { | |
| 35 ash::mojom::ShelfObserverAssociatedPtrInfo ptr_info; | |
| 36 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); | |
| 37 shelf_controller_->AddObserver(std::move(ptr_info)); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 bool ChromeLauncherController::ConnectToShelfController() { | |
| 42 if (shelf_controller_.is_bound()) | |
| 43 return true; | |
| 44 | |
| 45 shell::Connector* connector = | |
| 46 content::ServiceManagerConnection::GetForProcess()->GetConnector(); | |
| 47 // Unit tests may not have a connector. | |
| 48 if (!connector) | |
| 49 return false; | |
| 50 | |
| 51 // Under mash the ShelfController interface is in the ash process. In classic | |
| 52 // ash we provide it to ourself. | |
| 53 if (chrome::IsRunningInMash()) { | |
| 54 connector->ConnectToInterface("service:ash", &shelf_controller_); | |
| 55 } else { | |
| 56 connector->ConnectToInterface("service:content_browser", | |
| 57 &shelf_controller_); | |
| 58 } | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | |
| 63 const std::string& app_id) { | |
| 64 for (const auto& app_icon_loader : app_icon_loaders_) { | |
| 65 if (app_icon_loader->CanLoadImageForApp(app_id)) | |
| 66 return app_icon_loader.get(); | |
| 67 } | |
| 68 | |
| 69 return nullptr; | |
| 70 } | |
| 71 | |
| 72 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { | |
| 73 if (!ConnectToShelfController()) | |
| 74 return; | |
| 75 | |
| 76 // The pref helper functions return default values for invalid display ids. | |
| 77 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | |
| 78 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { | |
| 79 shelf_controller_->SetAutoHideBehavior( | |
| 80 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display.id()), | |
| 81 display.id()); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void ChromeLauncherController::SetShelfAlignmentFromPrefs() { | |
| 86 if (!ConnectToShelfController()) | |
| 87 return; | |
| 88 | |
| 89 // The pref helper functions return default values for invalid display ids. | |
| 90 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | |
| 91 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { | |
| 92 shelf_controller_->SetAlignment( | |
| 93 ash::launcher::GetShelfAlignmentPref(prefs, display.id()), | |
| 94 display.id()); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void ChromeLauncherController::SetShelfBehaviorsFromPrefs() { | |
| 99 SetShelfAutoHideBehaviorFromPrefs(); | |
| 100 SetShelfAlignmentFromPrefs(); | |
| 101 } | |
| 102 | |
| 103 void ChromeLauncherController::SetLauncherControllerHelperForTest( | |
| 104 std::unique_ptr<LauncherControllerHelper> helper) { | |
| 105 launcher_controller_helper_ = std::move(helper); | |
| 106 } | |
| 107 | |
| 108 void ChromeLauncherController::SetAppIconLoadersForTest( | |
| 109 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { | |
| 110 app_icon_loaders_.clear(); | |
| 111 for (auto& loader : loaders) | |
| 112 app_icon_loaders_.push_back(std::move(loader)); | |
| 113 } | |
| 114 | |
| 115 void ChromeLauncherController::SetProfileForTest(Profile* profile) { | |
| 116 profile_ = profile; | |
| 117 } | |
| 118 | |
| 119 void ChromeLauncherController::AttachProfile(Profile* profile) { | |
| 120 profile_ = profile; | |
| 121 // Either add the profile to the list of known profiles and make it the active | |
| 122 // one for some functions of LauncherControllerHelper or create a new one. | |
| 123 if (!launcher_controller_helper_.get()) | |
| 124 launcher_controller_helper_.reset(new LauncherControllerHelper(profile_)); | |
|
sky
2016/10/07 16:10:17
MakeUnique
msw
2016/10/07 22:45:57
Done.
| |
| 125 else | |
| 126 launcher_controller_helper_->SetCurrentUser(profile_); | |
| 127 | |
| 128 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded | |
| 129 // image is associated with a profile (its loader requires the profile). | |
| 130 // Since icon size changes are possible, the icon could be requested to be | |
| 131 // reloaded. However - having it not multi profile aware would cause problems | |
| 132 // if the icon cache gets deleted upon user switch. | |
| 133 std::unique_ptr<AppIconLoader> extension_app_icon_loader( | |
| 134 new extensions::ExtensionAppIconLoader( | |
|
sky
2016/10/07 16:10:18
MakeUnique
msw
2016/10/07 22:45:57
Done.
| |
| 135 profile, extension_misc::EXTENSION_ICON_SMALL, this)); | |
| 136 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); | |
| 137 | |
| 138 if (arc::ArcAuthService::IsAllowedForProfile(profile)) { | |
| 139 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( | |
| 140 profile, extension_misc::EXTENSION_ICON_SMALL, this)); | |
| 141 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void ChromeLauncherController::OnShelfCreated(int64_t display_id) { | |
| 146 if (!ConnectToShelfController()) | |
| 147 return; | |
| 148 | |
| 149 // The pref helper functions return default values for invalid display ids. | |
| 150 PrefService* prefs = profile_->GetPrefs(); | |
| 151 shelf_controller_->SetAlignment( | |
| 152 ash::launcher::GetShelfAlignmentPref(prefs, display_id), display_id); | |
| 153 shelf_controller_->SetAutoHideBehavior( | |
| 154 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display_id), | |
| 155 display_id); | |
| 156 } | |
| 157 | |
| 158 void ChromeLauncherController::OnAlignmentChanged(ash::ShelfAlignment alignment, | |
| 159 int64_t display_id) { | |
| 160 // The locked alignment is set temporarily and not saved to preferences. | |
| 161 if (alignment == ash::SHELF_ALIGNMENT_BOTTOM_LOCKED) | |
| 162 return; | |
| 163 // This will uselessly store a preference value for invalid display ids. | |
| 164 // TODO(msw): Avoid handling this pref change and forwarding the value to ash. | |
| 165 ash::launcher::SetShelfAlignmentPref(profile_->GetPrefs(), display_id, | |
| 166 alignment); | |
| 167 } | |
| 168 | |
| 169 void ChromeLauncherController::OnAutoHideBehaviorChanged( | |
| 170 ash::ShelfAutoHideBehavior auto_hide, | |
| 171 int64_t display_id) { | |
| 172 // This will uselessly store a preference value for invalid display ids. | |
| 173 // TODO(msw): Avoid handling this pref change and forwarding the value to ash. | |
| 174 ash::launcher::SetShelfAutoHideBehaviorPref(profile_->GetPrefs(), display_id, | |
| 175 auto_hide); | |
| 176 } | |
| 177 | |
| 178 void ChromeLauncherController::OnAppImageUpdated(const std::string& app_id, | |
| 179 const gfx::ImageSkia& image) { | |
| 180 // Implemented by subclasses; this should not be called. | |
| 181 NOTREACHED(); | |
| 182 } | |
| OLD | NEW |