base::FilePath file_path = data_dir.Append(file_name);
return base::PathExists(file_path) ||
- (file_util::WriteFile(file_path, data.c_str(),
- data.size()) != -1);
+ (base::WriteFile(file_path, data.c_str(), data.size()) != -1);
}
// Gets |file_name| from directory with |key|. Return false if the directory can
} // namespace
-bool WallpaperPrivateGetStringsFunction::RunImpl() {
+bool WallpaperPrivateGetStringsFunction::RunSync() {
base::DictionaryValue* dict = new base::DictionaryValue();
SetResult(dict);
WallpaperPrivateSetWallpaperIfExistsFunction::
~WallpaperPrivateSetWallpaperIfExistsFunction() {}
-bool WallpaperPrivateSetWallpaperIfExistsFunction::RunImpl() {
+bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() {
params = set_wallpaper_if_exists::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
- std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+ user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email();
base::FilePath wallpaper_path;
base::FilePath fallback_path;
- ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
- desktop_background_controller()->GetAppropriateResolution();
+ chromeos::WallpaperManager::WallpaperResolution resolution =
+ chromeos::WallpaperManager::GetAppropriateResolution();
std::string file_name = GURL(params->url).ExtractFileName();
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS,
&wallpaper_path));
fallback_path = wallpaper_path.Append(file_name);
if (params->layout != wallpaper_private::WALLPAPER_LAYOUT_STRETCH &&
- resolution == ash::WALLPAPER_RESOLUTION_SMALL) {
+ resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name).InsertBeforeExtension(
chromeos::kSmallWallpaperSuffix).value();
}
}
void WallpaperPrivateSetWallpaperIfExistsFunction::OnWallpaperDecoded(
- const gfx::ImageSkia& wallpaper) {
+ const gfx::ImageSkia& image) {
// Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
unsafe_wallpaper_decoder_ = NULL;
ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
wallpaper_private::ToString(params->layout));
- wallpaper_manager->SetWallpaperFromImageSkia(wallpaper, layout);
+ bool update_wallpaper =
+ user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
+ wallpaper_manager->SetWallpaperFromImageSkia(
+ user_id_, image, layout, update_wallpaper);
bool is_persistent =
!chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral();
chromeos::WallpaperInfo info = {
chromeos::User::ONLINE,
base::Time::Now().LocalMidnight()
};
- std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
- wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent);
+ wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent);
SetResult(base::Value::CreateBooleanValue(true));
SendResponse(true);
}
WallpaperPrivateSetWallpaperFunction::~WallpaperPrivateSetWallpaperFunction() {
}
-bool WallpaperPrivateSetWallpaperFunction::RunImpl() {
+bool WallpaperPrivateSetWallpaperFunction::RunAsync() {
params = set_wallpaper::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
// Gets email address while at UI thread.
- email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+ user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email();
StartDecode(params->wallpaper);
}
void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded(
- const gfx::ImageSkia& wallpaper) {
- wallpaper_ = wallpaper;
+ const gfx::ImageSkia& image) {
+ wallpaper_ = image;
// Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
unsafe_wallpaper_decoder_ = NULL;
// ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if
// post to another thread.
BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
+ BrowserThread::UI,
+ FROM_HERE,
base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper,
- this, base::Passed(&deep_copy)));
- chromeos::UserImage wallpaper(wallpaper_);
+ this,
+ base::Passed(deep_copy.Pass())));
base::FilePath wallpaper_dir;
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
// Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
// maintain the aspect ratio after resize.
chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
- wallpaper,
+ wallpaper_,
file_path,
ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
- ash::kSmallWallpaperMaxWidth,
- ash::kSmallWallpaperMaxHeight);
+ chromeos::kSmallWallpaperMaxWidth,
+ chromeos::kSmallWallpaperMaxHeight,
+ NULL);
} else {
std::string error = base::StringPrintf(
"Failed to create/write wallpaper to %s.", file_name.c_str());
}
void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper(
- scoped_ptr<gfx::ImageSkia> wallpaper) {
+ scoped_ptr<gfx::ImageSkia> image) {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
wallpaper_private::ToString(params->layout));
- wallpaper_manager->SetWallpaperFromImageSkia(*wallpaper.get(), layout);
+ bool update_wallpaper =
+ user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
+ wallpaper_manager->SetWallpaperFromImageSkia(
+ user_id_, *image.get(), layout, update_wallpaper);
+
bool is_persistent =
!chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral();
chromeos::WallpaperInfo info = {
chromeos::User::ONLINE,
base::Time::Now().LocalMidnight()
};
- wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent);
+ wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent);
SendResponse(true);
}
WallpaperPrivateResetWallpaperFunction::
~WallpaperPrivateResetWallpaperFunction() {}
-bool WallpaperPrivateResetWallpaperFunction::RunImpl() {
+bool WallpaperPrivateResetWallpaperFunction::RunAsync() {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
chromeos::UserManager* user_manager = chromeos::UserManager::Get();
- std::string email = user_manager->GetLoggedInUser()->email();
- wallpaper_manager->RemoveUserWallpaperInfo(email);
+ std::string user_id = user_manager->GetActiveUser()->email();
+ wallpaper_manager->RemoveUserWallpaperInfo(user_id);
chromeos::WallpaperInfo info = {
"",
};
bool is_persistent =
!user_manager->IsCurrentUserNonCryptohomeDataEphemeral();
- wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent);
- wallpaper_manager->SetDefaultWallpaperNow();
+ wallpaper_manager->SetUserWallpaperInfo(user_id, info, is_persistent);
+
+ wallpaper_manager->SetDefaultWallpaperNow(user_id);
return true;
}
WallpaperPrivateSetCustomWallpaperFunction::
~WallpaperPrivateSetCustomWallpaperFunction() {}
-bool WallpaperPrivateSetCustomWallpaperFunction::RunImpl() {
+bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() {
params = set_custom_wallpaper::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
// Gets email address and username hash while at UI thread.
- email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+ user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email();
user_id_hash_ =
- chromeos::UserManager::Get()->GetLoggedInUser()->username_hash();
+ chromeos::UserManager::Get()->GetActiveUser()->username_hash();
StartDecode(params->wallpaper);
}
void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
- const gfx::ImageSkia& wallpaper) {
+ const gfx::ImageSkia& image) {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
- chromeos::UserImage::RawImage raw_image(params->wallpaper.begin(),
- params->wallpaper.end());
- chromeos::UserImage image(wallpaper, raw_image);
base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
chromeos::kThumbnailWallpaperSubDir, user_id_hash_, params->file_name);
ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
wallpaper_private::ToString(params->layout));
- wallpaper_manager->SetCustomWallpaper(email_,
+ bool update_wallpaper =
+ user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
+ wallpaper_manager->SetCustomWallpaper(user_id_,
user_id_hash_,
params->file_name,
layout,
chromeos::User::CUSTOMIZED,
- image);
+ image,
+ update_wallpaper);
unsafe_wallpaper_decoder_ = NULL;
if (params->generate_thumbnail) {
- wallpaper.EnsureRepsForSupportedScales();
- scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
+ image.EnsureRepsForSupportedScales();
+ scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
task_runner->PostTask(FROM_HERE,
const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) {
DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
sequence_token_));
- chromeos::UserImage wallpaper(*image.get());
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());
scoped_refptr<base::RefCountedBytes> data;
- chromeos::WallpaperManager::Get()->ResizeWallpaper(
- wallpaper,
+ chromeos::WallpaperManager::Get()->ResizeImage(
+ *image,
ash::WALLPAPER_LAYOUT_STRETCH,
- ash::kWallpaperThumbnailWidth,
- ash::kWallpaperThumbnailHeight,
- &data);
+ chromeos::kWallpaperThumbnailWidth,
+ chromeos::kWallpaperThumbnailHeight,
+ &data,
+ NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
WallpaperPrivateSetCustomWallpaperLayoutFunction::
~WallpaperPrivateSetCustomWallpaperLayoutFunction() {}
-bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunImpl() {
+bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() {
scoped_ptr<set_custom_wallpaper_layout::Params> params(
set_custom_wallpaper_layout::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
info.layout = wallpaper_api_util::GetLayoutEnum(
wallpaper_private::ToString(params->layout));
- std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+ std::string email = chromeos::UserManager::Get()->GetActiveUser()->email();
bool is_persistent =
!chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral();
wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent);
- wallpaper_manager->UpdateWallpaper();
+ wallpaper_manager->UpdateWallpaper(false /* clear_cache */);
SendResponse(true);
// Gets email address while at UI thread.
~WallpaperPrivateMinimizeInactiveWindowsFunction() {
}
-bool WallpaperPrivateMinimizeInactiveWindowsFunction::RunImpl() {
+bool WallpaperPrivateMinimizeInactiveWindowsFunction::RunAsync() {
WindowStateManager::MinimizeInactiveWindows(
chromeos::UserManager::Get()->GetActiveUser()->username_hash());
return true;
~WallpaperPrivateRestoreMinimizedWindowsFunction() {
}
-bool WallpaperPrivateRestoreMinimizedWindowsFunction::RunImpl() {
+bool WallpaperPrivateRestoreMinimizedWindowsFunction::RunAsync() {
WindowStateManager::RestoreWindows(
chromeos::UserManager::Get()->GetActiveUser()->username_hash());
return true;
WallpaperPrivateGetThumbnailFunction::~WallpaperPrivateGetThumbnailFunction() {
}
-bool WallpaperPrivateGetThumbnailFunction::RunImpl() {
+bool WallpaperPrivateGetThumbnailFunction::RunAsync() {
scoped_ptr<get_thumbnail::Params> params(
get_thumbnail::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
base::FilePath thumbnail_path;
- std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+ std::string email = chromeos::UserManager::Get()->GetActiveUser()->email();
if (params->source == get_thumbnail::Params::SOURCE_ONLINE) {
std::string file_name = GURL(params->url_or_file).ExtractFileName();
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
WallpaperPrivateSaveThumbnailFunction::
~WallpaperPrivateSaveThumbnailFunction() {}
-bool WallpaperPrivateSaveThumbnailFunction::RunImpl() {
+bool WallpaperPrivateSaveThumbnailFunction::RunAsync() {
scoped_ptr<save_thumbnail::Params> params(
save_thumbnail::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
~WallpaperPrivateGetOfflineWallpaperListFunction() {
}
-bool WallpaperPrivateGetOfflineWallpaperListFunction::RunImpl() {
+bool WallpaperPrivateGetOfflineWallpaperListFunction::RunAsync() {
sequence_token_ = BrowserThread::GetBlockingPool()->
GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
scoped_refptr<base::SequencedTaskRunner> task_runner =