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

Unified Diff: chrome/browser/chromeos/login/wallpaper_loader.cc

Issue 10832019: Speed up custom wallpaper switching time and wallpaper manager code refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/wallpaper_loader.cc
diff --git a/chrome/browser/chromeos/login/wallpaper_loader.cc b/chrome/browser/chromeos/login/wallpaper_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9212f6d33a1dbd6c8e14af7776553097a230fdae
--- /dev/null
+++ b/chrome/browser/chromeos/login/wallpaper_loader.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/wallpaper_loader.h"
+
+#include "base/bind.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "content/public/browser/browser_thread.h"
+#include "skia/ext/image_operations.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/skbitmap_operations.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+WallpaperLoader::WallpaperInfo::WallpaperInfo(bool save_raw_image,
+ const std::string& save_to_path,
+ const LoadedCallback& loaded_cb)
+ : save_raw_image(save_raw_image),
+ save_to_path(save_to_path),
+ loaded_cb(loaded_cb) {
+}
+
+WallpaperLoader::WallpaperInfo::~WallpaperInfo() {
+}
+
+WallpaperLoader::WallpaperLoader()
+ : target_message_loop_(NULL) {
+}
+
+WallpaperLoader::~WallpaperLoader() {
+}
+
+void WallpaperLoader::Start(const std::string& filepath,
+ bool save_raw_image,
+ const std::string& save_to_path,
+ const LoadedCallback& loaded_cb) {
+ target_message_loop_ = MessageLoop::current();
+
+ WallpaperInfo info(save_raw_image, save_to_path, loaded_cb);
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&WallpaperLoader::LoadImage, this, filepath, info));
+}
+
+void WallpaperLoader::LoadImage(const std::string& filepath,
+ const WallpaperInfo& wallpaper_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ std::string image_data;
+ file_util::ReadFileToString(FilePath(filepath), &image_data);
+
+ scoped_refptr<ImageDecoder> image_decoder =
+ new ImageDecoder(this, image_data);
+ wallpaper_info_map_.insert(std::make_pair(image_decoder.get(),
+ wallpaper_info));
+ image_decoder->Start();
+}
+
+void WallpaperLoader::OnImageDecoded(const ImageDecoder* decoder,
+ const SkBitmap& decoded_image) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ WallpaperInfoMap::iterator wallpaper_info_it =
+ wallpaper_info_map_.find(decoder);
+ if (wallpaper_info_it == wallpaper_info_map_.end()) {
+ NOTREACHED();
+ return;
+ }
+
+ const WallpaperInfo& info = wallpaper_info_it->second;
+
+ if (info.save_raw_image) {
+ std::vector<unsigned char> image_data = decoder->get_image_data();
+ int write_bytes = file_util::WriteFile(FilePath(info.save_to_path),
+ reinterpret_cast<char*>(&*image_data.begin()),
+ image_data.size());
+ DCHECK(write_bytes == static_cast<int>(image_data.size()));
+ }
+
+ const LoadedCallback& loaded_cb = info.loaded_cb;
+
+ target_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(loaded_cb, decoded_image));
+
+ wallpaper_info_map_.erase(wallpaper_info_it);
+}
+
+void WallpaperLoader::OnDecodeImageFailed(const ImageDecoder* decoder) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ wallpaper_info_map_.erase(decoder);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698