Commit efa536ef authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Make wallpaper paths internal to WallpaperController

1) The original idea was to create a WallpaperPaths class in
   //ash/public, but it's unnecessary now. We only need a one-time
   initialization of the wallpaper paths, and they can be internal to
   //ash after that.

2) Saving and syncing thumbnail is entirely implemented in
   wallpaper_manager.js, so delete all thumbnail related code in
   *.cc files. The |thumbnail_path| variable in https://goo.gl/HZw6r7
   is left because https://chromiumcodereview.appspot.com/12334030
   forgot to clean it up.

3) Removed code duplication of thumbnail generation in wallpaper_api
   and wallpaper_private_api.

Bug: 795159
Test: Manual
Change-Id: Ia861da7579f743e5fc380128c6d28405246de2c4
Reviewed-on: https://chromium-review.googlesource.com/967882Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546222}
parent 75854af0
...@@ -51,12 +51,15 @@ interface WallpaperController { ...@@ -51,12 +51,15 @@ interface WallpaperController {
// reside. // reside.
// |chromeos_custom_wallpapers_path|: Directory where custom wallpapers // |chromeos_custom_wallpapers_path|: Directory where custom wallpapers
// reside. // reside.
// |device_policy_wallpaper_path|: The file path of the device policy
// wallpaper (if any).
// |is_device_wallpaper_policy_enforced|: Whether the device wallpaper policy // |is_device_wallpaper_policy_enforced|: Whether the device wallpaper policy
// is enforced on the device. // is enforced on the device.
Init(WallpaperControllerClient client, Init(WallpaperControllerClient client,
mojo_base.mojom.FilePath user_data_path, mojo_base.mojom.FilePath user_data_path,
mojo_base.mojom.FilePath chromeos_wallpapers_path, mojo_base.mojom.FilePath chromeos_wallpapers_path,
mojo_base.mojom.FilePath chromeos_custom_wallpapers_path, mojo_base.mojom.FilePath chromeos_custom_wallpapers_path,
mojo_base.mojom.FilePath device_policy_wallpaper_path,
bool is_device_wallpaper_policy_enforced); bool is_device_wallpaper_policy_enforced);
// Sets wallpaper from a local file and updates the saved wallpaper info for // Sets wallpaper from a local file and updates the saved wallpaper info for
......
This diff is collapsed.
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
class PrefRegistrySimple; class PrefRegistrySimple;
namespace base { namespace base {
class RefCountedBytes;
class SequencedTaskRunner; class SequencedTaskRunner;
} // namespace base } // namespace base
...@@ -77,14 +76,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -77,14 +76,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// command line, lock/login screens). // command line, lock/login screens).
static const SkColor kInvalidColor; static const SkColor kInvalidColor;
// The paths of wallpaper directories.
// TODO(crbug.com/776464): Move these to anonymous namespace after
// |WallpaperManager::LoadWallpaper| and
// |WallpaperManager::GetDeviceWallpaperDir| are migrated.
static base::FilePath dir_user_data_path_;
static base::FilePath dir_chrome_os_wallpapers_path_;
static base::FilePath dir_chrome_os_custom_wallpapers_path_;
// Directory names of custom wallpapers. // Directory names of custom wallpapers.
static const char kSmallWallpaperSubDir[]; static const char kSmallWallpaperSubDir[];
static const char kLargeWallpaperSubDir[]; static const char kLargeWallpaperSubDir[];
...@@ -104,10 +95,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -104,10 +95,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
static const int kLargeWallpaperMaxWidth; static const int kLargeWallpaperMaxWidth;
static const int kLargeWallpaperMaxHeight; static const int kLargeWallpaperMaxHeight;
// The width and height of wallpaper thumbnails.
static const int kWallpaperThumbnailWidth;
static const int kWallpaperThumbnailHeight;
// The color of the wallpaper if no other wallpaper images are available. // The color of the wallpaper if no other wallpaper images are available.
static const SkColor kDefaultWallpaperColor; static const SkColor kDefaultWallpaperColor;
...@@ -138,16 +125,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -138,16 +125,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Returns custom wallpaper directory by appending corresponding |sub_dir|. // Returns custom wallpaper directory by appending corresponding |sub_dir|.
static base::FilePath GetCustomWallpaperDir(const std::string& sub_dir); static base::FilePath GetCustomWallpaperDir(const std::string& sub_dir);
// Resizes |image| to a resolution which is nearest to |preferred_width| and
// |preferred_height| while respecting the |layout| choice. |output_skia| is
// optional (may be null). Returns true on success.
static bool ResizeImage(const gfx::ImageSkia& image,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
scoped_refptr<base::RefCountedBytes>* output,
gfx::ImageSkia* output_skia);
// Resizes |image| to a resolution which is nearest to |preferred_width| and // Resizes |image| to a resolution which is nearest to |preferred_width| and
// |preferred_height| while respecting the |layout| choice and saves the // |preferred_height| while respecting the |layout| choice and saves the
// resized wallpaper to |path|. |output_skia| is optional (may be // resized wallpaper to |path|. |output_skia| is optional (may be
...@@ -159,9 +136,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -159,9 +136,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
int preferred_height, int preferred_height,
gfx::ImageSkia* output_skia); gfx::ImageSkia* output_skia);
// Returns the file path of the device policy wallpaper.
static base::FilePath GetDevicePolicyWallpaperFilePath();
// Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back to the // Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back to the
// original custom wallpaper. When |show_wallpaper| is true, shows the // original custom wallpaper. When |show_wallpaper| is true, shows the
// wallpaper immediately. Must run on wallpaper sequenced worker thread. // wallpaper immediately. Must run on wallpaper sequenced worker thread.
...@@ -337,6 +311,7 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -337,6 +311,7 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
const base::FilePath& chromeos_wallpapers_path, const base::FilePath& chromeos_wallpapers_path,
const base::FilePath& chromeos_custom_wallpapers_path, const base::FilePath& chromeos_custom_wallpapers_path,
const base::FilePath& device_policy_wallpaper_path,
bool is_device_wallpaper_policy_enforced) override; bool is_device_wallpaper_policy_enforced) override;
void SetCustomWallpaper(mojom::WallpaperUserInfoPtr user_info, void SetCustomWallpaper(mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id, const std::string& wallpaper_files_id,
......
...@@ -150,15 +150,10 @@ void WaitUntilCustomWallpapersDeleted(const AccountId& account_id) { ...@@ -150,15 +150,10 @@ void WaitUntilCustomWallpapersDeleted(const AccountId& account_id) {
WallpaperController::GetCustomWallpaperDir( WallpaperController::GetCustomWallpaperDir(
WallpaperController::kOriginalWallpaperSubDir) WallpaperController::kOriginalWallpaperSubDir)
.Append(wallpaper_file_id); .Append(wallpaper_file_id);
base::FilePath thumbnail_wallpaper_dir =
WallpaperController::GetCustomWallpaperDir(
WallpaperController::kThumbnailWallpaperSubDir)
.Append(wallpaper_file_id);
while (base::PathExists(small_wallpaper_dir) || while (base::PathExists(small_wallpaper_dir) ||
base::PathExists(large_wallpaper_dir) || base::PathExists(large_wallpaper_dir) ||
base::PathExists(original_wallpaper_dir) || base::PathExists(original_wallpaper_dir)) {
base::PathExists(thumbnail_wallpaper_dir)) {
} }
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <vector> #include <vector>
#include "ash/public/cpp/wallpaper_types.h" #include "ash/public/cpp/wallpaper_types.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -179,11 +178,6 @@ bool WallpaperSetWallpaperFunction::RunAsync() { ...@@ -179,11 +178,6 @@ bool WallpaperSetWallpaperFunction::RunAsync() {
void WallpaperSetWallpaperFunction::OnWallpaperDecoded( void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
const gfx::ImageSkia& image) { const gfx::ImageSkia& image) {
base::FilePath thumbnail_path =
ash::WallpaperController::GetCustomWallpaperPath(
ash::WallpaperController::kThumbnailWallpaperSubDir,
wallpaper_files_id_, params_->details.filename);
ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
extensions::api::wallpaper::ToString(params_->details.layout)); extensions::api::wallpaper::ToString(params_->details.layout));
wallpaper_api_util::RecordCustomWallpaperLayout(layout); wallpaper_api_util::RecordCustomWallpaperLayout(layout);
...@@ -199,42 +193,13 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded( ...@@ -199,42 +193,13 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
// We need to generate thumbnail image anyway to make the current third party // We need to generate thumbnail image anyway to make the current third party
// wallpaper syncable through different devices. // wallpaper syncable through different devices.
image.EnsureRepsForSupportedScales(); image.EnsureRepsForSupportedScales();
std::unique_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
GetBlockingTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&WallpaperSetWallpaperFunction::GenerateThumbnail, this,
thumbnail_path, std::move(deep_copy)));
}
void WallpaperSetWallpaperFunction::GenerateThumbnail(
const base::FilePath& thumbnail_path,
std::unique_ptr<gfx::ImageSkia> image) {
AssertCalledOnWallpaperSequence(GetBlockingTaskRunner());
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());
scoped_refptr<base::RefCountedBytes> original_data;
scoped_refptr<base::RefCountedBytes> thumbnail_data; scoped_refptr<base::RefCountedBytes> thumbnail_data;
ash::WallpaperController::ResizeImage(*image, ash::WALLPAPER_LAYOUT_STRETCH, GenerateThumbnail(
image->width(), image->height(), image, gfx::Size(kWallpaperThumbnailWidth, kWallpaperThumbnailHeight),
&original_data, nullptr); &thumbnail_data);
ash::WallpaperController::ResizeImage( scoped_refptr<base::RefCountedBytes> original_data;
*image, ash::WALLPAPER_LAYOUT_STRETCH, GenerateThumbnail(image, image.size(), &original_data);
ash::WallpaperController::kWallpaperThumbnailWidth,
ash::WallpaperController::kWallpaperThumbnailHeight, &thumbnail_data,
nullptr);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this,
base::RetainedRef(original_data),
base::RetainedRef(thumbnail_data)));
}
void WallpaperSetWallpaperFunction::ThumbnailGenerated(
base::RefCountedBytes* original_data,
base::RefCountedBytes* thumbnail_data) {
std::unique_ptr<Value> original_result = Value::CreateWithCopiedBuffer( std::unique_ptr<Value> original_result = Value::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(original_data->front()), reinterpret_cast<const char*>(original_data->front()),
original_data->size()); original_data->size());
......
...@@ -12,10 +12,6 @@ ...@@ -12,10 +12,6 @@
#include "components/signin/core/account_id/account_id.h" #include "components/signin/core/account_id/account_id.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
namespace base {
class RefCountedBytes;
}
// Implementation of chrome.wallpaper.setWallpaper API. // Implementation of chrome.wallpaper.setWallpaper API.
// After this API being called, a jpeg encoded wallpaper will be saved to // After this API being called, a jpeg encoded wallpaper will be saved to
// /home/chronos/custom_wallpaper/{resolution}/{wallpaper_files_id_}/file_name. // /home/chronos/custom_wallpaper/{resolution}/{wallpaper_files_id_}/file_name.
...@@ -40,15 +36,6 @@ class WallpaperSetWallpaperFunction : public WallpaperFunctionBase { ...@@ -40,15 +36,6 @@ class WallpaperSetWallpaperFunction : public WallpaperFunctionBase {
private: private:
void OnWallpaperDecoded(const gfx::ImageSkia& image) override; void OnWallpaperDecoded(const gfx::ImageSkia& image) override;
// Generates thumbnail of custom wallpaper. A simple STRETCH is used for
// generating thumbnail.
void GenerateThumbnail(const base::FilePath& thumbnail_path,
std::unique_ptr<gfx::ImageSkia> image);
// Thumbnail is ready. Calls api function javascript callback.
void ThumbnailGenerated(base::RefCountedBytes* original_data,
base::RefCountedBytes* thumbnail_data);
// Called by OnURLFetchComplete(). // Called by OnURLFetchComplete().
void OnWallpaperFetched(bool success, const std::string& response); void OnWallpaperFetched(bool success, const std::string& response);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/synchronization/cancellation_flag.h" #include "base/synchronization/cancellation_flag.h"
#include "base/task_scheduler/lazy_task_runner.h" #include "base/task_scheduler/lazy_task_runner.h"
...@@ -14,6 +15,8 @@ ...@@ -14,6 +15,8 @@
#include "chromeos/login/login_state.h" #include "chromeos/login/login_state.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/image/image_skia_operations.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -115,11 +118,12 @@ class WallpaperFunctionBase::UnsafeWallpaperDecoder ...@@ -115,11 +118,12 @@ class WallpaperFunctionBase::UnsafeWallpaperDecoder
WallpaperFunctionBase::UnsafeWallpaperDecoder* WallpaperFunctionBase::UnsafeWallpaperDecoder*
WallpaperFunctionBase::unsafe_wallpaper_decoder_; WallpaperFunctionBase::unsafe_wallpaper_decoder_;
WallpaperFunctionBase::WallpaperFunctionBase() { const int WallpaperFunctionBase::kWallpaperThumbnailWidth = 108;
} const int WallpaperFunctionBase::kWallpaperThumbnailHeight = 68;
WallpaperFunctionBase::~WallpaperFunctionBase() { WallpaperFunctionBase::WallpaperFunctionBase() = default;
}
WallpaperFunctionBase::~WallpaperFunctionBase() = default;
base::SequencedTaskRunner* WallpaperFunctionBase::GetBlockingTaskRunner() { base::SequencedTaskRunner* WallpaperFunctionBase::GetBlockingTaskRunner() {
return wallpaper_api_util::g_blocking_task_runner.Get().get(); return wallpaper_api_util::g_blocking_task_runner.Get().get();
...@@ -145,13 +149,24 @@ void WallpaperFunctionBase::StartDecode(const std::vector<char>& data) { ...@@ -145,13 +149,24 @@ void WallpaperFunctionBase::StartDecode(const std::vector<char>& data) {
} }
void WallpaperFunctionBase::OnCancel() { void WallpaperFunctionBase::OnCancel() {
unsafe_wallpaper_decoder_ = NULL; unsafe_wallpaper_decoder_ = nullptr;
SetError(wallpaper_api_util::kCancelWallpaperMessage); SetError(wallpaper_api_util::kCancelWallpaperMessage);
SendResponse(false); SendResponse(false);
} }
void WallpaperFunctionBase::OnFailure(const std::string& error) { void WallpaperFunctionBase::OnFailure(const std::string& error) {
unsafe_wallpaper_decoder_ = NULL; unsafe_wallpaper_decoder_ = nullptr;
SetError(error); SetError(error);
SendResponse(false); SendResponse(false);
} }
void WallpaperFunctionBase::GenerateThumbnail(
const gfx::ImageSkia& image,
const gfx::Size& size,
scoped_refptr<base::RefCountedBytes>* thumbnail_data_out) {
*thumbnail_data_out = new base::RefCountedBytes();
gfx::ImageSkia thumbnail_image = gfx::ImageSkiaOperations::CreateResizedImage(
image, skia::ImageOperations::RESIZE_LANCZOS3, size);
gfx::JPEGCodec::Encode(*thumbnail_image.bitmap(), 90 /*quality=*/,
&(*thumbnail_data_out)->data());
}
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
namespace base { namespace base {
class RefCountedBytes;
class SequencedTaskRunner; class SequencedTaskRunner;
} }
...@@ -32,6 +33,9 @@ void RecordCustomWallpaperLayout(const ash::WallpaperLayout& layout); ...@@ -32,6 +33,9 @@ void RecordCustomWallpaperLayout(const ash::WallpaperLayout& layout);
// wallpaper data. // wallpaper data.
class WallpaperFunctionBase : public AsyncExtensionFunction { class WallpaperFunctionBase : public AsyncExtensionFunction {
public: public:
static const int kWallpaperThumbnailWidth;
static const int kWallpaperThumbnailHeight;
WallpaperFunctionBase(); WallpaperFunctionBase();
// For tasks that are worth blocking shutdown, i.e. saving user's custom // For tasks that are worth blocking shutdown, i.e. saving user's custom
...@@ -62,6 +66,12 @@ class WallpaperFunctionBase : public AsyncExtensionFunction { ...@@ -62,6 +66,12 @@ class WallpaperFunctionBase : public AsyncExtensionFunction {
// Handles failure case. Sets error message. // Handles failure case. Sets error message.
void OnFailure(const std::string& error); void OnFailure(const std::string& error);
// Resize the image to |size|, encode it and save to |thumbnail_data_out|.
void GenerateThumbnail(
const gfx::ImageSkia& image,
const gfx::Size& size,
scoped_refptr<base::RefCountedBytes>* thumbnail_data_out);
private: private:
virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) = 0; virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) = 0;
}; };
......
...@@ -522,11 +522,6 @@ bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() { ...@@ -522,11 +522,6 @@ bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() {
void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
const gfx::ImageSkia& image) { const gfx::ImageSkia& image) {
base::FilePath thumbnail_path =
ash::WallpaperController::GetCustomWallpaperPath(
ash::WallpaperController::kThumbnailWallpaperSubDir,
wallpaper_files_id_, params->file_name);
ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
wallpaper_base::ToString(params->layout)); wallpaper_base::ToString(params->layout));
wallpaper_api_util::RecordCustomWallpaperLayout(layout); wallpaper_api_util::RecordCustomWallpaperLayout(layout);
...@@ -538,45 +533,19 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( ...@@ -538,45 +533,19 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
if (params->generate_thumbnail) { if (params->generate_thumbnail) {
image.EnsureRepsForSupportedScales(); image.EnsureRepsForSupportedScales();
std::unique_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); scoped_refptr<base::RefCountedBytes> thumbnail_data;
// Generates thumbnail before call api function callback. We can then GenerateThumbnail(
// request thumbnail in the javascript callback. image, gfx::Size(kWallpaperThumbnailWidth, kWallpaperThumbnailHeight),
GetBlockingTaskRunner()->PostTask( &thumbnail_data);
FROM_HERE, SetResult(Value::CreateWithCopiedBuffer(
base::BindOnce( reinterpret_cast<const char*>(thumbnail_data->front()),
&WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, thumbnail_data->size()));
this, thumbnail_path, std::move(deep_copy))); SendResponse(true);
} else { } else {
SendResponse(true); SendResponse(true);
} }
} }
void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
const base::FilePath& thumbnail_path,
std::unique_ptr<gfx::ImageSkia> image) {
AssertCalledOnWallpaperSequence(GetBlockingTaskRunner());
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());
scoped_refptr<base::RefCountedBytes> data;
ash::WallpaperController::ResizeImage(
*image, ash::WALLPAPER_LAYOUT_STRETCH,
ash::WallpaperController::kWallpaperThumbnailWidth,
ash::WallpaperController::kWallpaperThumbnailHeight, &data, nullptr);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(
&WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, this,
base::RetainedRef(data)));
}
void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated(
base::RefCountedBytes* data) {
SetResult(Value::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(data->front()), data->size()));
SendResponse(true);
}
WallpaperPrivateSetCustomWallpaperLayoutFunction:: WallpaperPrivateSetCustomWallpaperLayoutFunction::
WallpaperPrivateSetCustomWallpaperLayoutFunction() {} WallpaperPrivateSetCustomWallpaperLayoutFunction() {}
......
...@@ -19,10 +19,6 @@ class CollectionInfoFetcher; ...@@ -19,10 +19,6 @@ class CollectionInfoFetcher;
class ImageInfoFetcher; class ImageInfoFetcher;
} // namespace backdrop_wallpaper_handlers } // namespace backdrop_wallpaper_handlers
namespace base {
class RefCountedBytes;
} // namespace base
// Wallpaper manager strings. // Wallpaper manager strings.
class WallpaperPrivateGetStringsFunction : public UIThreadExtensionFunction { class WallpaperPrivateGetStringsFunction : public UIThreadExtensionFunction {
public: public:
...@@ -156,14 +152,6 @@ class WallpaperPrivateSetCustomWallpaperFunction ...@@ -156,14 +152,6 @@ class WallpaperPrivateSetCustomWallpaperFunction
private: private:
void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) override; void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) override;
// Generates thumbnail of custom wallpaper. A simple STRETCH is used for
// generating thunbail.
void GenerateThumbnail(const base::FilePath& thumbnail_path,
std::unique_ptr<gfx::ImageSkia> image);
// Thumbnail is ready. Calls api function javascript callback.
void ThumbnailGenerated(base::RefCountedBytes* data);
std::unique_ptr< std::unique_ptr<
extensions::api::wallpaper_private::SetCustomWallpaper::Params> extensions::api::wallpaper_private::SetCustomWallpaper::Params>
params; params;
......
...@@ -33,6 +33,7 @@ void TestWallpaperController::Init( ...@@ -33,6 +33,7 @@ void TestWallpaperController::Init(
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
const base::FilePath& chromeos_wallpapers_path, const base::FilePath& chromeos_wallpapers_path,
const base::FilePath& chromeos_custom_wallpapers_path, const base::FilePath& chromeos_custom_wallpapers_path,
const base::FilePath& device_policy_wallpaper_path,
bool is_device_wallpaper_policy_enforced) { bool is_device_wallpaper_policy_enforced) {
was_client_set_ = true; was_client_set_ = true;
} }
......
...@@ -41,6 +41,7 @@ class TestWallpaperController : ash::mojom::WallpaperController { ...@@ -41,6 +41,7 @@ class TestWallpaperController : ash::mojom::WallpaperController {
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
const base::FilePath& chromeos_wallpapers_path, const base::FilePath& chromeos_wallpapers_path,
const base::FilePath& chromeos_custom_wallpapers_path, const base::FilePath& chromeos_custom_wallpapers_path,
const base::FilePath& device_policy_wallpaper_path,
bool is_device_wallpaper_policy_enforced) override; bool is_device_wallpaper_policy_enforced) override;
void SetCustomWallpaper(ash::mojom::WallpaperUserInfoPtr user_info, void SetCustomWallpaper(ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id, const std::string& wallpaper_files_id,
......
...@@ -417,20 +417,10 @@ void WallpaperControllerClient::BindAndSetClient() { ...@@ -417,20 +417,10 @@ void WallpaperControllerClient::BindAndSetClient() {
CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS, CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS,
&chromeos_custom_wallpapers_path)); &chromeos_custom_wallpapers_path));
// Set the static variables in WallpaperController to make it work under MASH.
// The reason we do this is so that the static utility functions in
// WallpaperController in ash continue to work under MASH.
// TODO(wzang|xdai): Create a WallpaperPaths class under //ash/public/cpp and
// move all the unititly functions there. See https://crbug.com/795159.
ash::WallpaperController::dir_user_data_path_ = user_data_path;
ash::WallpaperController::dir_chrome_os_wallpapers_path_ =
chromeos_wallpapers_path;
ash::WallpaperController::dir_chrome_os_custom_wallpapers_path_ =
chromeos_custom_wallpapers_path;
wallpaper_controller_->Init( wallpaper_controller_->Init(
std::move(client), user_data_path, chromeos_wallpapers_path, std::move(client), user_data_path, chromeos_wallpapers_path,
chromeos_custom_wallpapers_path, chromeos_custom_wallpapers_path,
policy_handler_.device_wallpaper_file_path(),
policy_handler_.IsDeviceWallpaperPolicyEnforced()); policy_handler_.IsDeviceWallpaperPolicyEnforced());
} }
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
#include "chrome/browser/ui/ash/wallpaper_policy_handler.h" #include "chrome/browser/ui/ash/wallpaper_policy_handler.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/customization/customization_wallpaper_downloader.h" #include "chrome/browser/chromeos/customization/customization_wallpaper_downloader.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/settings/cros_settings_names.h" #include "chromeos/settings/cros_settings_names.h"
#include "crypto/sha2.h" #include "crypto/sha2.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -22,6 +23,10 @@ using chromeos::CrosSettings; ...@@ -22,6 +23,10 @@ using chromeos::CrosSettings;
namespace { namespace {
// The directory and file name to save the downloaded device policy wallpaper.
constexpr char kDeviceWallpaperDir[] = "device_wallpaper";
constexpr char kDeviceWallpaperFile[] = "device_wallpaper_image.jpg";
// A helper function to check the existing/downloaded device wallpaper file's // A helper function to check the existing/downloaded device wallpaper file's
// hash value matches with the hash value provided in the policy settings. // hash value matches with the hash value provided in the policy settings.
bool CheckWallpaperFileMatchHash(const base::FilePath& device_wallpaper_file, bool CheckWallpaperFileMatchHash(const base::FilePath& device_wallpaper_file,
...@@ -54,6 +59,15 @@ WallpaperPolicyHandler::WallpaperPolicyHandler(Delegate* delegate) ...@@ -54,6 +59,15 @@ WallpaperPolicyHandler::WallpaperPolicyHandler(Delegate* delegate)
base::Bind( base::Bind(
&WallpaperPolicyHandler::ShowUserNamesOnSignInPolicyChanged, &WallpaperPolicyHandler::ShowUserNamesOnSignInPolicyChanged,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
// Initialize the desired file path for device policy wallpaper. The path will
// be used by WallpaperController to access the wallpaper file.
base::FilePath chromeos_wallpapers_path;
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS,
&chromeos_wallpapers_path));
device_wallpaper_file_path_ =
chromeos_wallpapers_path.Append(kDeviceWallpaperDir)
.Append(kDeviceWallpaperFile);
} }
WallpaperPolicyHandler::~WallpaperPolicyHandler() { WallpaperPolicyHandler::~WallpaperPolicyHandler() {
...@@ -93,12 +107,6 @@ bool WallpaperPolicyHandler::GetDeviceWallpaperPolicyStrings( ...@@ -93,12 +107,6 @@ bool WallpaperPolicyHandler::GetDeviceWallpaperPolicyStrings(
} }
void WallpaperPolicyHandler::DeviceWallpaperPolicyChanged() { void WallpaperPolicyHandler::DeviceWallpaperPolicyChanged() {
// Get the desired file path for device policy wallpaper first.
if (device_wallpaper_file_path_.empty()) {
device_wallpaper_file_path_ =
ash::WallpaperController::GetDevicePolicyWallpaperFilePath();
}
// First check if the device policy was cleared. // First check if the device policy was cleared.
const base::DictionaryValue* dict = nullptr; const base::DictionaryValue* dict = nullptr;
if (!CrosSettings::Get()->GetDictionary(chromeos::kDeviceWallpaperImage, if (!CrosSettings::Get()->GetDictionary(chromeos::kDeviceWallpaperImage,
......
...@@ -44,6 +44,10 @@ class WallpaperPolicyHandler { ...@@ -44,6 +44,10 @@ class WallpaperPolicyHandler {
// Returns true if user names should be shown on the login screen. // Returns true if user names should be shown on the login screen.
bool ShouldShowUserNamesOnLogin(); bool ShouldShowUserNamesOnLogin();
base::FilePath device_wallpaper_file_path() {
return device_wallpaper_file_path_;
}
private: private:
// Gets the device policy controlled wallpaper's url and hash values. Returns // Gets the device policy controlled wallpaper's url and hash values. Returns
// false if the values can't be retrieved. // false if the values can't be retrieved.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment