wallpaper_api.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_API_H_ 6#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_API_H_ 7 8#include "ash/desktop_background/desktop_background_controller.h" 9#include "base/threading/sequenced_worker_pool.h" 10#include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" 11 12// Implementation of chrome.wallpaper.setWallpaper API. 13// After this API being called, a jpeg encoded wallpaper will be saved to 14// /home/chronos/custom_wallpaper/{resolution}/{username}/file_name. The 15// wallpaper can then persistent after Chrome restart. New call to this API 16// will replace the previous saved wallpaper with new one. 17// Note: For security reason, the original encoded wallpaper image is not saved 18// directly. It is decoded and re-encoded to jpeg format before saved to file 19// system. 20class WallpaperSetWallpaperFunction : public WallpaperFunctionBase { 21 public: 22 DECLARE_EXTENSION_FUNCTION("wallpaper.setWallpaper", 23 WALLPAPER_SETWALLPAPER) 24 25 WallpaperSetWallpaperFunction(); 26 27 protected: 28 virtual ~WallpaperSetWallpaperFunction(); 29 30 // AsyncExtensionFunction overrides. 31 virtual bool RunImpl() OVERRIDE; 32 33 private: 34 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; 35 36 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for 37 // generating thumbnail. 38 void GenerateThumbnail(const base::FilePath& thumbnail_path, 39 scoped_ptr<gfx::ImageSkia> image); 40 41 // Thumbnail is ready. Calls api function javascript callback. 42 void ThumbnailGenerated(base::RefCountedBytes* data); 43 44 // Layout of the downloaded wallpaper. 45 ash::WallpaperLayout layout_; 46 47 // True if need to generate thumbnail and pass to callback. 48 bool generate_thumbnail_; 49 50 // Unique file name of the custom wallpaper. 51 std::string file_name_; 52 53 // Email address of logged in user. 54 // TODO(bshe): User's email should not be used as part of wallpaper file path. 55 // http://crbug.com/287020 56 std::string email_; 57 58 // String representation of downloaded wallpaper. 59 std::string image_data_; 60 61 // Sequence token associated with wallpaper operations. Shared with 62 // WallpaperManager. 63 base::SequencedWorkerPool::SequenceToken sequence_token_; 64}; 65 66#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_API_H_ 67 68