Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/arc/arc_wallpaper_handler.h" | 5 #include "chrome/browser/chromeos/arc/arc_wallpaper_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/shell.h" | |
| 12 #include "ash/wallpaper/wallpaper_controller.h" | |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/task_runner_util.h" | |
| 13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 16 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 17 #include "components/arc/arc_bridge_service.h" | |
| 14 #include "components/signin/core/account_id/account_id.h" | 18 #include "components/signin/core/account_id/account_id.h" |
| 15 #include "components/user_manager/user_manager.h" | 19 #include "components/user_manager/user_manager.h" |
| 16 #include "components/wallpaper/wallpaper_files_id.h" | 20 #include "components/wallpaper/wallpaper_files_id.h" |
| 17 #include "components/wallpaper/wallpaper_layout.h" | 21 #include "components/wallpaper/wallpaper_layout.h" |
| 18 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "ui/gfx/codec/png_codec.h" | |
| 24 #include "ui/gfx/image/image.h" | |
| 19 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/gfx/image/image_util.h" | |
| 20 | 27 |
| 21 using user_manager::UserManager; | 28 using user_manager::UserManager; |
| 22 | 29 |
| 23 namespace arc { | 30 namespace arc { |
| 24 | 31 |
| 25 namespace { | 32 namespace { |
| 26 | 33 |
| 27 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; | 34 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; |
| 28 | 35 |
| 29 // Sets a decoded bitmap as the wallpaper. | 36 // Sets a decoded bitmap as the wallpaper. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 49 account_id, wallpaper_files_id, kAndroidWallpaperFilename, | 56 account_id, wallpaper_files_id, kAndroidWallpaperFilename, |
| 50 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, | 57 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, |
| 51 image, update_wallpaper); | 58 image, update_wallpaper); |
| 52 | 59 |
| 53 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper | 60 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper |
| 54 // picker. Currently the new wallpaper does not appear there. The best way to | 61 // picker. Currently the new wallpaper does not appear there. The best way to |
| 55 // make this happen seems to do the same things as wallpaper_api.cc and | 62 // make this happen seems to do the same things as wallpaper_api.cc and |
| 56 // wallpaper_private_api.cc. | 63 // wallpaper_private_api.cc. |
| 57 } | 64 } |
| 58 | 65 |
| 66 std::vector<uint8_t> EncodeImagePng(const gfx::ImageSkia image) { | |
| 67 std::vector<uint8_t> result; | |
| 68 gfx::PNGCodec::FastEncodeBGRASkBitmap(*image.bitmap(), true, &result); | |
| 69 return result; | |
| 70 } | |
| 71 | |
| 59 } // namespace | 72 } // namespace |
| 60 | 73 |
| 61 ArcWallpaperHandler::ArcWallpaperHandler() = default; | 74 ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service) |
| 75 : ArcService(bridge_service), binding_(this) { | |
| 76 arc_bridge_service()->wallpaper()->AddObserver(this); | |
| 77 DCHECK(!instance_); | |
|
hidehiko
2016/09/07 03:26:49
nit: Could you follow the style guide by avoiding
| |
| 78 instance_ = this; | |
| 79 } | |
| 62 | 80 |
| 63 ArcWallpaperHandler::~ArcWallpaperHandler() { | 81 ArcWallpaperService::~ArcWallpaperService() { |
| 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 65 // Make sure the callback is never called after destruction. It is safe to | 83 // Make sure the callback is never called after destruction. It is safe to |
| 66 // call Cancel() even when there is no in-flight request. | 84 // call Cancel() even when there is no in-flight request. |
| 67 ImageDecoder::Cancel(this); | 85 ImageDecoder::Cancel(this); |
| 86 arc_bridge_service()->wallpaper()->RemoveObserver(this); | |
| 87 DCHECK(instance_ == this); | |
| 88 instance_ = nullptr; | |
| 68 } | 89 } |
| 69 | 90 |
| 70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { | 91 void ArcWallpaperService::OnInstanceReady() { |
| 92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 93 mojom::WallpaperInstance* wallpaper_instance = | |
| 94 arc_bridge_service()->wallpaper()->instance(); | |
| 95 if (!wallpaper_instance) { | |
| 96 LOG(DFATAL) << "OnWallpaperInstanceReady called, " | |
| 97 << "but no wallpaper instance found"; | |
| 98 return; | |
| 99 } | |
| 100 wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind()); | |
| 101 } | |
| 102 | |
| 103 void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) { | |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 105 ImageDecoder::Cancel(this); | |
| 106 ImageDecoder::StartWithOptions(this, png_data.PassStorage(), | |
| 107 ImageDecoder::ROBUST_PNG_CODEC, true); | |
| 108 } | |
| 109 | |
| 110 void ArcWallpaperService::GetWallpaper(const GetWallpaperCallback& callback) { | |
| 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 112 ash::WallpaperController* wc = | |
| 113 ash::Shell::GetInstance()->wallpaper_controller(); | |
| 114 gfx::ImageSkia wallpaper = wc->GetWallpaper(); | |
| 115 base::PostTaskAndReplyWithResult( | |
| 116 content::BrowserThread::GetBlockingPool(), FROM_HERE, | |
| 117 base::Bind(&EncodeImagePng, wallpaper), callback); | |
| 118 } | |
| 119 | |
| 120 void ArcWallpaperService::SetWallpaperJpeg( | |
| 121 const std::vector<uint8_t>& jpeg_data) { | |
| 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 72 // If there is an in-flight request, cancel it. It is safe to call Cancel() | 123 // If there is an in-flight request, cancel it. It is safe to call Cancel() |
| 73 // even when there is no in-flight request. | 124 // even when there is no in-flight request. |
| 74 ImageDecoder::Cancel(this); | 125 ImageDecoder::Cancel(this); |
| 75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), | 126 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), |
| 76 ImageDecoder::ROBUST_JPEG_CODEC, true); | 127 ImageDecoder::ROBUST_JPEG_CODEC, true); |
| 77 } | 128 } |
| 78 | 129 |
| 79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { | 130 void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) { |
| 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 131 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 81 SetBitmapAsWallpaper(bitmap); | 132 SetBitmapAsWallpaper(bitmap); |
| 82 } | 133 } |
| 83 | 134 |
| 84 void ArcWallpaperHandler::OnDecodeImageFailed() { | 135 void ArcWallpaperService::OnDecodeImageFailed() { |
| 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 136 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 86 LOG(ERROR) << "Failed to decode wallpaper image."; | 137 LOG(ERROR) << "Failed to decode wallpaper image."; |
| 87 } | 138 } |
| 88 | 139 |
| 89 } // namespace arc | 140 } // namespace arc |
| OLD | NEW |