| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/desktop_background/desktop_background_controller.h" | 11 #include "ash/desktop_background/desktop_background_controller.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 25 #include "components/user_manager/user.h" | 26 #include "components/user_manager/user.h" |
| 26 #include "components/user_manager/user_manager.h" | 27 #include "components/user_manager/user_manager.h" |
| 27 #include "components/wallpaper/wallpaper_layout.h" | 28 #include "components/wallpaper/wallpaper_layout.h" |
| 28 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| 29 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::unique_ptr<net::URLFetcher> url_fetcher_; | 90 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 90 FetchCallback callback_; | 91 FetchCallback callback_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 base::LazyInstance<WallpaperFetcher> g_wallpaper_fetcher = | 94 base::LazyInstance<WallpaperFetcher> g_wallpaper_fetcher = |
| 94 LAZY_INSTANCE_INITIALIZER; | 95 LAZY_INSTANCE_INITIALIZER; |
| 95 | 96 |
| 97 // Gets the |User| for a given |BrowserContext|. The function will only return |
| 98 // valid objects. |
| 99 const user_manager::User* GetUserFromBrowserContext( |
| 100 content::BrowserContext* context) { |
| 101 Profile* profile = Profile::FromBrowserContext(context); |
| 102 DCHECK(profile); |
| 103 const user_manager::User* user = |
| 104 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 105 DCHECK(user); |
| 106 return user; |
| 107 } |
| 108 |
| 96 } // namespace | 109 } // namespace |
| 97 | 110 |
| 98 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { | 111 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { |
| 99 } | 112 } |
| 100 | 113 |
| 101 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { | 114 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { |
| 102 } | 115 } |
| 103 | 116 |
| 104 bool WallpaperSetWallpaperFunction::RunAsync() { | 117 bool WallpaperSetWallpaperFunction::RunAsync() { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 106 params_ = set_wallpaper::Params::Create(*args_); | 119 params_ = set_wallpaper::Params::Create(*args_); |
| 107 EXTENSION_FUNCTION_VALIDATE(params_); | 120 EXTENSION_FUNCTION_VALIDATE(params_); |
| 108 | 121 |
| 109 // Gets account id and user wallpaper files id while at UI thread. | 122 // Gets account id from the caller, ensuring multiprofile compatibility. |
| 110 const user_manager::User* user = | 123 const user_manager::User* user = GetUserFromBrowserContext(browser_context()); |
| 111 user_manager::UserManager::Get()->GetLoggedInUser(); | |
| 112 account_id_ = user->GetAccountId(); | 124 account_id_ = user->GetAccountId(); |
| 113 chromeos::WallpaperManager* wallpaper_manager = | 125 chromeos::WallpaperManager* wallpaper_manager = |
| 114 chromeos::WallpaperManager::Get(); | 126 chromeos::WallpaperManager::Get(); |
| 115 wallpaper_files_id_ = wallpaper_manager->GetFilesId(*user); | 127 wallpaper_files_id_ = wallpaper_manager->GetFilesId(*user); |
| 116 | 128 |
| 117 if (params_->details.data) { | 129 if (params_->details.data) { |
| 118 StartDecode(*params_->details.data); | 130 StartDecode(*params_->details.data); |
| 119 } else if (params_->details.url) { | 131 } else if (params_->details.url) { |
| 120 GURL wallpaper_url(*params_->details.url); | 132 GURL wallpaper_url(*params_->details.url); |
| 121 if (wallpaper_url.is_valid()) { | 133 if (wallpaper_url.is_valid()) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 const std::string& response) { | 264 const std::string& response) { |
| 253 if (success) { | 265 if (success) { |
| 254 params_->details.data.reset( | 266 params_->details.data.reset( |
| 255 new std::vector<char>(response.begin(), response.end())); | 267 new std::vector<char>(response.begin(), response.end())); |
| 256 StartDecode(*params_->details.data); | 268 StartDecode(*params_->details.data); |
| 257 } else { | 269 } else { |
| 258 SetError(response); | 270 SetError(response); |
| 259 SendResponse(false); | 271 SendResponse(false); |
| 260 } | 272 } |
| 261 } | 273 } |
| OLD | NEW |