OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
6 | 6 |
7 #include <stdint.h> | |
8 #include <numeric> | |
9 #include <utility> | 7 #include <utility> |
10 #include <vector> | |
11 | 8 |
12 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
13 #include "ash/common/wallpaper/wallpaper_controller.h" | 10 #include "ash/common/wallpaper/wallpaper_controller.h" |
14 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
15 #include "ash/public/interfaces/wallpaper.mojom.h" | |
16 #include "base/bind.h" | 12 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
18 #include "base/command_line.h" | 14 #include "base/command_line.h" |
19 #include "base/files/file_enumerator.h" | |
20 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
21 #include "base/files/file_util.h" | |
22 #include "base/logging.h" | 16 #include "base/logging.h" |
23 #include "base/macros.h" | |
24 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
25 #include "base/path_service.h" | |
26 #include "base/sha1.h" | 18 #include "base/sha1.h" |
27 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/string_util.h" | |
29 #include "base/strings/stringprintf.h" | |
30 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
31 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
32 #include "base/time/time.h" | 22 #include "base/time/time.h" |
33 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
34 #include "base/values.h" | 24 #include "base/values.h" |
35 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
36 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
37 #include "chrome/browser/chromeos/customization/customization_document.h" | 27 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 28 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" |
38 #include "chrome/browser/chromeos/login/startup_utils.h" | 29 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 30 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" |
39 #include "chrome/browser/chromeos/login/wizard_controller.h" | 31 #include "chrome/browser/chromeos/login/wizard_controller.h" |
40 #include "chrome/browser/chromeos/settings/cros_settings.h" | 32 #include "chrome/browser/image_decoder.h" |
41 #include "chrome/browser/ui/ash/ash_util.h" | 33 #include "chrome/browser/ui/ash/ash_util.h" |
42 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
43 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
45 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
46 #include "chromeos/cryptohome/system_salt_getter.h" | 38 #include "chromeos/cryptohome/system_salt_getter.h" |
47 #include "chromeos/dbus/dbus_thread_manager.h" | |
48 #include "chromeos/login/user_names.h" | 39 #include "chromeos/login/user_names.h" |
49 #include "components/prefs/pref_registry_simple.h" | 40 #include "components/prefs/pref_registry_simple.h" |
50 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
51 #include "components/prefs/scoped_user_pref_update.h" | 42 #include "components/prefs/scoped_user_pref_update.h" |
52 #include "components/signin/core/account_id/account_id.h" | 43 #include "components/signin/core/account_id/account_id.h" |
53 #include "components/user_manager/known_user.h" | 44 #include "components/user_manager/known_user.h" |
54 #include "components/user_manager/user.h" | |
55 #include "components/user_manager/user_image/user_image.h" | |
56 #include "components/user_manager/user_manager.h" | |
57 #include "components/user_manager/user_type.h" | 45 #include "components/user_manager/user_type.h" |
58 #include "components/wallpaper/wallpaper_files_id.h" | 46 #include "components/wallpaper/wallpaper_files_id.h" |
59 #include "components/wallpaper/wallpaper_layout.h" | 47 #include "components/wallpaper/wallpaper_layout.h" |
60 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
61 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
62 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
63 #include "content/public/common/service_manager_connection.h" | 51 #include "content/public/common/service_manager_connection.h" |
64 #include "services/service_manager/public/cpp/connector.h" | 52 #include "services/service_manager/public/cpp/connector.h" |
65 #include "third_party/skia/include/core/SkColor.h" | |
66 #include "ui/gfx/codec/jpeg_codec.h" | |
67 #include "ui/gfx/image/image_skia_operations.h" | |
68 #include "ui/gfx/skia_util.h" | |
69 | 53 |
70 using content::BrowserThread; | 54 using content::BrowserThread; |
71 using wallpaper::WallpaperManagerBase; | 55 using wallpaper::WallpaperManagerBase; |
72 using wallpaper::WallpaperInfo; | 56 using wallpaper::WallpaperInfo; |
73 using wallpaper::MovableOnDestroyCallback; | 57 using wallpaper::MovableOnDestroyCallback; |
74 using wallpaper::MovableOnDestroyCallbackHolder; | 58 using wallpaper::MovableOnDestroyCallbackHolder; |
75 | 59 |
76 namespace chromeos { | 60 namespace chromeos { |
77 | 61 |
78 namespace { | 62 namespace { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 SystemSaltGetter::Get()->AddOnSystemSaltReady(closure); | 164 SystemSaltGetter::Get()->AddOnSystemSaltReady(closure); |
181 } | 165 } |
182 | 166 |
183 void SetKnownUserWallpaperFilesId( | 167 void SetKnownUserWallpaperFilesId( |
184 const AccountId& account_id, | 168 const AccountId& account_id, |
185 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 169 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
186 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 170 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
187 wallpaper_files_id.id()); | 171 wallpaper_files_id.id()); |
188 } | 172 } |
189 | 173 |
190 ash::mojom::WallpaperLayout WallpaperLayoutToMojo( | 174 // A helper to set the wallpaper image for Classic Ash and Mash. |
191 wallpaper::WallpaperLayout layout) { | |
192 switch (layout) { | |
193 case wallpaper::WALLPAPER_LAYOUT_CENTER: | |
194 return ash::mojom::WallpaperLayout::CENTER; | |
195 case wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED: | |
196 return ash::mojom::WallpaperLayout::CENTER_CROPPED; | |
197 case wallpaper::WALLPAPER_LAYOUT_STRETCH: | |
198 return ash::mojom::WallpaperLayout::STRETCH; | |
199 case wallpaper::WALLPAPER_LAYOUT_TILE: | |
200 return ash::mojom::WallpaperLayout::TILE; | |
201 case wallpaper::NUM_WALLPAPER_LAYOUT: | |
202 NOTREACHED(); | |
203 return ash::mojom::WallpaperLayout::CENTER; | |
204 } | |
205 NOTREACHED(); | |
206 return ash::mojom::WallpaperLayout::CENTER; | |
207 } | |
208 | |
209 // A helper to set the wallpaper image for Ash and Mash. | |
210 void SetWallpaper(const gfx::ImageSkia& image, | 175 void SetWallpaper(const gfx::ImageSkia& image, |
211 wallpaper::WallpaperLayout layout) { | 176 wallpaper::WallpaperLayout layout) { |
212 if (chrome::IsRunningInMash()) { | 177 if (chrome::IsRunningInMash()) { |
| 178 // In mash, connect to the WallpaperController interface via mojo. |
213 service_manager::Connector* connector = | 179 service_manager::Connector* connector = |
214 content::ServiceManagerConnection::GetForProcess()->GetConnector(); | 180 content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 181 if (!connector) |
| 182 return; |
| 183 |
215 ash::mojom::WallpaperControllerPtr wallpaper_controller; | 184 ash::mojom::WallpaperControllerPtr wallpaper_controller; |
216 connector->ConnectToInterface("service:ash", &wallpaper_controller); | 185 connector->ConnectToInterface("service:ash", &wallpaper_controller); |
217 wallpaper_controller->SetWallpaper(*image.bitmap(), | 186 // TODO(crbug.com/655875): Optimize ash wallpaper transport; avoid sending |
218 WallpaperLayoutToMojo(layout)); | 187 // large bitmaps over Mojo; use shared memory like BitmapUploader, etc. |
219 return; | 188 wallpaper_controller->SetWallpaper(*image.bitmap(), layout); |
220 } | 189 } else if (ash::WmShell::HasInstance()) { |
221 // Avoid loading unnecessary wallpapers in tests without a shell instance. | 190 // Note: Wallpaper setting is skipped in unit tests without shell instances. |
222 if (ash::WmShell::HasInstance()) { | 191 // In classic ash, interact with the WallpaperController class directly. |
223 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, | 192 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, |
224 layout); | 193 layout); |
225 } | 194 } |
226 } | 195 } |
227 | 196 |
228 } // namespace | 197 } // namespace |
229 | 198 |
230 // This is "wallpaper either scheduled to load, or loading right now". | 199 // This is "wallpaper either scheduled to load, or loading right now". |
231 // | 200 // |
232 // While enqueued, it defines moment in the future, when it will be loaded. | 201 // While enqueued, it defines moment in the future, when it will be loaded. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 return wallpaper_manager; | 362 return wallpaper_manager; |
394 } | 363 } |
395 | 364 |
396 // static | 365 // static |
397 void WallpaperManager::Shutdown() { | 366 void WallpaperManager::Shutdown() { |
398 CHECK(wallpaper_manager); | 367 CHECK(wallpaper_manager); |
399 delete wallpaper_manager; | 368 delete wallpaper_manager; |
400 wallpaper_manager = nullptr; | 369 wallpaper_manager = nullptr; |
401 } | 370 } |
402 | 371 |
| 372 void WallpaperManager::BindRequest( |
| 373 ash::mojom::WallpaperManagerRequest request) { |
| 374 bindings_.AddBinding(this, std::move(request)); |
| 375 } |
| 376 |
403 WallpaperManager::WallpaperResolution | 377 WallpaperManager::WallpaperResolution |
404 WallpaperManager::GetAppropriateResolution() { | 378 WallpaperManager::GetAppropriateResolution() { |
405 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
406 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); | 380 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); |
407 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || | 381 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || |
408 size.height() > wallpaper::kSmallWallpaperMaxHeight) | 382 size.height() > wallpaper::kSmallWallpaperMaxHeight) |
409 ? WALLPAPER_RESOLUTION_LARGE | 383 ? WALLPAPER_RESOLUTION_LARGE |
410 : WALLPAPER_RESOLUTION_SMALL; | 384 : WALLPAPER_RESOLUTION_SMALL; |
411 } | 385 } |
412 | 386 |
413 void WallpaperManager::AddObservers() { | 387 void WallpaperManager::AddObservers() { |
414 show_user_name_on_signin_subscription_ = | 388 show_user_name_on_signin_subscription_ = |
415 CrosSettings::Get()->AddSettingsObserver( | 389 CrosSettings::Get()->AddSettingsObserver( |
416 kAccountsPrefShowUserNamesOnSignIn, | 390 kAccountsPrefShowUserNamesOnSignIn, |
417 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | 391 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
418 weak_factory_.GetWeakPtr())); | 392 weak_factory_.GetWeakPtr())); |
419 } | 393 } |
420 | 394 |
421 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 395 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
422 // Some browser tests do not have a shell instance. As no wallpaper is needed | |
423 // in these tests anyway, avoid loading one, preventing crashes and speeding | |
424 // up the tests. | |
425 if (!ash::WmShell::HasInstance()) | |
426 return; | |
427 | |
428 WallpaperInfo info; | 396 WallpaperInfo info; |
429 if (GetLoggedInUserWallpaperInfo(&info)) { | 397 if (GetLoggedInUserWallpaperInfo(&info)) { |
430 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, | 398 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, |
431 user_manager::User::WALLPAPER_TYPE_COUNT); | 399 user_manager::User::WALLPAPER_TYPE_COUNT); |
432 if (info == current_user_wallpaper_info_) | 400 if (info == current_user_wallpaper_info_) |
433 return; | 401 return; |
434 } | 402 } |
435 SetUserWallpaperNow( | 403 SetUserWallpaperNow( |
436 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId()); | 404 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId()); |
437 } | 405 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 if (!user_manager->IsUserLoggedIn()) { | 439 if (!user_manager->IsUserLoggedIn()) { |
472 if (!StartupUtils::IsDeviceRegistered()) | 440 if (!StartupUtils::IsDeviceRegistered()) |
473 SetDefaultWallpaperDelayed(login::SignInAccountId()); | 441 SetDefaultWallpaperDelayed(login::SignInAccountId()); |
474 else | 442 else |
475 InitializeRegisteredDeviceWallpaper(); | 443 InitializeRegisteredDeviceWallpaper(); |
476 return; | 444 return; |
477 } | 445 } |
478 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId()); | 446 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId()); |
479 } | 447 } |
480 | 448 |
| 449 void WallpaperManager::Open() { |
| 450 wallpaper_manager_util::OpenWallpaperManager(); |
| 451 } |
| 452 |
481 void WallpaperManager::Observe(int type, | 453 void WallpaperManager::Observe(int type, |
482 const content::NotificationSource& source, | 454 const content::NotificationSource& source, |
483 const content::NotificationDetails& details) { | 455 const content::NotificationDetails& details) { |
484 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 456 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
485 switch (type) { | 457 switch (type) { |
486 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 458 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
487 ClearDisposableWallpaperCache(); | 459 ClearDisposableWallpaperCache(); |
488 BrowserThread::PostDelayedTask( | 460 BrowserThread::PostDelayedTask( |
489 BrowserThread::UI, | 461 BrowserThread::UI, |
490 FROM_HERE, | 462 FROM_HERE, |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 &stored_value)) { | 1154 &stored_value)) { |
1183 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1155 return wallpaper::WallpaperFilesId::FromString(stored_value); |
1184 } | 1156 } |
1185 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1157 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
1186 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1158 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
1187 SetKnownUserWallpaperFilesId(account_id, files_id); | 1159 SetKnownUserWallpaperFilesId(account_id, files_id); |
1188 return files_id; | 1160 return files_id; |
1189 } | 1161 } |
1190 | 1162 |
1191 } // namespace chromeos | 1163 } // namespace chromeos |
OLD | NEW |