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_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
12 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
13 #include "components/signin/core/account_id/account_id.h" | 14 #include "components/signin/core/account_id/account_id.h" |
14 #include "components/user_manager/user_manager.h" | 15 #include "components/user_manager/user_manager.h" |
15 #include "components/wallpaper/wallpaper_files_id.h" | 16 #include "components/wallpaper/wallpaper_files_id.h" |
16 #include "components/wallpaper/wallpaper_layout.h" | 17 #include "components/wallpaper/wallpaper_layout.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 60 |
60 ArcWallpaperHandler::ArcWallpaperHandler() = default; | 61 ArcWallpaperHandler::ArcWallpaperHandler() = default; |
61 | 62 |
62 ArcWallpaperHandler::~ArcWallpaperHandler() { | 63 ArcWallpaperHandler::~ArcWallpaperHandler() { |
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
64 // Make sure the callback is never called after destruction. It is safe to | 65 // Make sure the callback is never called after destruction. It is safe to |
65 // call Cancel() even when there is no in-flight request. | 66 // call Cancel() even when there is no in-flight request. |
66 ImageDecoder::Cancel(this); | 67 ImageDecoder::Cancel(this); |
67 } | 68 } |
68 | 69 |
69 void ArcWallpaperHandler::SetWallpaper(const std::vector<uint8_t>& jpeg_data) { | 70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
71 // If there is an in-flight request, cancel it. It is safe to call Cancel() | 72 // If there is an in-flight request, cancel it. It is safe to call Cancel() |
72 // even when there is no in-flight request. | 73 // even when there is no in-flight request. |
73 ImageDecoder::Cancel(this); | 74 ImageDecoder::Cancel(this); |
74 // TODO(nya): Improve ImageDecoder to minimize copy. | 75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), |
75 std::string jpeg_data_as_string( | |
76 reinterpret_cast<const char*>(jpeg_data.data()), jpeg_data.size()); | |
77 ImageDecoder::StartWithOptions(this, jpeg_data_as_string, | |
78 ImageDecoder::ROBUST_JPEG_CODEC, true); | 76 ImageDecoder::ROBUST_JPEG_CODEC, true); |
79 } | 77 } |
80 | 78 |
81 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { | 79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { |
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
83 SetBitmapAsWallpaper(bitmap); | 81 SetBitmapAsWallpaper(bitmap); |
84 } | 82 } |
85 | 83 |
86 void ArcWallpaperHandler::OnDecodeImageFailed() { | 84 void ArcWallpaperHandler::OnDecodeImageFailed() { |
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
88 LOG(ERROR) << "Failed to decode wallpaper image."; | 86 LOG(ERROR) << "Failed to decode wallpaper image."; |
89 } | 87 } |
90 | 88 |
91 } // namespace arc | 89 } // namespace arc |
OLD | NEW |