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

Side by Side Diff: chrome/browser/chromeos/arc/arc_wallpaper_handler.cc

Issue 2177833003: Avoid unnecessary copies in ImageDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change ArcWallpaperHandler to use new API. Created 4 years, 4 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
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_handler.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_handler.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698