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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 2413503002: Cleanup mojo Wallpaper interfaces for mash. (Closed)
Patch Set: Sync and rebase; do *not* use mojo in classic ash. Created 4 years, 2 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 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"
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
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) {
177 auto connection = content::ServiceManagerConnection::GetForProcess();
178 auto connector = connection ? connection->GetConnector() : nullptr;
James Cook 2016/10/14 21:58:02 ditto
msw 2016/10/17 22:22:48 Done.
179 if (!connector)
180 return;
181
182 ash::mojom::WallpaperControllerPtr wallpaper_controller;
183 // Under mash the WallpaperController interface is in the ash process. In
184 // classic ash we provide it to ourself.
212 if (chrome::IsRunningInMash()) { 185 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); 186 connector->ConnectToInterface("service:ash", &wallpaper_controller);
217 wallpaper_controller->SetWallpaper(*image.bitmap(), 187 // TODO(crbug.com/655875): Optimize ash wallpaper transport; avoid sending
msw 2016/10/14 21:07:43 Because sending large wallpaper bitmaps over Mojo
218 WallpaperLayoutToMojo(layout)); 188 // large bitmaps over Mojo; use shared memory like BitmapUploader, etc.
219 return; 189 wallpaper_controller->SetWallpaper(*image.bitmap(), layout);
220 } 190 } else if (ash::WmShell::HasInstance()) {
James Cook 2016/10/14 21:58:02 I would keep the previous comment about tests. (In
msw 2016/10/17 22:22:48 Running *Wallpaper* ash_unittests, browser_tests a
221 // Avoid loading unnecessary wallpapers in tests without a shell instance.
222 if (ash::WmShell::HasInstance()) {
223 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image, 191 ash::WmShell::Get()->wallpaper_controller()->SetWallpaperImage(image,
224 layout); 192 layout);
225 } 193 }
226 } 194 }
227 195
228 } // namespace 196 } // namespace
229 197
230 // This is "wallpaper either scheduled to load, or loading right now". 198 // This is "wallpaper either scheduled to load, or loading right now".
231 // 199 //
232 // While enqueued, it defines moment in the future, when it will be loaded. 200 // 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
393 return wallpaper_manager; 361 return wallpaper_manager;
394 } 362 }
395 363
396 // static 364 // static
397 void WallpaperManager::Shutdown() { 365 void WallpaperManager::Shutdown() {
398 CHECK(wallpaper_manager); 366 CHECK(wallpaper_manager);
399 delete wallpaper_manager; 367 delete wallpaper_manager;
400 wallpaper_manager = nullptr; 368 wallpaper_manager = nullptr;
401 } 369 }
402 370
371 void WallpaperManager::BindRequest(
372 ash::mojom::WallpaperManagerRequest request) {
373 bindings_.AddBinding(this, std::move(request));
374 }
375
403 WallpaperManager::WallpaperResolution 376 WallpaperManager::WallpaperResolution
404 WallpaperManager::GetAppropriateResolution() { 377 WallpaperManager::GetAppropriateResolution() {
405 DCHECK_CURRENTLY_ON(BrowserThread::UI); 378 DCHECK_CURRENTLY_ON(BrowserThread::UI);
406 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative(); 379 gfx::Size size = ash::WallpaperController::GetMaxDisplaySizeInNative();
407 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 380 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
408 size.height() > wallpaper::kSmallWallpaperMaxHeight) 381 size.height() > wallpaper::kSmallWallpaperMaxHeight)
409 ? WALLPAPER_RESOLUTION_LARGE 382 ? WALLPAPER_RESOLUTION_LARGE
410 : WALLPAPER_RESOLUTION_SMALL; 383 : WALLPAPER_RESOLUTION_SMALL;
411 } 384 }
412 385
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (!user_manager->IsUserLoggedIn()) { 444 if (!user_manager->IsUserLoggedIn()) {
472 if (!StartupUtils::IsDeviceRegistered()) 445 if (!StartupUtils::IsDeviceRegistered())
473 SetDefaultWallpaperDelayed(login::SignInAccountId()); 446 SetDefaultWallpaperDelayed(login::SignInAccountId());
474 else 447 else
475 InitializeRegisteredDeviceWallpaper(); 448 InitializeRegisteredDeviceWallpaper();
476 return; 449 return;
477 } 450 }
478 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId()); 451 SetUserWallpaperDelayed(user_manager->GetLoggedInUser()->GetAccountId());
479 } 452 }
480 453
454 void WallpaperManager::Open() {
455 wallpaper_manager_util::OpenWallpaperManager();
456 }
457
481 void WallpaperManager::Observe(int type, 458 void WallpaperManager::Observe(int type,
482 const content::NotificationSource& source, 459 const content::NotificationSource& source,
483 const content::NotificationDetails& details) { 460 const content::NotificationDetails& details) {
484 DCHECK_CURRENTLY_ON(BrowserThread::UI); 461 DCHECK_CURRENTLY_ON(BrowserThread::UI);
485 switch (type) { 462 switch (type) {
486 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 463 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
487 ClearDisposableWallpaperCache(); 464 ClearDisposableWallpaperCache();
488 BrowserThread::PostDelayedTask( 465 BrowserThread::PostDelayedTask(
489 BrowserThread::UI, 466 BrowserThread::UI,
490 FROM_HERE, 467 FROM_HERE,
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 &stored_value)) { 1159 &stored_value)) {
1183 return wallpaper::WallpaperFilesId::FromString(stored_value); 1160 return wallpaper::WallpaperFilesId::FromString(stored_value);
1184 } 1161 }
1185 const std::string& old_id = account_id.GetUserEmail(); // Migrated 1162 const std::string& old_id = account_id.GetUserEmail(); // Migrated
1186 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); 1163 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id);
1187 SetKnownUserWallpaperFilesId(account_id, files_id); 1164 SetKnownUserWallpaperFilesId(account_id, files_id);
1188 return files_id; 1165 return files_id;
1189 } 1166 }
1190 1167
1191 } // namespace chromeos 1168 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698