Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 2627083005: Use TaskScheduler instead of blocking pool in wallpaper_manager.cc. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/login/users/wallpaper/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/ash_constants.h" 9 #include "ash/common/ash_constants.h"
10 #include "ash/common/wallpaper/wallpaper_controller.h" 10 #include "ash/common/wallpaper/wallpaper_controller.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/sha1.h" 19 #include "base/sha1.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "base/task_scheduler/post_task.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/threading/worker_pool.h" 24 #include "base/threading/worker_pool.h"
24 #include "base/time/time.h" 25 #include "base/time/time.h"
25 #include "base/trace_event/trace_event.h" 26 #include "base/trace_event/trace_event.h"
26 #include "base/values.h" 27 #include "base/values.h"
27 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/chromeos/customization/customization_document.h" 30 #include "chrome/browser/chromeos/customization/customization_document.h"
30 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" 31 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
31 #include "chrome/browser/chromeos/login/startup_utils.h" 32 #include "chrome/browser/chromeos/login/startup_utils.h"
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 user_manager::UserManager::Get()->IsUserLoggedIn() 954 user_manager::UserManager::Get()->IsUserLoggedIn()
954 ? user_manager::UserManager::Get()->GetActiveUser()->GetAccountId() 955 ? user_manager::UserManager::Get()->GetActiveUser()->GetAccountId()
955 : user_manager::SignInAccountId()); 956 : user_manager::SignInAccountId());
956 } 957 }
957 958
958 void WallpaperManager::OnDeviceWallpaperExists(const AccountId& account_id, 959 void WallpaperManager::OnDeviceWallpaperExists(const AccountId& account_id,
959 const std::string& url, 960 const std::string& url,
960 const std::string& hash, 961 const std::string& hash,
961 bool exist) { 962 bool exist) {
962 if (exist) { 963 if (exist) {
963 base::PostTaskAndReplyWithResult( 964 base::PostTaskWithTraitsAndReplyWithResult(
964 BrowserThread::GetBlockingPool(), FROM_HERE, 965 FROM_HERE, base::TaskTraits().MayBlock(),
965 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(), 966 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(),
966 hash), 967 hash),
967 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash, 968 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash,
968 weak_factory_.GetWeakPtr(), account_id, url, hash)); 969 weak_factory_.GetWeakPtr(), account_id, url, hash));
969 } else { 970 } else {
970 GURL device_wallpaper_url(url); 971 GURL device_wallpaper_url(url);
971 device_wallpaper_downloader_.reset(new CustomizationWallpaperDownloader( 972 device_wallpaper_downloader_.reset(new CustomizationWallpaperDownloader(
972 g_browser_process->system_request_context(), device_wallpaper_url, 973 g_browser_process->system_request_context(), device_wallpaper_url,
973 GetDeviceWallpaperDir(), GetDeviceWallpaperFilePath(), 974 GetDeviceWallpaperDir(), GetDeviceWallpaperFilePath(),
974 base::Bind(&WallpaperManager::OnDeviceWallpaperDownloaded, 975 base::Bind(&WallpaperManager::OnDeviceWallpaperDownloaded,
975 weak_factory_.GetWeakPtr(), account_id, hash))); 976 weak_factory_.GetWeakPtr(), account_id, hash)));
976 device_wallpaper_downloader_->Start(); 977 device_wallpaper_downloader_->Start();
977 } 978 }
978 } 979 }
979 980
980 void WallpaperManager::OnDeviceWallpaperDownloaded(const AccountId& account_id, 981 void WallpaperManager::OnDeviceWallpaperDownloaded(const AccountId& account_id,
981 const std::string& hash, 982 const std::string& hash,
982 bool success, 983 bool success,
983 const GURL& url) { 984 const GURL& url) {
984 if (!success) { 985 if (!success) {
985 LOG(ERROR) << "Failed to download the device wallpaper. Fallback to " 986 LOG(ERROR) << "Failed to download the device wallpaper. Fallback to "
986 "default wallpaper."; 987 "default wallpaper.";
987 SetDefaultWallpaperDelayed(account_id); 988 SetDefaultWallpaperDelayed(account_id);
988 return; 989 return;
989 } 990 }
990 991
991 base::PostTaskAndReplyWithResult( 992 base::PostTaskWithTraitsAndReplyWithResult(
992 BrowserThread::GetBlockingPool(), FROM_HERE, 993 FROM_HERE, base::TaskTraits().MayBlock(),
993 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(), 994 base::Bind(&CheckDeviceWallpaperMatchHash, GetDeviceWallpaperFilePath(),
994 hash), 995 hash),
995 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash, 996 base::Bind(&WallpaperManager::OnCheckDeviceWallpaperMatchHash,
996 weak_factory_.GetWeakPtr(), account_id, url.spec(), hash)); 997 weak_factory_.GetWeakPtr(), account_id, url.spec(), hash));
997 } 998 }
998 999
999 void WallpaperManager::OnCheckDeviceWallpaperMatchHash( 1000 void WallpaperManager::OnCheckDeviceWallpaperMatchHash(
1000 const AccountId& account_id, 1001 const AccountId& account_id,
1001 const std::string& url, 1002 const std::string& url,
1002 const std::string& hash, 1003 const std::string& hash,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 return files_id; 1298 return files_id;
1298 } 1299 }
1299 1300
1300 bool WallpaperManager::SetDeviceWallpaperIfApplicable( 1301 bool WallpaperManager::SetDeviceWallpaperIfApplicable(
1301 const AccountId& account_id) { 1302 const AccountId& account_id) {
1302 std::string url; 1303 std::string url;
1303 std::string hash; 1304 std::string hash;
1304 if (ShouldSetDeviceWallpaper(account_id, &url, &hash)) { 1305 if (ShouldSetDeviceWallpaper(account_id, &url, &hash)) {
1305 // Check if the device wallpaper exists and matches the hash. If so, use it 1306 // Check if the device wallpaper exists and matches the hash. If so, use it
1306 // directly. Otherwise download it first. 1307 // directly. Otherwise download it first.
1307 base::PostTaskAndReplyWithResult( 1308 base::PostTaskWithTraitsAndReplyWithResult(
1308 BrowserThread::GetBlockingPool(), FROM_HERE, 1309 FROM_HERE, base::TaskTraits().MayBlock(),
1309 base::Bind(&base::PathExists, GetDeviceWallpaperFilePath()), 1310 base::Bind(&base::PathExists, GetDeviceWallpaperFilePath()),
1310 base::Bind(&WallpaperManager::OnDeviceWallpaperExists, 1311 base::Bind(&WallpaperManager::OnDeviceWallpaperExists,
1311 weak_factory_.GetWeakPtr(), account_id, url, hash)); 1312 weak_factory_.GetWeakPtr(), account_id, url, hash));
1312 return true; 1313 return true;
1313 } 1314 }
1314 return false; 1315 return false;
1315 } 1316 }
1316 1317
1317 void WallpaperManager::UserChangedChildStatus(user_manager::User* user) { 1318 void WallpaperManager::UserChangedChildStatus(user_manager::User* user) {
1318 SetUserWallpaperNow(user->GetAccountId()); 1319 SetUserWallpaperNow(user->GetAccountId());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 1407
1407 UMA_HISTOGRAM_ENUMERATION( 1408 UMA_HISTOGRAM_ENUMERATION(
1408 "Ash.Wallpaper.Apps", 1409 "Ash.Wallpaper.Apps",
1409 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile) 1410 wallpaper_manager_util::ShouldUseAndroidWallpapersApp(profile)
1410 ? WALLPAPERS_APP_ANDROID 1411 ? WALLPAPERS_APP_ANDROID
1411 : WALLPAPERS_PICKER_APP_CHROMEOS, 1412 : WALLPAPERS_PICKER_APP_CHROMEOS,
1412 WALLPAPERS_APPS_NUM); 1413 WALLPAPERS_APPS_NUM);
1413 } 1414 }
1414 1415
1415 } // namespace chromeos 1416 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698