Commit cdc6fb42 authored by skuhne's avatar skuhne Committed by Commit bot

Fixing remote wallpaper change in multi profile cases

The problem was that if the wallpaper of the non active user got changed on a different system, the remote system would replace the wallpaper of the active desktop with the change, no matter which user currently was active.

JS is supplying the browser-context to the api call which can be used to get the applications owner - and that is used to identify the proper user.

Creating a test case for this scenario is a lot of work (setting up multi profile, running the wallpaper manager for both users, triggering a change in the app of one user to force a change, waiting until the change has trickled through the system, ..).
Since the work required for an automated test feels rather complex and time consuming for this setup and the change itself is fairly straight forward and simple, so I did not create a test.

BUG=459599
TEST=visual

Review URL: https://codereview.chromium.org/939233004

Cr-Commit-Position: refs/heads/master@{#317322}
parent 5db108fb
......@@ -26,6 +26,7 @@
#include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
......@@ -101,6 +102,18 @@ bool GetData(const base::FilePath& path, std::string* data) {
base::ReadFileToString(path, data);
}
// Gets the |User| for a given |BrowserContext|. The function will only return
// valid objects.
const user_manager::User* GetUserFromBrowserContext(
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
DCHECK(profile);
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
DCHECK(user);
return user;
}
// WindowStateManager remembers which windows have been minimized in order to
// restore them when the wallpaper viewer is hidden.
class WindowStateManager : public aura::WindowObserver {
......@@ -323,7 +336,9 @@ bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() {
params = set_wallpaper_if_exists::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
user_id_ = user_manager::UserManager::Get()->GetActiveUser()->email();
// Gets email address from caller, ensuring multiprofile compatibility.
const user_manager::User* user = GetUserFromBrowserContext(browser_context());
user_id_ = user->email();
base::FilePath wallpaper_path;
base::FilePath fallback_path;
......@@ -432,8 +447,9 @@ bool WallpaperPrivateSetWallpaperFunction::RunAsync() {
params = set_wallpaper::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
// Gets email address while at UI thread.
user_id_ = user_manager::UserManager::Get()->GetActiveUser()->email();
// Gets email address from caller, ensuring multiprofile compatibility.
const user_manager::User* user = GetUserFromBrowserContext(browser_context());
user_id_ = user->email();
StartDecode(params->wallpaper);
......@@ -567,10 +583,10 @@ bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() {
params = set_custom_wallpaper::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
// Gets email address and username hash while at UI thread.
user_id_ = user_manager::UserManager::Get()->GetActiveUser()->email();
user_id_hash_ =
user_manager::UserManager::Get()->GetActiveUser()->username_hash();
// Gets email address from caller, ensuring multiprofile compatibility.
const user_manager::User* user = GetUserFromBrowserContext(browser_context());
user_id_ = user->email();
user_id_hash_ = user->username_hash();
StartDecode(params->wallpaper);
......
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