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

mash: Remove //ash dependency in wallpaper_private_api.cc

We need this because:
1) Mustash requires all //ash dependency except //ash/public to be
   removed from //chrome.
2) Currently saving and retrieving online wallpapers are handled
   separately in //chrome and //ash, and it has duplicate logic in the
   path calculation.
3) Currently wallpaper_private_api.cc is responsible for saving online
   wallpapers, so it defeats the goal of making wallpaper paths
   internal to //ash.

Also fixed a bug: on Linux build, online wallpaper is lost at login
screen.

Bug: 827062
Change-Id: I0d3ea5daf537db6e189c7a8b2ede469521e9dcbf
Reviewed-on: https://chromium-review.googlesource.com/1013211Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552244}
parent b338af18
......@@ -79,21 +79,37 @@ interface WallpaperController {
gfx.mojom.ImageSkia image,
bool preview_mode);
// Sets wallpaper from the wallpaper picker selection, i.e., the wallpaper
// type is ONLINE.
// Sets wallpaper from the Chrome OS wallpaper picker. If the wallpaper file
// corresponding to |url| already exists in local file system (i.e.
// |SetOnlineWallpaperFromData| was called earlier with the same |url|),
// returns true and sets wallpaper for the user, otherwise returns false.
// |user_info|: The user's information related to wallpaper.
// |image|: The wallpaper image.
// |url|: The url corresponding to this wallpaper. Used as a placeholder for
// the location in WallpaperInfo.
// |url|: The wallpaper url.
// |layout|: The layout of the wallpaper, used for wallpaper resizing.
// |preview_mode|: If true, show the wallpaper immediately but doesn't change
// the user wallpaper info until |ConfirmPreviewWallpaper| is
// called.
SetOnlineWallpaper(WallpaperUserInfo user_info,
gfx.mojom.ImageSkia image,
string url,
WallpaperLayout layout,
bool preview_mode);
// |file_exists|: If the wallpaper file exists in local file system.
SetOnlineWallpaperIfExists(WallpaperUserInfo user_info,
url.mojom.Url url,
WallpaperLayout layout,
bool preview_mode) => (bool file_exists);
// Sets wallpaper from the Chrome OS wallpaper picker and saves the wallpaper
// to local file system. After this, |SetOnlineWallpaperIfExists| will return
// true for the same |url|, so that there's no need to provide |image_data|
// when the same wallpaper needs to be set again or for another user.
// |user_info|: The user's information related to wallpaper.
// |url|: The wallpaper url.
// |layout|: The layout of the wallpaper, used for wallpaper resizing.
// |preview_mode|: If true, show the wallpaper immediately but doesn't change
// the user wallpaper info until |ConfirmPreviewWallpaper| is
// called.
SetOnlineWallpaperFromData(WallpaperUserInfo user_info,
string image_data,
url.mojom.Url url,
WallpaperLayout layout,
bool preview_mode);
// Sets the user's wallpaper to be the default wallpaper. Note: different user
// types may have different default wallpapers.
......@@ -194,6 +210,11 @@ interface WallpaperController {
// |wallpaper_files_id|: The file id for user_info.account_id.
RemovePolicyWallpaper(WallpaperUserInfo user_info, string wallpaper_files_id);
// Returns the file names of the wallpapers that exist in local file system
// (i.e. |SetOnlineWallpaperFromData| was called earlier). The file name is
// used as id to identify which wallpapers are available to be set offline.
GetOfflineWallpaperList() => (array<string> file_names);
// Sets wallpaper animation duration. Passing an empty value disables the
// animation.
SetAnimationDuration(mojo_base.mojom.TimeDelta animation_duration);
......
This diff is collapsed.
......@@ -109,6 +109,11 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Returns the appropriate wallpaper resolution for all root windows.
static WallpaperResolution GetAppropriateResolution();
// Returns the path of the online wallpaper corresponding to |url| and
// |resolution|.
static base::FilePath GetOnlineWallpaperPath(const GURL& url,
WallpaperResolution resolution);
// Returns wallpaper subdirectory name for current resolution.
static std::string GetCustomWallpaperSubdirForCurrentResolution();
......@@ -311,11 +316,17 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
WallpaperLayout layout,
const gfx::ImageSkia& image,
bool preview_mode) override;
void SetOnlineWallpaper(mojom::WallpaperUserInfoPtr user_info,
const gfx::ImageSkia& image,
const std::string& url,
WallpaperLayout layout,
bool preview_mode) override;
void SetOnlineWallpaperIfExists(
mojom::WallpaperUserInfoPtr user_info,
const GURL& url,
WallpaperLayout layout,
bool preview_mode,
SetOnlineWallpaperIfExistsCallback callback) override;
void SetOnlineWallpaperFromData(mojom::WallpaperUserInfoPtr user_info,
const std::string& image_data,
const GURL& url,
WallpaperLayout layout,
bool preview_mode) override;
void SetDefaultWallpaper(mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id,
bool show_wallpaper) override;
......@@ -342,6 +353,8 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
const std::string& wallpaper_files_id) override;
void RemovePolicyWallpaper(mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id) override;
void GetOfflineWallpaperList(
GetOfflineWallpaperListCallback callback) override;
void SetAnimationDuration(base::TimeDelta animation_duration) override;
void OpenWallpaperPickerIfAllowed() override;
void MinimizeInactiveWindows(const std::string& user_id_hash) override;
......@@ -364,7 +377,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
void OnColorCalculationComplete() override;
// Sets dummy values for wallpaper directories.
void InitializePathsForTesting();
void InitializePathsForTesting(
const base::FilePath& user_data_path,
const base::FilePath& chromeos_wallpapers_path,
const base::FilePath& chromeos_custom_wallpapers_path);
// Shows a default wallpaper for testing, without changing users' wallpaper
// info.
......@@ -396,6 +412,14 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
base::FilePath file_path;
};
struct OnlineWallpaperParams {
AccountId account_id;
bool is_ephemeral;
GURL url;
WallpaperLayout layout;
bool preview_mode;
};
// Creates a WallpaperWidgetController for |root_window|.
void InstallDesktopController(aura::Window* root_window);
......@@ -417,12 +441,24 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
void RemoveUserWallpaperImpl(const AccountId& account_id,
const std::string& wallpaper_files_id);
// Used as the callback of checking ONLINE wallpaper existence in
// |SetOnlineWallpaperIfExists|. Initiates reading and decoding the wallpaper
// if |file_path| is not empty.
void SetOnlineWallpaperFromPath(SetOnlineWallpaperIfExistsCallback callback,
const OnlineWallpaperParams& params,
const base::FilePath& file_path);
// Used as the callback of decoding wallpapers of type ONLINE. Saves the image
// to local file if |save_file| is true, and shows the wallpaper immediately
// if |params.account_id| is the active user.
void OnOnlineWallpaperDecoded(const OnlineWallpaperParams& params,
bool save_file,
const gfx::ImageSkia& image);
// Implementation of |SetOnlineWallpaper|. Shows the wallpaper on screen if
// |show_wallpaper| is true.
void SetOnlineWallpaperImpl(const gfx::ImageSkia& image,
const std::string& url,
const WallpaperLayout& layout,
mojom::WallpaperUserInfoPtr user_info,
void SetOnlineWallpaperImpl(const OnlineWallpaperParams& params,
const gfx::ImageSkia& image,
bool show_wallpaper);
// Decodes |account_id|'s wallpaper. Shows the decoded wallpaper if
......@@ -459,10 +495,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
const WallpaperInfo& info,
bool show_wallpaper);
// Used as the callback of wallpaper decoding. (Wallpapers of type DEFAULT
// and DEVICE should use their corresponding |*Decoded|, and all other types
// should use this.) Shows the wallpaper now if |show_wallpaper| is true.
// Otherwise, only update the cache.
// Used as the callback of wallpaper decoding. (Wallpapers of type ONLINE,
// DEFAULT and DEVICE should use their corresponding |*Decoded|, and all other
// types should use this.) Shows the wallpaper immediately if |show_wallpaper|
// is true. Otherwise, only updates the cache.
void OnWallpaperDecoded(const AccountId& account_id,
const user_manager::UserType& user_type,
const base::FilePath& path,
......
......@@ -158,14 +158,8 @@ void WallpaperFunctionBase::OnCancel() {
}
void WallpaperFunctionBase::OnFailure(const std::string& error) {
OnFailureWithArguments(nullptr, error);
}
void WallpaperFunctionBase::OnFailureWithArguments(
std::unique_ptr<base::ListValue> args,
const std::string& error) {
unsafe_wallpaper_decoder_ = nullptr;
Respond(args ? ErrorWithArguments(std::move(args), error) : Error(error));
Respond(Error(error));
}
void WallpaperFunctionBase::GenerateThumbnail(
......
......@@ -66,13 +66,6 @@ class WallpaperFunctionBase : public UIThreadExtensionFunction {
// Handles failure case. Sets error message.
void OnFailure(const std::string& error);
// Handles failure case with setting an error message with results argument.
// TODO(wzang): This is a bug, we shouldn't be sending arguments when the
// function fails. Only used in setWallpaperIfExists function. See
// https://crbug.com/830212 for details.
void OnFailureWithArguments(std::unique_ptr<base::ListValue> args,
const std::string& error);
// Resize the image to |size|, encode it and save to |thumbnail_data_out|.
void GenerateThumbnail(
const gfx::ImageSkia& image,
......
......@@ -60,7 +60,7 @@ class WallpaperPrivateGetSyncSettingFunction
};
class WallpaperPrivateSetWallpaperIfExistsFunction
: public WallpaperFunctionBase {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists",
WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS)
......@@ -74,25 +74,13 @@ class WallpaperPrivateSetWallpaperIfExistsFunction
ResponseAction Run() override;
private:
void OnWallpaperDecoded(const gfx::ImageSkia& image) override;
// File doesn't exist. Sets javascript callback parameter to false.
void OnFileNotExists(const std::string& error);
// Reads file specified by |file_path|. If success, post a task to start
// decoding the file.
void ReadFileAndInitiateStartDecode(const base::FilePath& file_path,
const base::FilePath& fallback_path);
// Responds with the |file_exists| result.
void OnSetOnlineWallpaperIfExistsCallback(bool file_exists);
std::unique_ptr<
extensions::api::wallpaper_private::SetWallpaperIfExists::Params>
params;
// User id of the active user when this api is been called.
AccountId account_id_ = EmptyAccountId();
DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateSetWallpaperIfExistsFunction);
};
class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
class WallpaperPrivateSetWallpaperFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper",
WALLPAPERPRIVATE_SETWALLPAPER)
......@@ -106,23 +94,7 @@ class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
ResponseAction Run() override;
private:
void OnWallpaperDecoded(const gfx::ImageSkia& image) override;
// Saves the image data to a file.
void SaveToFile();
// Sets wallpaper to the decoded image.
void SetDecodedWallpaper(std::unique_ptr<gfx::ImageSkia> image);
std::unique_ptr<extensions::api::wallpaper_private::SetWallpaper::Params>
params;
// The decoded wallpaper. It may accessed from UI thread to set wallpaper or
// FILE thread to resize and save wallpaper to disk.
gfx::ImageSkia wallpaper_;
// User account id of the active user when this api is been called.
AccountId account_id_ = EmptyAccountId();
DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateSetWallpaperFunction);
};
class WallpaperPrivateResetWallpaperFunction
......@@ -276,12 +248,11 @@ class WallpaperPrivateGetOfflineWallpaperListFunction
ResponseAction Run() override;
private:
// Enumerates the list of files in online wallpaper directory.
void GetList();
// Responds with the list of urls.
void OnOfflineWallpaperListReturned(
const std::vector<std::string>& file_names);
// Sends the list of files to extension api caller. If no files or no
// directory, sends empty list.
void OnComplete(const std::vector<std::string>& file_list);
DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateGetOfflineWallpaperListFunction);
};
// The wallpaper UMA is recorded when a new wallpaper is set, either by the
......
......@@ -45,13 +45,23 @@ void TestWallpaperController::SetCustomWallpaper(
ash::WallpaperLayout layout,
const gfx::ImageSkia& image,
bool preview_mode) {
set_custom_wallpaper_count_++;
++set_custom_wallpaper_count_;
}
void TestWallpaperController::SetOnlineWallpaper(
void TestWallpaperController::SetOnlineWallpaperIfExists(
ash::mojom::WallpaperUserInfoPtr user_info,
const gfx::ImageSkia& image,
const std::string& url,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode,
ash::mojom::WallpaperController::SetOnlineWallpaperIfExistsCallback
callback) {
NOTIMPLEMENTED();
}
void TestWallpaperController::SetOnlineWallpaperFromData(
ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& image_data,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode) {
NOTIMPLEMENTED();
......@@ -61,7 +71,7 @@ void TestWallpaperController::SetDefaultWallpaper(
ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id,
bool show_wallpaper) {
set_default_wallpaper_count_++;
++set_default_wallpaper_count_;
}
void TestWallpaperController::SetCustomizedDefaultWallpaperPaths(
......@@ -118,7 +128,7 @@ void TestWallpaperController::ShowSigninWallpaper() {
void TestWallpaperController::RemoveUserWallpaper(
ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id) {
remove_user_wallpaper_count_++;
++remove_user_wallpaper_count_;
}
void TestWallpaperController::RemovePolicyWallpaper(
......@@ -127,6 +137,11 @@ void TestWallpaperController::RemovePolicyWallpaper(
NOTIMPLEMENTED();
}
void TestWallpaperController::GetOfflineWallpaperList(
ash::mojom::WallpaperController::GetOfflineWallpaperListCallback callback) {
NOTIMPLEMENTED();
}
void TestWallpaperController::SetAnimationDuration(
base::TimeDelta animation_duration) {
NOTIMPLEMENTED();
......
......@@ -49,11 +49,18 @@ class TestWallpaperController : ash::mojom::WallpaperController {
ash::WallpaperLayout layout,
const gfx::ImageSkia& image,
bool preview_mode) override;
void SetOnlineWallpaper(ash::mojom::WallpaperUserInfoPtr user_info,
const gfx::ImageSkia& image,
const std::string& url,
ash::WallpaperLayout layout,
bool preview_mode) override;
void SetOnlineWallpaperIfExists(
ash::mojom::WallpaperUserInfoPtr user_info,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode,
ash::mojom::WallpaperController::SetOnlineWallpaperIfExistsCallback
callback) override;
void SetOnlineWallpaperFromData(ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& image_data,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode) override;
void SetDefaultWallpaper(ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id,
bool show_wallpaper) override;
......@@ -82,6 +89,9 @@ class TestWallpaperController : ash::mojom::WallpaperController {
const std::string& wallpaper_files_id) override;
void RemovePolicyWallpaper(ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id) override;
void GetOfflineWallpaperList(
ash::mojom::WallpaperController::GetOfflineWallpaperListCallback callback)
override;
void SetAnimationDuration(base::TimeDelta animation_duration) override;
void OpenWallpaperPickerIfAllowed() override;
void MinimizeInactiveWindows(const std::string& user_id_hash) override;
......
......@@ -193,17 +193,33 @@ void WallpaperControllerClient::SetCustomWallpaper(
layout, image, preview_mode);
}
void WallpaperControllerClient::SetOnlineWallpaper(const AccountId& account_id,
const gfx::ImageSkia& image,
const std::string& url,
ash::WallpaperLayout layout,
bool preview_mode) {
void WallpaperControllerClient::SetOnlineWallpaperIfExists(
const AccountId& account_id,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode,
ash::mojom::WallpaperController::SetOnlineWallpaperIfExistsCallback
callback) {
ash::mojom::WallpaperUserInfoPtr user_info =
AccountIdToWallpaperUserInfo(account_id);
if (!user_info)
return;
wallpaper_controller_->SetOnlineWallpaperIfExists(
std::move(user_info), url, layout, preview_mode, std::move(callback));
}
void WallpaperControllerClient::SetOnlineWallpaperFromData(
const AccountId& account_id,
const std::string& image_data,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode) {
ash::mojom::WallpaperUserInfoPtr user_info =
AccountIdToWallpaperUserInfo(account_id);
if (!user_info)
return;
wallpaper_controller_->SetOnlineWallpaper(std::move(user_info), image, url,
layout, preview_mode);
wallpaper_controller_->SetOnlineWallpaperFromData(
std::move(user_info), image_data, url, layout, preview_mode);
}
void WallpaperControllerClient::SetDefaultWallpaper(const AccountId& account_id,
......@@ -350,6 +366,11 @@ void WallpaperControllerClient::RemovePolicyWallpaper(
GetFilesId(account_id));
}
void WallpaperControllerClient::GetOfflineWallpaperList(
ash::mojom::WallpaperController::GetOfflineWallpaperListCallback callback) {
wallpaper_controller_->GetOfflineWallpaperList(std::move(callback));
}
void WallpaperControllerClient::SetAnimationDuration(
const base::TimeDelta& animation_duration) {
wallpaper_controller_->SetAnimationDuration(animation_duration);
......
......@@ -37,11 +37,18 @@ class WallpaperControllerClient : public ash::mojom::WallpaperControllerClient,
ash::WallpaperLayout layout,
const gfx::ImageSkia& image,
bool preview_mode);
void SetOnlineWallpaper(const AccountId& account_id,
const gfx::ImageSkia& image,
const std::string& url,
ash::WallpaperLayout layout,
bool preview_mode);
void SetOnlineWallpaperIfExists(
const AccountId& account_id,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode,
ash::mojom::WallpaperController::SetOnlineWallpaperIfExistsCallback
callback);
void SetOnlineWallpaperFromData(const AccountId& account_id,
const std::string& image_data,
const GURL& url,
ash::WallpaperLayout layout,
bool preview_mode);
void SetDefaultWallpaper(const AccountId& account_id, bool show_wallpaper);
void SetCustomizedDefaultWallpaperPaths(
const base::FilePath& customized_default_small_path,
......@@ -63,6 +70,9 @@ class WallpaperControllerClient : public ash::mojom::WallpaperControllerClient,
void ShowSigninWallpaper();
void RemoveUserWallpaper(const AccountId& account_id);
void RemovePolicyWallpaper(const AccountId& account_id);
void GetOfflineWallpaperList(
ash::mojom::WallpaperController::GetOfflineWallpaperListCallback
callback);
void SetAnimationDuration(const base::TimeDelta& animation_duration);
void OpenWallpaperPickerIfAllowed();
void MinimizeInactiveWindows(const std::string& user_id_hash);
......
......@@ -106,13 +106,13 @@ chrome.test.getConfig(function(config) {
chrome.wallpaperPrivate.setWallpaperIfExists(
'http://dummyurl/test1.jpg', 'CENTER_CROPPED',
false /*previewMode=*/,
fail('Failed to set wallpaper test1.jpg from file system.'));
fail('The wallpaper doesn\'t exist in local file system.'));
// Attempt to preview wallpaper from a non-existent file should
// also fail.
chrome.wallpaperPrivate.setWallpaperIfExists(
'http://dummyurl/test1.jpg', 'CENTER_CROPPED',
true /*previewMode=*/,
fail('Failed to set wallpaper test1.jpg from file system.'));
fail('The wallpaper doesn\'t exist in local file system.'));
}));
},
function getAndSetThumbnail() {
......
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