OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "ash/desktop_background/desktop_background_controller.h" | 14 #include "ash/desktop_background/desktop_background_controller.h" |
15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
16 #include "ash/wm/common/window_state.h" | 16 #include "ash/wm/common/window_state.h" |
17 #include "ash/wm/mru_window_tracker.h" | 17 #include "ash/wm/mru_window_tracker.h" |
18 #include "ash/wm/window_state_aura.h" | 18 #include "ash/wm/window_state_aura.h" |
19 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
21 #include "base/files/file_enumerator.h" | 21 #include "base/files/file_enumerator.h" |
22 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 24 #include "base/memory/ptr_util.h" |
24 #include "base/memory/ref_counted_memory.h" | 25 #include "base/memory/ref_counted_memory.h" |
25 #include "base/metrics/histogram_macros.h" | 26 #include "base/metrics/histogram_macros.h" |
26 #include "base/path_service.h" | 27 #include "base/path_service.h" |
27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
29 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 32 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
32 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 33 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
33 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 case wallpaper_private::WALLPAPER_SOURCE_THIRDPARTY: | 287 case wallpaper_private::WALLPAPER_SOURCE_THIRDPARTY: |
287 return user_manager::User::THIRDPARTY; | 288 return user_manager::User::THIRDPARTY; |
288 default: | 289 default: |
289 return user_manager::User::ONLINE; | 290 return user_manager::User::ONLINE; |
290 } | 291 } |
291 } | 292 } |
292 | 293 |
293 } // namespace | 294 } // namespace |
294 | 295 |
295 bool WallpaperPrivateGetStringsFunction::RunSync() { | 296 bool WallpaperPrivateGetStringsFunction::RunSync() { |
296 base::DictionaryValue* dict = new base::DictionaryValue(); | 297 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
297 SetResult(dict); | |
298 | 298 |
299 #define SET_STRING(id, idr) \ | 299 #define SET_STRING(id, idr) \ |
300 dict->SetString(id, l10n_util::GetStringUTF16(idr)) | 300 dict->SetString(id, l10n_util::GetStringUTF16(idr)) |
301 SET_STRING("webFontFamily", IDS_WEB_FONT_FAMILY); | 301 SET_STRING("webFontFamily", IDS_WEB_FONT_FAMILY); |
302 SET_STRING("webFontSize", IDS_WEB_FONT_SIZE); | 302 SET_STRING("webFontSize", IDS_WEB_FONT_SIZE); |
303 SET_STRING("allCategoryLabel", IDS_WALLPAPER_MANAGER_ALL_CATEGORY_LABEL); | 303 SET_STRING("allCategoryLabel", IDS_WALLPAPER_MANAGER_ALL_CATEGORY_LABEL); |
304 SET_STRING("deleteCommandLabel", IDS_WALLPAPER_MANAGER_DELETE_COMMAND_LABEL); | 304 SET_STRING("deleteCommandLabel", IDS_WALLPAPER_MANAGER_DELETE_COMMAND_LABEL); |
305 SET_STRING("customCategoryLabel", | 305 SET_STRING("customCategoryLabel", |
306 IDS_WALLPAPER_MANAGER_CUSTOM_CATEGORY_LABEL); | 306 IDS_WALLPAPER_MANAGER_CUSTOM_CATEGORY_LABEL); |
307 SET_STRING("selectCustomLabel", | 307 SET_STRING("selectCustomLabel", |
(...skipping 11 matching lines...) Expand all Loading... |
319 IDS_WALLPAPER_MANAGER_SHOW_CUSTOM_WALLPAPER_ON_START_WARNING); | 319 IDS_WALLPAPER_MANAGER_SHOW_CUSTOM_WALLPAPER_ON_START_WARNING); |
320 SET_STRING("accessFileFailure", IDS_WALLPAPER_MANAGER_ACCESS_FILE_FAILURE); | 320 SET_STRING("accessFileFailure", IDS_WALLPAPER_MANAGER_ACCESS_FILE_FAILURE); |
321 SET_STRING("invalidWallpaper", IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER); | 321 SET_STRING("invalidWallpaper", IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER); |
322 SET_STRING("surpriseMeLabel", IDS_WALLPAPER_MANAGER_SURPRISE_ME_LABEL); | 322 SET_STRING("surpriseMeLabel", IDS_WALLPAPER_MANAGER_SURPRISE_ME_LABEL); |
323 SET_STRING("learnMore", IDS_LEARN_MORE); | 323 SET_STRING("learnMore", IDS_LEARN_MORE); |
324 SET_STRING("currentWallpaperSetByMessage", | 324 SET_STRING("currentWallpaperSetByMessage", |
325 IDS_CURRENT_WALLPAPER_SET_BY_MESSAGE); | 325 IDS_CURRENT_WALLPAPER_SET_BY_MESSAGE); |
326 #undef SET_STRING | 326 #undef SET_STRING |
327 | 327 |
328 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 328 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
329 webui::SetLoadTimeDataDefaults(app_locale, dict); | 329 webui::SetLoadTimeDataDefaults(app_locale, dict.get()); |
330 | 330 |
331 chromeos::WallpaperManager* wallpaper_manager = | 331 chromeos::WallpaperManager* wallpaper_manager = |
332 chromeos::WallpaperManager::Get(); | 332 chromeos::WallpaperManager::Get(); |
333 wallpaper::WallpaperInfo info; | 333 wallpaper::WallpaperInfo info; |
334 | 334 |
335 if (wallpaper_manager->GetLoggedInUserWallpaperInfo(&info)) | 335 if (wallpaper_manager->GetLoggedInUserWallpaperInfo(&info)) |
336 dict->SetString("currentWallpaper", info.location); | 336 dict->SetString("currentWallpaper", info.location); |
337 | 337 |
338 #if defined(GOOGLE_CHROME_BUILD) | 338 #if defined(GOOGLE_CHROME_BUILD) |
339 dict->SetString("manifestBaseURL", kWallpaperManifestBaseURL); | 339 dict->SetString("manifestBaseURL", kWallpaperManifestBaseURL); |
340 #endif | 340 #endif |
341 | 341 |
342 Profile* profile = Profile::FromBrowserContext(browser_context()); | 342 Profile* profile = Profile::FromBrowserContext(browser_context()); |
343 std::string app_name( | 343 std::string app_name( |
344 profile->GetPrefs()->GetString(prefs::kCurrentWallpaperAppName)); | 344 profile->GetPrefs()->GetString(prefs::kCurrentWallpaperAppName)); |
345 if (!app_name.empty()) | 345 if (!app_name.empty()) |
346 dict->SetString("wallpaperAppName", app_name); | 346 dict->SetString("wallpaperAppName", app_name); |
347 | 347 |
348 dict->SetBoolean("isOEMDefaultWallpaper", IsOEMDefaultWallpaper()); | 348 dict->SetBoolean("isOEMDefaultWallpaper", IsOEMDefaultWallpaper()); |
349 dict->SetString("canceledWallpaper", | 349 dict->SetString("canceledWallpaper", |
350 wallpaper_api_util::kCancelWallpaperMessage); | 350 wallpaper_api_util::kCancelWallpaperMessage); |
| 351 |
| 352 SetResult(std::move(dict)); |
351 return true; | 353 return true; |
352 } | 354 } |
353 | 355 |
354 bool WallpaperPrivateGetSyncSettingFunction::RunSync() { | 356 bool WallpaperPrivateGetSyncSettingFunction::RunSync() { |
355 Profile* profile = Profile::FromBrowserContext(browser_context()); | 357 Profile* profile = Profile::FromBrowserContext(browser_context()); |
356 ProfileSyncService* sync = | 358 ProfileSyncService* sync = |
357 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 359 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
358 base::DictionaryValue* dict = new base::DictionaryValue(); | 360 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
359 SetResult(dict); | |
360 dict->SetBoolean("syncThemes", | 361 dict->SetBoolean("syncThemes", |
361 sync->GetActiveDataTypes().Has(syncer::THEMES)); | 362 sync->GetActiveDataTypes().Has(syncer::THEMES)); |
| 363 SetResult(std::move(dict)); |
362 return true; | 364 return true; |
363 } | 365 } |
364 | 366 |
365 WallpaperPrivateSetWallpaperIfExistsFunction:: | 367 WallpaperPrivateSetWallpaperIfExistsFunction:: |
366 WallpaperPrivateSetWallpaperIfExistsFunction() {} | 368 WallpaperPrivateSetWallpaperIfExistsFunction() {} |
367 | 369 |
368 WallpaperPrivateSetWallpaperIfExistsFunction:: | 370 WallpaperPrivateSetWallpaperIfExistsFunction:: |
369 ~WallpaperPrivateSetWallpaperIfExistsFunction() {} | 371 ~WallpaperPrivateSetWallpaperIfExistsFunction() {} |
370 | 372 |
371 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() { | 373 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 453 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
452 wallpaper_manager->SetWallpaperFromImageSkia(account_id_, image, layout, | 454 wallpaper_manager->SetWallpaperFromImageSkia(account_id_, image, layout, |
453 update_wallpaper); | 455 update_wallpaper); |
454 bool is_persistent = !user_manager::UserManager::Get() | 456 bool is_persistent = !user_manager::UserManager::Get() |
455 ->IsCurrentUserNonCryptohomeDataEphemeral(); | 457 ->IsCurrentUserNonCryptohomeDataEphemeral(); |
456 wallpaper::WallpaperInfo info = {params->url, | 458 wallpaper::WallpaperInfo info = {params->url, |
457 layout, | 459 layout, |
458 user_manager::User::ONLINE, | 460 user_manager::User::ONLINE, |
459 base::Time::Now().LocalMidnight()}; | 461 base::Time::Now().LocalMidnight()}; |
460 wallpaper_manager->SetUserWallpaperInfo(account_id_, info, is_persistent); | 462 wallpaper_manager->SetUserWallpaperInfo(account_id_, info, is_persistent); |
461 SetResult(new base::FundamentalValue(true)); | 463 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
462 Profile* profile = Profile::FromBrowserContext(browser_context()); | 464 Profile* profile = Profile::FromBrowserContext(browser_context()); |
463 // This API is only available to the component wallpaper picker. We do not | 465 // This API is only available to the component wallpaper picker. We do not |
464 // need to show the app's name if it is the component wallpaper picker. So set | 466 // need to show the app's name if it is the component wallpaper picker. So set |
465 // the pref to empty string. | 467 // the pref to empty string. |
466 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 468 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
467 std::string()); | 469 std::string()); |
468 SendResponse(true); | 470 SendResponse(true); |
469 } | 471 } |
470 | 472 |
471 void WallpaperPrivateSetWallpaperIfExistsFunction::OnFileNotExists( | 473 void WallpaperPrivateSetWallpaperIfExistsFunction::OnFileNotExists( |
472 const std::string& error) { | 474 const std::string& error) { |
473 SetResult(new base::FundamentalValue(false)); | 475 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
474 OnFailure(error); | 476 OnFailure(error); |
475 } | 477 } |
476 | 478 |
477 WallpaperPrivateSetWallpaperFunction::WallpaperPrivateSetWallpaperFunction() { | 479 WallpaperPrivateSetWallpaperFunction::WallpaperPrivateSetWallpaperFunction() { |
478 } | 480 } |
479 | 481 |
480 WallpaperPrivateSetWallpaperFunction::~WallpaperPrivateSetWallpaperFunction() { | 482 WallpaperPrivateSetWallpaperFunction::~WallpaperPrivateSetWallpaperFunction() { |
481 } | 483 } |
482 | 484 |
483 bool WallpaperPrivateSetWallpaperFunction::RunAsync() { | 485 bool WallpaperPrivateSetWallpaperFunction::RunAsync() { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 BrowserThread::UI, FROM_HERE, | 697 BrowserThread::UI, FROM_HERE, |
696 base::Bind( | 698 base::Bind( |
697 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, this, | 699 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, this, |
698 base::RetainedRef(data))); | 700 base::RetainedRef(data))); |
699 } | 701 } |
700 | 702 |
701 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( | 703 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( |
702 base::RefCountedBytes* data) { | 704 base::RefCountedBytes* data) { |
703 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( | 705 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( |
704 reinterpret_cast<const char*>(data->front()), data->size()); | 706 reinterpret_cast<const char*>(data->front()), data->size()); |
705 SetResult(result); | 707 SetResult(base::WrapUnique(result)); |
706 SendResponse(true); | 708 SendResponse(true); |
707 } | 709 } |
708 | 710 |
709 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 711 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
710 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 712 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
711 | 713 |
712 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 714 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
713 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 715 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
714 | 716 |
715 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { | 717 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 823 } |
822 | 824 |
823 void WallpaperPrivateGetThumbnailFunction::FileNotLoaded() { | 825 void WallpaperPrivateGetThumbnailFunction::FileNotLoaded() { |
824 SendResponse(true); | 826 SendResponse(true); |
825 } | 827 } |
826 | 828 |
827 void WallpaperPrivateGetThumbnailFunction::FileLoaded( | 829 void WallpaperPrivateGetThumbnailFunction::FileLoaded( |
828 const std::string& data) { | 830 const std::string& data) { |
829 BinaryValue* thumbnail = BinaryValue::CreateWithCopiedBuffer(data.c_str(), | 831 BinaryValue* thumbnail = BinaryValue::CreateWithCopiedBuffer(data.c_str(), |
830 data.size()); | 832 data.size()); |
831 SetResult(thumbnail); | 833 SetResult(base::WrapUnique(thumbnail)); |
832 SendResponse(true); | 834 SendResponse(true); |
833 } | 835 } |
834 | 836 |
835 void WallpaperPrivateGetThumbnailFunction::Get(const base::FilePath& path) { | 837 void WallpaperPrivateGetThumbnailFunction::Get(const base::FilePath& path) { |
836 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 838 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
837 sequence_token_)); | 839 sequence_token_)); |
838 std::string data; | 840 std::string data; |
839 if (GetData(path, &data)) { | 841 if (GetData(path, &data)) { |
840 if (data.empty()) { | 842 if (data.empty()) { |
841 BrowserThread::PostTask( | 843 BrowserThread::PostTask( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 949 } |
948 } | 950 } |
949 BrowserThread::PostTask( | 951 BrowserThread::PostTask( |
950 BrowserThread::UI, FROM_HERE, | 952 BrowserThread::UI, FROM_HERE, |
951 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, | 953 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, |
952 this, file_list)); | 954 this, file_list)); |
953 } | 955 } |
954 | 956 |
955 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 957 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
956 const std::vector<std::string>& file_list) { | 958 const std::vector<std::string>& file_list) { |
957 base::ListValue* results = new base::ListValue(); | 959 std::unique_ptr<base::ListValue> results(new base::ListValue()); |
958 results->AppendStrings(file_list); | 960 results->AppendStrings(file_list); |
959 SetResult(results); | 961 SetResult(std::move(results)); |
960 SendResponse(true); | 962 SendResponse(true); |
961 } | 963 } |
962 | 964 |
963 bool WallpaperPrivateRecordWallpaperUMAFunction::RunSync() { | 965 bool WallpaperPrivateRecordWallpaperUMAFunction::RunSync() { |
964 std::unique_ptr<record_wallpaper_uma::Params> params( | 966 std::unique_ptr<record_wallpaper_uma::Params> params( |
965 record_wallpaper_uma::Params::Create(*args_)); | 967 record_wallpaper_uma::Params::Create(*args_)); |
966 EXTENSION_FUNCTION_VALIDATE(params); | 968 EXTENSION_FUNCTION_VALIDATE(params); |
967 | 969 |
968 user_manager::User::WallpaperType source = getWallpaperType(params->source); | 970 user_manager::User::WallpaperType source = getWallpaperType(params->source); |
969 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, | 971 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, |
970 user_manager::User::WALLPAPER_TYPE_COUNT); | 972 user_manager::User::WALLPAPER_TYPE_COUNT); |
971 return true; | 973 return true; |
972 } | 974 } |
OLD | NEW |