| 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> | 7 #include <stdint.h> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/common/ash_constants.h" | 12 #include "ash/common/ash_constants.h" |
| 13 #include "ash/common/ash_switches.h" | 13 #include "ash/common/ash_switches.h" |
| 14 #include "ash/desktop_background/desktop_background_controller.h" | 14 #include "ash/desktop_background/desktop_background_controller.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/sysui/public/interfaces/wallpaper.mojom.h" |
| 16 #include "base/bind.h" | 17 #include "base/bind.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "base/files/file_enumerator.h" | 19 #include "base/files/file_enumerator.h" |
| 19 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 20 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| 22 #include "base/macros.h" | 23 #include "base/macros.h" |
| 23 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
| 24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 25 #include "base/sha1.h" | 26 #include "base/sha1.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| 60 #include "content/public/browser/notification_service.h" | 61 #include "content/public/browser/notification_service.h" |
| 61 #include "content/public/common/content_switches.h" | 62 #include "content/public/common/content_switches.h" |
| 62 #include "content/public/common/mojo_shell_connection.h" | 63 #include "content/public/common/mojo_shell_connection.h" |
| 63 #include "services/shell/public/cpp/connector.h" | 64 #include "services/shell/public/cpp/connector.h" |
| 64 #include "third_party/skia/include/core/SkColor.h" | 65 #include "third_party/skia/include/core/SkColor.h" |
| 65 #include "ui/gfx/codec/jpeg_codec.h" | 66 #include "ui/gfx/codec/jpeg_codec.h" |
| 66 #include "ui/gfx/image/image_skia_operations.h" | 67 #include "ui/gfx/image/image_skia_operations.h" |
| 67 #include "ui/gfx/skia_util.h" | 68 #include "ui/gfx/skia_util.h" |
| 68 | 69 |
| 69 #if defined(MOJO_SHELL_CLIENT) | |
| 70 #include "ash/sysui/public/interfaces/wallpaper.mojom.h" | |
| 71 #endif | |
| 72 | |
| 73 using content::BrowserThread; | 70 using content::BrowserThread; |
| 74 using wallpaper::WallpaperManagerBase; | 71 using wallpaper::WallpaperManagerBase; |
| 75 using wallpaper::WallpaperInfo; | 72 using wallpaper::WallpaperInfo; |
| 76 using wallpaper::MovableOnDestroyCallback; | 73 using wallpaper::MovableOnDestroyCallback; |
| 77 using wallpaper::MovableOnDestroyCallbackHolder; | 74 using wallpaper::MovableOnDestroyCallbackHolder; |
| 78 | 75 |
| 79 namespace chromeos { | 76 namespace chromeos { |
| 80 | 77 |
| 81 namespace { | 78 namespace { |
| 82 | 79 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return wallpaper::WallpaperFilesId::FromString(result); | 170 return wallpaper::WallpaperFilesId::FromString(result); |
| 174 } | 171 } |
| 175 | 172 |
| 176 void SetKnownUserWallpaperFilesId( | 173 void SetKnownUserWallpaperFilesId( |
| 177 const AccountId& account_id, | 174 const AccountId& account_id, |
| 178 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 175 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
| 179 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 176 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
| 180 wallpaper_files_id.id()); | 177 wallpaper_files_id.id()); |
| 181 } | 178 } |
| 182 | 179 |
| 183 #if defined(MOJO_SHELL_CLIENT) | |
| 184 ash::sysui::mojom::WallpaperLayout WallpaperLayoutToMojo( | 180 ash::sysui::mojom::WallpaperLayout WallpaperLayoutToMojo( |
| 185 wallpaper::WallpaperLayout layout) { | 181 wallpaper::WallpaperLayout layout) { |
| 186 switch (layout) { | 182 switch (layout) { |
| 187 case wallpaper::WALLPAPER_LAYOUT_CENTER: | 183 case wallpaper::WALLPAPER_LAYOUT_CENTER: |
| 188 return ash::sysui::mojom::WallpaperLayout::CENTER; | 184 return ash::sysui::mojom::WallpaperLayout::CENTER; |
| 189 case wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED: | 185 case wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED: |
| 190 return ash::sysui::mojom::WallpaperLayout::CENTER_CROPPED; | 186 return ash::sysui::mojom::WallpaperLayout::CENTER_CROPPED; |
| 191 case wallpaper::WALLPAPER_LAYOUT_STRETCH: | 187 case wallpaper::WALLPAPER_LAYOUT_STRETCH: |
| 192 return ash::sysui::mojom::WallpaperLayout::STRETCH; | 188 return ash::sysui::mojom::WallpaperLayout::STRETCH; |
| 193 case wallpaper::WALLPAPER_LAYOUT_TILE: | 189 case wallpaper::WALLPAPER_LAYOUT_TILE: |
| 194 return ash::sysui::mojom::WallpaperLayout::TILE; | 190 return ash::sysui::mojom::WallpaperLayout::TILE; |
| 195 case wallpaper::NUM_WALLPAPER_LAYOUT: | 191 case wallpaper::NUM_WALLPAPER_LAYOUT: |
| 196 NOTREACHED(); | 192 NOTREACHED(); |
| 197 return ash::sysui::mojom::WallpaperLayout::CENTER; | 193 return ash::sysui::mojom::WallpaperLayout::CENTER; |
| 198 } | 194 } |
| 199 NOTREACHED(); | 195 NOTREACHED(); |
| 200 return ash::sysui::mojom::WallpaperLayout::CENTER; | 196 return ash::sysui::mojom::WallpaperLayout::CENTER; |
| 201 } | 197 } |
| 202 #endif | |
| 203 | 198 |
| 204 // A helper to set the wallpaper image for Ash and Mash. | 199 // A helper to set the wallpaper image for Ash and Mash. |
| 205 void SetWallpaper(const gfx::ImageSkia& image, | 200 void SetWallpaper(const gfx::ImageSkia& image, |
| 206 wallpaper::WallpaperLayout layout) { | 201 wallpaper::WallpaperLayout layout) { |
| 207 #if defined(MOJO_SHELL_CLIENT) | |
| 208 if (chrome::IsRunningInMash()) { | 202 if (chrome::IsRunningInMash()) { |
| 209 shell::Connector* connector = | 203 shell::Connector* connector = |
| 210 content::MojoShellConnection::GetForProcess()->GetConnector(); | 204 content::MojoShellConnection::GetForProcess()->GetConnector(); |
| 211 ash::sysui::mojom::WallpaperControllerPtr wallpaper_controller; | 205 ash::sysui::mojom::WallpaperControllerPtr wallpaper_controller; |
| 212 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); | 206 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); |
| 213 wallpaper_controller->SetWallpaper(*image.bitmap(), | 207 wallpaper_controller->SetWallpaper(*image.bitmap(), |
| 214 WallpaperLayoutToMojo(layout)); | 208 WallpaperLayoutToMojo(layout)); |
| 215 return; | 209 return; |
| 216 } | 210 } |
| 217 #endif | |
| 218 // Avoid loading unnecessary wallpapers in tests without a shell instance. | 211 // Avoid loading unnecessary wallpapers in tests without a shell instance. |
| 219 if (ash::Shell::HasInstance()) { | 212 if (ash::Shell::HasInstance()) { |
| 220 ash::Shell::GetInstance() | 213 ash::Shell::GetInstance() |
| 221 ->desktop_background_controller() | 214 ->desktop_background_controller() |
| 222 ->SetWallpaperImage(image, layout); | 215 ->SetWallpaperImage(image, layout); |
| 223 } | 216 } |
| 224 } | 217 } |
| 225 | 218 |
| 226 } // namespace | 219 } // namespace |
| 227 | 220 |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 &stored_value)) { | 1166 &stored_value)) { |
| 1174 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1167 return wallpaper::WallpaperFilesId::FromString(stored_value); |
| 1175 } | 1168 } |
| 1176 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1169 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
| 1177 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1170 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
| 1178 SetKnownUserWallpaperFilesId(account_id, files_id); | 1171 SetKnownUserWallpaperFilesId(account_id, files_id); |
| 1179 return files_id; | 1172 return files_id; |
| 1180 } | 1173 } |
| 1181 | 1174 |
| 1182 } // namespace chromeos | 1175 } // namespace chromeos |
| OLD | NEW |