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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_cycle_controller.h" | 10 #include "ash/wm/window_cycle_controller.h" |
11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_enumerator.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/synchronization/cancellation_flag.h" | 19 #include "base/synchronization/cancellation_flag.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chromeos/login/user.h" | 23 #include "chrome/browser/chromeos/login/user.h" |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList( | 879 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList( |
879 const std::string& email, | 880 const std::string& email, |
880 const std::string& source) { | 881 const std::string& source) { |
881 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 882 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
882 sequence_token_)); | 883 sequence_token_)); |
883 std::vector<std::string> file_list; | 884 std::vector<std::string> file_list; |
884 if (source == kOnlineSource) { | 885 if (source == kOnlineSource) { |
885 base::FilePath wallpaper_dir; | 886 base::FilePath wallpaper_dir; |
886 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); | 887 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); |
887 if (file_util::DirectoryExists(wallpaper_dir)) { | 888 if (file_util::DirectoryExists(wallpaper_dir)) { |
888 file_util::FileEnumerator files(wallpaper_dir, false, | 889 base::FileEnumerator files(wallpaper_dir, false, |
889 file_util::FileEnumerator::FILES); | 890 base::FileEnumerator::FILES); |
890 for (base::FilePath current = files.Next(); !current.empty(); | 891 for (base::FilePath current = files.Next(); !current.empty(); |
891 current = files.Next()) { | 892 current = files.Next()) { |
892 std::string file_name = current.BaseName().RemoveExtension().value(); | 893 std::string file_name = current.BaseName().RemoveExtension().value(); |
893 // Do not add file name of small resolution wallpaper to the list. | 894 // Do not add file name of small resolution wallpaper to the list. |
894 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true)) | 895 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true)) |
895 file_list.push_back(current.BaseName().value()); | 896 file_list.push_back(current.BaseName().value()); |
896 } | 897 } |
897 } | 898 } |
898 } else { | 899 } else { |
899 base::FilePath custom_thumbnails_dir = chromeos::WallpaperManager::Get()-> | 900 base::FilePath custom_thumbnails_dir = chromeos::WallpaperManager::Get()-> |
900 GetCustomWallpaperPath(chromeos::kThumbnailWallpaperSubDir, email, ""); | 901 GetCustomWallpaperPath(chromeos::kThumbnailWallpaperSubDir, email, ""); |
901 if (file_util::DirectoryExists(custom_thumbnails_dir)) { | 902 if (file_util::DirectoryExists(custom_thumbnails_dir)) { |
902 file_util::FileEnumerator files(custom_thumbnails_dir, false, | 903 base::FileEnumerator files(custom_thumbnails_dir, false, |
903 file_util::FileEnumerator::FILES); | 904 base::FileEnumerator::FILES); |
904 std::set<std::string> file_name_set; | 905 std::set<std::string> file_name_set; |
905 for (base::FilePath current = files.Next(); !current.empty(); | 906 for (base::FilePath current = files.Next(); !current.empty(); |
906 current = files.Next()) { | 907 current = files.Next()) { |
907 file_name_set.insert(current.BaseName().value()); | 908 file_name_set.insert(current.BaseName().value()); |
908 } | 909 } |
909 for (std::set<std::string>::reverse_iterator rit = file_name_set.rbegin(); | 910 for (std::set<std::string>::reverse_iterator rit = file_name_set.rbegin(); |
910 rit != file_name_set.rend(); ++rit) { | 911 rit != file_name_set.rend(); ++rit) { |
911 file_list.push_back(*rit); | 912 file_list.push_back(*rit); |
912 } | 913 } |
913 } | 914 } |
914 } | 915 } |
915 BrowserThread::PostTask( | 916 BrowserThread::PostTask( |
916 BrowserThread::UI, FROM_HERE, | 917 BrowserThread::UI, FROM_HERE, |
917 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, | 918 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, |
918 this, file_list)); | 919 this, file_list)); |
919 } | 920 } |
920 | 921 |
921 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 922 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
922 const std::vector<std::string>& file_list) { | 923 const std::vector<std::string>& file_list) { |
923 ListValue* results = new ListValue(); | 924 ListValue* results = new ListValue(); |
924 results->AppendStrings(file_list); | 925 results->AppendStrings(file_list); |
925 SetResult(results); | 926 SetResult(results); |
926 SendResponse(true); | 927 SendResponse(true); |
927 } | 928 } |
OLD | NEW |