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_service.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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/gfx/image/image_util.h" | 26 #include "ui/gfx/image/image_util.h" |
| 27 | 27 |
| 28 using user_manager::UserManager; | 28 using user_manager::UserManager; |
| 29 | 29 |
| 30 namespace arc { | 30 namespace arc { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 constexpr uint32_t kMinOnWallpaperChangedVersion = 1; | |
| 34 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; | 35 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; |
| 35 | 36 |
| 36 // Sets a decoded bitmap as the wallpaper. | 37 // Sets a decoded bitmap as the wallpaper. |
| 37 void SetBitmapAsWallpaper(const SkBitmap& bitmap) { | 38 void SetBitmapAsWallpaper(const SkBitmap& bitmap) { |
| 38 // Make the SkBitmap immutable as we won't modify it. This is important | 39 // Make the SkBitmap immutable as we won't modify it. This is important |
| 39 // because otherwise it gets duplicated during painting, wasting memory. | 40 // because otherwise it gets duplicated during painting, wasting memory. |
| 40 SkBitmap immutable_bitmap(bitmap); | 41 SkBitmap immutable_bitmap(bitmap); |
| 41 immutable_bitmap.setImmutable(); | 42 immutable_bitmap.setImmutable(); |
| 42 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(immutable_bitmap); | 43 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(immutable_bitmap); |
| 43 image.MakeThreadSafe(); | 44 image.MakeThreadSafe(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 74 ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service) | 75 ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service) |
| 75 : ArcService(bridge_service), binding_(this) { | 76 : ArcService(bridge_service), binding_(this) { |
| 76 arc_bridge_service()->wallpaper()->AddObserver(this); | 77 arc_bridge_service()->wallpaper()->AddObserver(this); |
| 77 } | 78 } |
| 78 | 79 |
| 79 ArcWallpaperService::~ArcWallpaperService() { | 80 ArcWallpaperService::~ArcWallpaperService() { |
| 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 81 // Make sure the callback is never called after destruction. It is safe to | 82 // Make sure the callback is never called after destruction. It is safe to |
| 82 // call Cancel() even when there is no in-flight request. | 83 // call Cancel() even when there is no in-flight request. |
| 83 ImageDecoder::Cancel(this); | 84 ImageDecoder::Cancel(this); |
| 85 ash::WmShell::Get()->wallpaper_controller()->RemoveObserver(this); | |
|
Yusuke Sato
2016/09/16 00:45:19
You need null check(s). See the trybot (browser_te
Muyuan
2016/09/16 17:35:16
Done.
| |
| 84 arc_bridge_service()->wallpaper()->RemoveObserver(this); | 86 arc_bridge_service()->wallpaper()->RemoveObserver(this); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void ArcWallpaperService::OnInstanceReady() { | 89 void ArcWallpaperService::OnInstanceReady() { |
| 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 89 mojom::WallpaperInstance* wallpaper_instance = | 91 mojom::WallpaperInstance* wallpaper_instance = |
| 90 arc_bridge_service()->wallpaper()->instance(); | 92 arc_bridge_service()->wallpaper()->instance(); |
| 91 if (!wallpaper_instance) { | 93 if (!wallpaper_instance) { |
| 92 LOG(DFATAL) << "OnWallpaperInstanceReady called, " | 94 LOG(DFATAL) << "OnWallpaperInstanceReady called, " |
| 93 << "but no wallpaper instance found"; | 95 << "but no wallpaper instance found"; |
| 94 return; | 96 return; |
| 95 } | 97 } |
| 96 wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind()); | 98 wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 99 ash::WmShell::Get()->wallpaper_controller()->AddObserver(this); | |
| 97 } | 100 } |
| 98 | 101 |
| 99 void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) { | 102 void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) { |
| 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 101 ImageDecoder::Cancel(this); | 104 ImageDecoder::Cancel(this); |
| 102 ImageDecoder::StartWithOptions(this, png_data.PassStorage(), | 105 ImageDecoder::StartWithOptions(this, png_data.PassStorage(), |
| 103 ImageDecoder::ROBUST_PNG_CODEC, true); | 106 ImageDecoder::ROBUST_PNG_CODEC, true); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void ArcWallpaperService::GetWallpaper(const GetWallpaperCallback& callback) { | 109 void ArcWallpaperService::GetWallpaper(const GetWallpaperCallback& callback) { |
| 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 108 ash::WallpaperController* wc = ash::WmShell::Get()->wallpaper_controller(); | 111 ash::WallpaperController* wc = ash::WmShell::Get()->wallpaper_controller(); |
| 109 gfx::ImageSkia wallpaper = wc->GetWallpaper(); | 112 gfx::ImageSkia wallpaper = wc->GetWallpaper(); |
| 110 base::PostTaskAndReplyWithResult( | 113 base::PostTaskAndReplyWithResult( |
| 111 content::BrowserThread::GetBlockingPool(), FROM_HERE, | 114 content::BrowserThread::GetBlockingPool(), FROM_HERE, |
| 112 base::Bind(&EncodeImagePng, wallpaper), callback); | 115 base::Bind(&EncodeImagePng, wallpaper), callback); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) { | 118 void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) { |
| 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 117 SetBitmapAsWallpaper(bitmap); | 120 SetBitmapAsWallpaper(bitmap); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void ArcWallpaperService::OnDecodeImageFailed() { | 123 void ArcWallpaperService::OnDecodeImageFailed() { |
| 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 122 LOG(ERROR) << "Failed to decode wallpaper image."; | 125 LOG(ERROR) << "Failed to decode wallpaper image."; |
| 123 } | 126 } |
| 124 | 127 |
| 128 void ArcWallpaperService::OnWallpaperDataChanged() { | |
| 129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 130 if (!CheckWallpaperInstanceVersion(kMinOnWallpaperChangedVersion)) { | |
| 131 return; | |
| 132 } | |
| 133 arc_bridge_service()->wallpaper()->instance()->OnWallpaperChanged(); | |
|
Luis Héctor Chávez
2016/09/16 00:01:58
what if instance() is null? It's probably better t
Muyuan
2016/09/16 16:30:05
The observer is registered in OnInstanceReady, so
Luis Héctor Chávez
2016/09/16 16:34:02
You can't assume that: What happens if the other s
Muyuan
2016/09/16 17:35:16
Done.
Muyuan
2016/09/16 17:37:22
Should I remove the wallpaper observer when the in
Luis Héctor Chávez
2016/09/16 17:49:14
So what I'm saying is:
a) Change CheckWallpaperIn
Muyuan
2016/09/16 19:52:07
Done.
| |
| 134 } | |
| 135 | |
| 136 bool ArcWallpaperService::CheckWallpaperInstanceVersion(uint32_t version_need) { | |
| 137 uint32_t version = arc_bridge_service()->wallpaper()->version(); | |
| 138 if (version >= version_need) { | |
| 139 return true; | |
| 140 } | |
| 141 LOG(WARNING) << "Wallpaper instance is too old (version " << version | |
| 142 << ") need version " << version_need; | |
| 143 return false; | |
| 144 } | |
| 145 | |
| 125 } // namespace arc | 146 } // namespace arc |
| OLD | NEW |