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

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

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

Powered by Google App Engine
This is Rietveld 408576698