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/shell/public/cpp/connector.h" | 52 #include "services/shell/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" | |
James Cook
2016/10/11 23:21:49
You're so good at keeping includes clean!
| |
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 NOTREACHED(); | 186 NOTREACHED(); |
203 return ash::mojom::WallpaperLayout::CENTER; | 187 return ash::mojom::WallpaperLayout::CENTER; |
204 } | 188 } |
205 NOTREACHED(); | 189 NOTREACHED(); |
206 return ash::mojom::WallpaperLayout::CENTER; | 190 return ash::mojom::WallpaperLayout::CENTER; |
207 } | 191 } |
208 | 192 |
209 // A helper to set the wallpaper image for Ash and Mash. | 193 // A helper to set the wallpaper image for Ash and Mash. |
210 void SetWallpaper(const gfx::ImageSkia& image, | 194 void SetWallpaper(const gfx::ImageSkia& image, |
211 wallpaper::WallpaperLayout layout) { | 195 wallpaper::WallpaperLayout layout) { |
196 shell::Connector* connector = | |
197 content::ServiceManagerConnection::GetForProcess()->GetConnector(); | |
198 if (!connector) | |
199 return; | |
200 | |
201 ash::mojom::WallpaperControllerPtr wallpaper_controller; | |
202 // Under mash the WallpaperController interface is in the ash process. In | |
203 // classic ash we provide it to ourself. | |
212 if (chrome::IsRunningInMash()) { | 204 if (chrome::IsRunningInMash()) { |
213 shell::Connector* connector = | |
214 content::ServiceManagerConnection::GetForProcess()->GetConnector(); | |
215 ash::mojom::WallpaperControllerPtr wallpaper_controller; | |
216 connector->ConnectToInterface("service:ash", &wallpaper_controller); | 205 connector->ConnectToInterface("service:ash", &wallpaper_controller); |
217 wallpaper_controller->SetWallpaper(*image.bitmap(), | 206 } else { |
218 WallpaperLayoutToMojo(layout)); | 207 connector->ConnectToInterface("service:content_browser", |
219 return; | 208 &wallpaper_controller); |
220 } | 209 } |
221 // Avoid loading unnecessary wallpapers in tests without a shell instance. | 210 wallpaper_controller->SetWallpaper(*image.bitmap(), |
222 if (ash::WmShell::HasInstance()) { | 211 WallpaperLayoutToMojo(layout)); |
223 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, | |
224 layout); | |
225 } | |
226 } | 212 } |
227 | 213 |
228 } // namespace | 214 } // namespace |
229 | 215 |
230 // This is "wallpaper either scheduled to load, or loading right now". | 216 // This is "wallpaper either scheduled to load, or loading right now". |
231 // | 217 // |
232 // While enqueued, it defines moment in the future, when it will be loaded. | 218 // While enqueued, it defines moment in the future, when it will be loaded. |
233 // Enqueued but not started request might be updated by subsequent load | 219 // Enqueued but not started request might be updated by subsequent load |
234 // request. Therefore it's created empty, and updated being enqueued. | 220 // request. Therefore it's created empty, and updated being enqueued. |
235 // | 221 // |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 return wallpaper_manager; | 379 return wallpaper_manager; |
394 } | 380 } |
395 | 381 |
396 // static | 382 // static |
397 void WallpaperManager::Shutdown() { | 383 void WallpaperManager::Shutdown() { |
398 CHECK(wallpaper_manager); | 384 CHECK(wallpaper_manager); |
399 delete wallpaper_manager; | 385 delete wallpaper_manager; |
400 wallpaper_manager = nullptr; | 386 wallpaper_manager = nullptr; |
401 } | 387 } |
402 | 388 |
389 void WallpaperManager::BindRequest( | |
390 ash::mojom::WallpaperManagerRequest request) { | |
391 bindings_.AddBinding(this, std::move(request)); | |
392 } | |
393 | |
403 WallpaperManager::WallpaperResolution | 394 WallpaperManager::WallpaperResolution |
404 WallpaperManager::GetAppropriateResolution() { | 395 WallpaperManager::GetAppropriateResolution() { |
405 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
406 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); | 397 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); |
407 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || | 398 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || |
408 size.height() > wallpaper::kSmallWallpaperMaxHeight) | 399 size.height() > wallpaper::kSmallWallpaperMaxHeight) |
409 ? WALLPAPER_RESOLUTION_LARGE | 400 ? WALLPAPER_RESOLUTION_LARGE |
410 : WALLPAPER_RESOLUTION_SMALL; | 401 : WALLPAPER_RESOLUTION_SMALL; |
411 } | 402 } |
412 | 403 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 if (!user_manager->IsUserLoggedIn()) { | 462 if (!user_manager->IsUserLoggedIn()) { |
472 if (!StartupUtils::IsDeviceRegistered()) | 463 if (!StartupUtils::IsDeviceRegistered()) |
473 SetDefaultWallpaperDelayed(login::SignInAccountId()); | 464 SetDefaultWallpaperDelayed(login::SignInAccountId()); |
474 else | 465 else |
475 InitializeRegisteredDeviceWallpaper(); | 466 InitializeRegisteredDeviceWallpaper(); |
476 return; | 467 return; |
477 } | 468 } |
478 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId()); | 469 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId()); |
479 } | 470 } |
480 | 471 |
472 void WallpaperManager::Open() { | |
473 wallpaper_manager_util::OpenWallpaperManager(); | |
474 } | |
475 | |
481 void WallpaperManager::Observe(int type, | 476 void WallpaperManager::Observe(int type, |
482 const content::NotificationSource& source, | 477 const content::NotificationSource& source, |
483 const content::NotificationDetails& details) { | 478 const content::NotificationDetails& details) { |
484 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 479 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
485 switch (type) { | 480 switch (type) { |
486 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 481 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
487 ClearDisposableWallpaperCache(); | 482 ClearDisposableWallpaperCache(); |
488 BrowserThread::PostDelayedTask( | 483 BrowserThread::PostDelayedTask( |
489 BrowserThread::UI, | 484 BrowserThread::UI, |
490 FROM_HERE, | 485 FROM_HERE, |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1180 &stored_value)) { | 1175 &stored_value)) { |
1181 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1176 return wallpaper::WallpaperFilesId::FromString(stored_value); |
1182 } | 1177 } |
1183 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1178 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
1184 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1179 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
1185 SetKnownUserWallpaperFilesId(account_id, files_id); | 1180 SetKnownUserWallpaperFilesId(account_id, files_id); |
1186 return files_id; | 1181 return files_id; |
1187 } | 1182 } |
1188 | 1183 |
1189 } // namespace chromeos | 1184 } // namespace chromeos |
OLD | NEW |