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

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 2315303002: Remove calls to IsRunningSequenceOnCurrentThread() in wallpaper API. (Closed)
Patch Set: Leaky LazyInstance Created 4 years, 3 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
OLDNEW
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>
(...skipping 10 matching lines...) Expand all
21 #include "base/command_line.h" 21 #include "base/command_line.h"
22 #include "base/files/file_enumerator.h" 22 #include "base/files/file_enumerator.h"
23 #include "base/files/file_util.h" 23 #include "base/files/file_util.h"
24 #include "base/macros.h" 24 #include "base/macros.h"
25 #include "base/memory/ptr_util.h" 25 #include "base/memory/ptr_util.h"
26 #include "base/memory/ref_counted_memory.h" 26 #include "base/memory/ref_counted_memory.h"
27 #include "base/metrics/histogram_macros.h" 27 #include "base/metrics/histogram_macros.h"
28 #include "base/path_service.h" 28 #include "base/path_service.h"
29 #include "base/strings/string_number_conversions.h" 29 #include "base/strings/string_number_conversions.h"
30 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
31 #include "base/threading/sequenced_worker_pool.h"
31 #include "base/threading/worker_pool.h" 32 #include "base/threading/worker_pool.h"
32 #include "chrome/browser/browser_process.h" 33 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 34 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
34 #include "chrome/browser/chromeos/profiles/profile_helper.h" 35 #include "chrome/browser/chromeos/profiles/profile_helper.h"
35 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/sync/profile_sync_service_factory.h" 37 #include "chrome/browser/sync/profile_sync_service_factory.h"
37 #include "chrome/browser/ui/ash/ash_util.h" 38 #include "chrome/browser/ui/ash/ash_util.h"
38 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
39 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "chrome/grit/generated_resources.h" 41 #include "chrome/grit/generated_resources.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 &wallpaper_path)); 400 &wallpaper_path));
400 fallback_path = wallpaper_path.Append(file_name); 401 fallback_path = wallpaper_path.Append(file_name);
401 if (params->layout != wallpaper_base::WALLPAPER_LAYOUT_STRETCH && 402 if (params->layout != wallpaper_base::WALLPAPER_LAYOUT_STRETCH &&
402 resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) { 403 resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) {
403 file_name = base::FilePath(file_name) 404 file_name = base::FilePath(file_name)
404 .InsertBeforeExtension(wallpaper::kSmallWallpaperSuffix) 405 .InsertBeforeExtension(wallpaper::kSmallWallpaperSuffix)
405 .value(); 406 .value();
406 } 407 }
407 wallpaper_path = wallpaper_path.Append(file_name); 408 wallpaper_path = wallpaper_path.Append(file_name);
408 409
409 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
410 wallpaper::kWallpaperSequenceTokenName);
411 scoped_refptr<base::SequencedTaskRunner> task_runner = 410 scoped_refptr<base::SequencedTaskRunner> task_runner =
412 BrowserThread::GetBlockingPool()-> 411 BrowserThread::GetBlockingPool()
413 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 412 ->GetSequencedTaskRunnerWithShutdownBehavior(
413 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
414 wallpaper::kWallpaperSequenceTokenName),
414 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 415 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
415 416
416 task_runner->PostTask(FROM_HERE, 417 task_runner->PostTask(FROM_HERE,
417 base::Bind( 418 base::Bind(
418 &WallpaperPrivateSetWallpaperIfExistsFunction:: 419 &WallpaperPrivateSetWallpaperIfExistsFunction::
419 ReadFileAndInitiateStartDecode, 420 ReadFileAndInitiateStartDecode,
420 this, wallpaper_path, fallback_path)); 421 this, wallpaper_path, fallback_path));
421 return true; 422 return true;
422 } 423 }
423 424
424 void WallpaperPrivateSetWallpaperIfExistsFunction:: 425 void WallpaperPrivateSetWallpaperIfExistsFunction::
425 ReadFileAndInitiateStartDecode(const base::FilePath& file_path, 426 ReadFileAndInitiateStartDecode(const base::FilePath& file_path,
426 const base::FilePath& fallback_path) { 427 const base::FilePath& fallback_path) {
427 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 428 wallpaper::AssertCalledOnWallpaperSequence();
428 sequence_token_));
429 base::FilePath path = file_path; 429 base::FilePath path = file_path;
430 430
431 if (!base::PathExists(file_path)) 431 if (!base::PathExists(file_path))
432 path = fallback_path; 432 path = fallback_path;
433 433
434 std::string data; 434 std::string data;
435 if (base::PathExists(path) && 435 if (base::PathExists(path) &&
436 base::ReadFileToString(path, &data)) { 436 base::ReadFileToString(path, &data)) {
437 BrowserThread::PostTask( 437 BrowserThread::PostTask(
438 BrowserThread::UI, FROM_HERE, 438 BrowserThread::UI, FROM_HERE,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 505
506 return true; 506 return true;
507 } 507 }
508 508
509 void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded( 509 void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded(
510 const gfx::ImageSkia& image) { 510 const gfx::ImageSkia& image) {
511 wallpaper_ = image; 511 wallpaper_ = image;
512 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished. 512 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
513 unsafe_wallpaper_decoder_ = NULL; 513 unsafe_wallpaper_decoder_ = NULL;
514 514
515 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
516 wallpaper::kWallpaperSequenceTokenName);
517 scoped_refptr<base::SequencedTaskRunner> task_runner = 515 scoped_refptr<base::SequencedTaskRunner> task_runner =
518 BrowserThread::GetBlockingPool()-> 516 BrowserThread::GetBlockingPool()
519 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 517 ->GetSequencedTaskRunnerWithShutdownBehavior(
518 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
519 wallpaper::kWallpaperSequenceTokenName),
520 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 520 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
521 521
522 task_runner->PostTask(FROM_HERE, 522 task_runner->PostTask(FROM_HERE,
523 base::Bind(&WallpaperPrivateSetWallpaperFunction::SaveToFile, this)); 523 base::Bind(&WallpaperPrivateSetWallpaperFunction::SaveToFile, this));
524 } 524 }
525 525
526 void WallpaperPrivateSetWallpaperFunction::SaveToFile() { 526 void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
527 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 527 wallpaper::AssertCalledOnWallpaperSequence();
528 sequence_token_));
529 std::string file_name = GURL(params->url).ExtractFileName(); 528 std::string file_name = GURL(params->url).ExtractFileName();
530 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPERS, file_name, params->wallpaper)) { 529 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPERS, file_name, params->wallpaper)) {
531 wallpaper_.EnsureRepsForSupportedScales(); 530 wallpaper_.EnsureRepsForSupportedScales();
532 std::unique_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy()); 531 std::unique_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy());
533 // ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if 532 // ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if
534 // post to another thread. 533 // post to another thread.
535 BrowserThread::PostTask( 534 BrowserThread::PostTask(
536 BrowserThread::UI, FROM_HERE, 535 BrowserThread::UI, FROM_HERE,
537 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper, 536 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper,
538 this, base::Passed(std::move(deep_copy)))); 537 this, base::Passed(std::move(deep_copy))));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 644 }
646 645
647 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( 646 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
648 const gfx::ImageSkia& image) { 647 const gfx::ImageSkia& image) {
649 chromeos::WallpaperManager* wallpaper_manager = 648 chromeos::WallpaperManager* wallpaper_manager =
650 chromeos::WallpaperManager::Get(); 649 chromeos::WallpaperManager::Get();
651 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( 650 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
652 wallpaper::kThumbnailWallpaperSubDir, wallpaper_files_id_, 651 wallpaper::kThumbnailWallpaperSubDir, wallpaper_files_id_,
653 params->file_name); 652 params->file_name);
654 653
655 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
656 wallpaper::kWallpaperSequenceTokenName);
657 scoped_refptr<base::SequencedTaskRunner> task_runner = 654 scoped_refptr<base::SequencedTaskRunner> task_runner =
658 BrowserThread::GetBlockingPool()-> 655 BrowserThread::GetBlockingPool()
659 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 656 ->GetSequencedTaskRunnerWithShutdownBehavior(
657 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
658 wallpaper::kWallpaperSequenceTokenName),
660 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 659 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
661 660
662 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( 661 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
663 wallpaper_base::ToString(params->layout)); 662 wallpaper_base::ToString(params->layout));
664 wallpaper_api_util::RecordCustomWallpaperLayout(layout); 663 wallpaper_api_util::RecordCustomWallpaperLayout(layout);
665 664
666 bool update_wallpaper = 665 bool update_wallpaper =
667 account_id_ == 666 account_id_ ==
668 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); 667 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
669 wallpaper_manager->SetCustomWallpaper( 668 wallpaper_manager->SetCustomWallpaper(
(...skipping 17 matching lines...) Expand all
687 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, 686 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail,
688 this, thumbnail_path, base::Passed(&deep_copy))); 687 this, thumbnail_path, base::Passed(&deep_copy)));
689 } else { 688 } else {
690 SendResponse(true); 689 SendResponse(true);
691 } 690 }
692 } 691 }
693 692
694 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( 693 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
695 const base::FilePath& thumbnail_path, 694 const base::FilePath& thumbnail_path,
696 std::unique_ptr<gfx::ImageSkia> image) { 695 std::unique_ptr<gfx::ImageSkia> image) {
697 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 696 wallpaper::AssertCalledOnWallpaperSequence();
698 sequence_token_));
699 if (!base::PathExists(thumbnail_path.DirName())) 697 if (!base::PathExists(thumbnail_path.DirName()))
700 base::CreateDirectory(thumbnail_path.DirName()); 698 base::CreateDirectory(thumbnail_path.DirName());
701 699
702 scoped_refptr<base::RefCountedBytes> data; 700 scoped_refptr<base::RefCountedBytes> data;
703 chromeos::WallpaperManager::Get()->ResizeImage( 701 chromeos::WallpaperManager::Get()->ResizeImage(
704 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, 702 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH,
705 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight, 703 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight,
706 &data, NULL); 704 &data, NULL);
707 BrowserThread::PostTask( 705 BrowserThread::PostTask(
708 BrowserThread::UI, FROM_HERE, 706 BrowserThread::UI, FROM_HERE,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 return false; 803 return false;
806 } 804 }
807 805
808 // TODO(bshe): Small resolution wallpaper is used here as wallpaper 806 // TODO(bshe): Small resolution wallpaper is used here as wallpaper
809 // thumbnail. We should either resize it or include a wallpaper thumbnail in 807 // thumbnail. We should either resize it or include a wallpaper thumbnail in
810 // addition to large and small wallpaper resolutions. 808 // addition to large and small wallpaper resolutions.
811 thumbnail_path = base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( 809 thumbnail_path = base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
812 chromeos::switches::kDefaultWallpaperSmall); 810 chromeos::switches::kDefaultWallpaperSmall);
813 } 811 }
814 812
815 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
816 wallpaper::kWallpaperSequenceTokenName);
817 scoped_refptr<base::SequencedTaskRunner> task_runner = 813 scoped_refptr<base::SequencedTaskRunner> task_runner =
818 BrowserThread::GetBlockingPool()-> 814 BrowserThread::GetBlockingPool()
819 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 815 ->GetSequencedTaskRunnerWithShutdownBehavior(
816 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
817 wallpaper::kWallpaperSequenceTokenName),
820 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 818 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
821 819
822 task_runner->PostTask(FROM_HERE, 820 task_runner->PostTask(FROM_HERE,
823 base::Bind(&WallpaperPrivateGetThumbnailFunction::Get, this, 821 base::Bind(&WallpaperPrivateGetThumbnailFunction::Get, this,
824 thumbnail_path)); 822 thumbnail_path));
825 return true; 823 return true;
826 } 824 }
827 825
828 void WallpaperPrivateGetThumbnailFunction::Failure( 826 void WallpaperPrivateGetThumbnailFunction::Failure(
829 const std::string& file_name) { 827 const std::string& file_name) {
830 SetError(base::StringPrintf("Failed to access wallpaper thumbnails for %s.", 828 SetError(base::StringPrintf("Failed to access wallpaper thumbnails for %s.",
831 file_name.c_str())); 829 file_name.c_str()));
832 SendResponse(false); 830 SendResponse(false);
833 } 831 }
834 832
835 void WallpaperPrivateGetThumbnailFunction::FileNotLoaded() { 833 void WallpaperPrivateGetThumbnailFunction::FileNotLoaded() {
836 SendResponse(true); 834 SendResponse(true);
837 } 835 }
838 836
839 void WallpaperPrivateGetThumbnailFunction::FileLoaded( 837 void WallpaperPrivateGetThumbnailFunction::FileLoaded(
840 const std::string& data) { 838 const std::string& data) {
841 SetResult(BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size())); 839 SetResult(BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size()));
842 SendResponse(true); 840 SendResponse(true);
843 } 841 }
844 842
845 void WallpaperPrivateGetThumbnailFunction::Get(const base::FilePath& path) { 843 void WallpaperPrivateGetThumbnailFunction::Get(const base::FilePath& path) {
846 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 844 wallpaper::AssertCalledOnWallpaperSequence();
847 sequence_token_));
848 std::string data; 845 std::string data;
849 if (GetData(path, &data)) { 846 if (GetData(path, &data)) {
850 if (data.empty()) { 847 if (data.empty()) {
851 BrowserThread::PostTask( 848 BrowserThread::PostTask(
852 BrowserThread::UI, FROM_HERE, 849 BrowserThread::UI, FROM_HERE,
853 base::Bind(&WallpaperPrivateGetThumbnailFunction::FileNotLoaded, this)); 850 base::Bind(&WallpaperPrivateGetThumbnailFunction::FileNotLoaded, this));
854 } else { 851 } else {
855 BrowserThread::PostTask( 852 BrowserThread::PostTask(
856 BrowserThread::UI, FROM_HERE, 853 BrowserThread::UI, FROM_HERE,
857 base::Bind(&WallpaperPrivateGetThumbnailFunction::FileLoaded, this, 854 base::Bind(&WallpaperPrivateGetThumbnailFunction::FileLoaded, this,
(...skipping 11 matching lines...) Expand all
869 } 866 }
870 867
871 WallpaperPrivateSaveThumbnailFunction:: 868 WallpaperPrivateSaveThumbnailFunction::
872 ~WallpaperPrivateSaveThumbnailFunction() {} 869 ~WallpaperPrivateSaveThumbnailFunction() {}
873 870
874 bool WallpaperPrivateSaveThumbnailFunction::RunAsync() { 871 bool WallpaperPrivateSaveThumbnailFunction::RunAsync() {
875 std::unique_ptr<save_thumbnail::Params> params( 872 std::unique_ptr<save_thumbnail::Params> params(
876 save_thumbnail::Params::Create(*args_)); 873 save_thumbnail::Params::Create(*args_));
877 EXTENSION_FUNCTION_VALIDATE(params); 874 EXTENSION_FUNCTION_VALIDATE(params);
878 875
879 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
880 wallpaper::kWallpaperSequenceTokenName);
881 scoped_refptr<base::SequencedTaskRunner> task_runner = 876 scoped_refptr<base::SequencedTaskRunner> task_runner =
882 BrowserThread::GetBlockingPool()-> 877 BrowserThread::GetBlockingPool()
883 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 878 ->GetSequencedTaskRunnerWithShutdownBehavior(
879 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
880 wallpaper::kWallpaperSequenceTokenName),
884 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 881 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
885 882
886 task_runner->PostTask(FROM_HERE, 883 task_runner->PostTask(FROM_HERE,
887 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Save, 884 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Save,
888 this, params->data, GURL(params->url).ExtractFileName())); 885 this, params->data, GURL(params->url).ExtractFileName()));
889 return true; 886 return true;
890 } 887 }
891 888
892 void WallpaperPrivateSaveThumbnailFunction::Failure( 889 void WallpaperPrivateSaveThumbnailFunction::Failure(
893 const std::string& file_name) { 890 const std::string& file_name) {
894 SetError(base::StringPrintf("Failed to create/write thumbnail of %s.", 891 SetError(base::StringPrintf("Failed to create/write thumbnail of %s.",
895 file_name.c_str())); 892 file_name.c_str()));
896 SendResponse(false); 893 SendResponse(false);
897 } 894 }
898 895
899 void WallpaperPrivateSaveThumbnailFunction::Success() { 896 void WallpaperPrivateSaveThumbnailFunction::Success() {
900 SendResponse(true); 897 SendResponse(true);
901 } 898 }
902 899
903 void WallpaperPrivateSaveThumbnailFunction::Save(const std::vector<char>& data, 900 void WallpaperPrivateSaveThumbnailFunction::Save(const std::vector<char>& data,
904 const std::string& file_name) { 901 const std::string& file_name) {
905 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 902 wallpaper::AssertCalledOnWallpaperSequence();
906 sequence_token_));
907 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS, file_name, data)) { 903 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS, file_name, data)) {
908 BrowserThread::PostTask( 904 BrowserThread::PostTask(
909 BrowserThread::UI, FROM_HERE, 905 BrowserThread::UI, FROM_HERE,
910 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Success, this)); 906 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Success, this));
911 } else { 907 } else {
912 BrowserThread::PostTask( 908 BrowserThread::PostTask(
913 BrowserThread::UI, FROM_HERE, 909 BrowserThread::UI, FROM_HERE,
914 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Failure, 910 base::Bind(&WallpaperPrivateSaveThumbnailFunction::Failure,
915 this, file_name)); 911 this, file_name));
916 } 912 }
917 } 913 }
918 914
919 WallpaperPrivateGetOfflineWallpaperListFunction:: 915 WallpaperPrivateGetOfflineWallpaperListFunction::
920 WallpaperPrivateGetOfflineWallpaperListFunction() { 916 WallpaperPrivateGetOfflineWallpaperListFunction() {
921 } 917 }
922 918
923 WallpaperPrivateGetOfflineWallpaperListFunction:: 919 WallpaperPrivateGetOfflineWallpaperListFunction::
924 ~WallpaperPrivateGetOfflineWallpaperListFunction() { 920 ~WallpaperPrivateGetOfflineWallpaperListFunction() {
925 } 921 }
926 922
927 bool WallpaperPrivateGetOfflineWallpaperListFunction::RunAsync() { 923 bool WallpaperPrivateGetOfflineWallpaperListFunction::RunAsync() {
928 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
929 wallpaper::kWallpaperSequenceTokenName);
930 scoped_refptr<base::SequencedTaskRunner> task_runner = 924 scoped_refptr<base::SequencedTaskRunner> task_runner =
931 BrowserThread::GetBlockingPool()-> 925 BrowserThread::GetBlockingPool()
932 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 926 ->GetSequencedTaskRunnerWithShutdownBehavior(
927 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
928 wallpaper::kWallpaperSequenceTokenName),
933 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 929 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
934 930
935 task_runner->PostTask(FROM_HERE, 931 task_runner->PostTask(FROM_HERE,
936 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::GetList, 932 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::GetList,
937 this)); 933 this));
938 return true; 934 return true;
939 } 935 }
940 936
941 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList() { 937 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList() {
942 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 938 wallpaper::AssertCalledOnWallpaperSequence();
943 sequence_token_));
944 std::vector<std::string> file_list; 939 std::vector<std::string> file_list;
945 base::FilePath wallpaper_dir; 940 base::FilePath wallpaper_dir;
946 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 941 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
947 if (base::DirectoryExists(wallpaper_dir)) { 942 if (base::DirectoryExists(wallpaper_dir)) {
948 base::FileEnumerator files(wallpaper_dir, false, 943 base::FileEnumerator files(wallpaper_dir, false,
949 base::FileEnumerator::FILES); 944 base::FileEnumerator::FILES);
950 for (base::FilePath current = files.Next(); !current.empty(); 945 for (base::FilePath current = files.Next(); !current.empty();
951 current = files.Next()) { 946 current = files.Next()) {
952 std::string file_name = current.BaseName().RemoveExtension().value(); 947 std::string file_name = current.BaseName().RemoveExtension().value();
953 // Do not add file name of small resolution wallpaper to the list. 948 // Do not add file name of small resolution wallpaper to the list.
(...skipping 20 matching lines...) Expand all
974 WallpaperPrivateRecordWallpaperUMAFunction::Run() { 969 WallpaperPrivateRecordWallpaperUMAFunction::Run() {
975 std::unique_ptr<record_wallpaper_uma::Params> params( 970 std::unique_ptr<record_wallpaper_uma::Params> params(
976 record_wallpaper_uma::Params::Create(*args_)); 971 record_wallpaper_uma::Params::Create(*args_));
977 EXTENSION_FUNCTION_VALIDATE(params); 972 EXTENSION_FUNCTION_VALIDATE(params);
978 973
979 user_manager::User::WallpaperType source = getWallpaperType(params->source); 974 user_manager::User::WallpaperType source = getWallpaperType(params->source);
980 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, 975 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source,
981 user_manager::User::WALLPAPER_TYPE_COUNT); 976 user_manager::User::WALLPAPER_TYPE_COUNT);
982 return RespondNow(NoArguments()); 977 return RespondNow(NoArguments());
983 } 978 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698