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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // directory can not be found/created or failed to write file. 76 // directory can not be found/created or failed to write file.
77 bool SaveData(int key, const std::string& file_name, const std::string& data) { 77 bool SaveData(int key, const std::string& file_name, const std::string& data) {
78 base::FilePath data_dir; 78 base::FilePath data_dir;
79 CHECK(PathService::Get(key, &data_dir)); 79 CHECK(PathService::Get(key, &data_dir));
80 if (!file_util::DirectoryExists(data_dir) && 80 if (!file_util::DirectoryExists(data_dir) &&
81 !file_util::CreateDirectory(data_dir)) { 81 !file_util::CreateDirectory(data_dir)) {
82 return false; 82 return false;
83 } 83 }
84 base::FilePath file_path = data_dir.Append(file_name); 84 base::FilePath file_path = data_dir.Append(file_name);
85 85
86 return file_util::PathExists(file_path) || 86 return base::PathExists(file_path) ||
87 (file_util::WriteFile(file_path, data.c_str(), 87 (file_util::WriteFile(file_path, data.c_str(),
88 data.size()) != -1); 88 data.size()) != -1);
89 } 89 }
90 90
91 // Gets |file_name| from directory with |key|. Return false if the directory can 91 // Gets |file_name| from directory with |key|. Return false if the directory can
92 // not be found or failed to read file to string |data|. Note if the |file_name| 92 // not be found or failed to read file to string |data|. Note if the |file_name|
93 // can not be found in the directory, return true with empty |data|. It is 93 // can not be found in the directory, return true with empty |data|. It is
94 // expected that we may try to access file which did not saved yet. 94 // expected that we may try to access file which did not saved yet.
95 bool GetData(const base::FilePath& path, std::string* data) { 95 bool GetData(const base::FilePath& path, std::string* data) {
96 base::FilePath data_dir = path.DirName(); 96 base::FilePath data_dir = path.DirName();
97 if (!file_util::DirectoryExists(data_dir) && 97 if (!file_util::DirectoryExists(data_dir) &&
98 !file_util::CreateDirectory(data_dir)) 98 !file_util::CreateDirectory(data_dir))
99 return false; 99 return false;
100 100
101 return !file_util::PathExists(path) || 101 return !base::PathExists(path) ||
102 file_util::ReadFileToString(path, data); 102 file_util::ReadFileToString(path, data);
103 } 103 }
104 104
105 class WindowStateManager; 105 class WindowStateManager;
106 106
107 // static 107 // static
108 WindowStateManager* g_window_state_manager = NULL; 108 WindowStateManager* g_window_state_manager = NULL;
109 109
110 // WindowStateManager remembers which windows have been minimized in order to 110 // WindowStateManager remembers which windows have been minimized in order to
111 // restore them when the wallpaper viewer is hidden. 111 // restore them when the wallpaper viewer is hidden.
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 375 }
376 376
377 void WallpaperPrivateSetWallpaperIfExistsFunction:: 377 void WallpaperPrivateSetWallpaperIfExistsFunction::
378 ReadFileAndInitiateStartDecode(const base::FilePath& file_path, 378 ReadFileAndInitiateStartDecode(const base::FilePath& file_path,
379 const base::FilePath& fallback_path) { 379 const base::FilePath& fallback_path) {
380 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 380 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
381 sequence_token_)); 381 sequence_token_));
382 std::string data; 382 std::string data;
383 base::FilePath path = file_path; 383 base::FilePath path = file_path;
384 384
385 if (!file_util::PathExists(file_path)) 385 if (!base::PathExists(file_path))
386 path = fallback_path; 386 path = fallback_path;
387 387
388 if (file_util::PathExists(path) && 388 if (base::PathExists(path) &&
389 file_util::ReadFileToString(path, &data)) { 389 file_util::ReadFileToString(path, &data)) {
390 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 390 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
391 base::Bind(&WallpaperPrivateSetWallpaperIfExistsFunction::StartDecode, 391 base::Bind(&WallpaperPrivateSetWallpaperIfExistsFunction::StartDecode,
392 this, data)); 392 this, data));
393 return; 393 return;
394 } 394 }
395 std::string error = base::StringPrintf( 395 std::string error = base::StringPrintf(
396 "Failed to set wallpaper %s from file system.", 396 "Failed to set wallpaper %s from file system.",
397 path.BaseName().value().c_str()); 397 path.BaseName().value().c_str());
398 BrowserThread::PostTask( 398 BrowserThread::PostTask(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 BrowserThread::PostTask( 485 BrowserThread::PostTask(
486 BrowserThread::UI, FROM_HERE, 486 BrowserThread::UI, FROM_HERE,
487 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper, 487 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper,
488 this, base::Passed(&deep_copy))); 488 this, base::Passed(&deep_copy)));
489 chromeos::UserImage wallpaper(wallpaper_); 489 chromeos::UserImage wallpaper(wallpaper_);
490 490
491 base::FilePath wallpaper_dir; 491 base::FilePath wallpaper_dir;
492 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 492 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
493 base::FilePath file_path = wallpaper_dir.Append( 493 base::FilePath file_path = wallpaper_dir.Append(
494 file_name).InsertBeforeExtension(chromeos::kSmallWallpaperSuffix); 494 file_name).InsertBeforeExtension(chromeos::kSmallWallpaperSuffix);
495 if (file_util::PathExists(file_path)) 495 if (base::PathExists(file_path))
496 return; 496 return;
497 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to 497 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
498 // maintain the aspect ratio after resize. 498 // maintain the aspect ratio after resize.
499 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( 499 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
500 wallpaper, 500 wallpaper,
501 file_path, 501 file_path,
502 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, 502 ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
503 ash::kSmallWallpaperMaxWidth, 503 ash::kSmallWallpaperMaxWidth,
504 ash::kSmallWallpaperMaxHeight); 504 ash::kSmallWallpaperMaxHeight);
505 } else { 505 } else {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } else { 621 } else {
622 SendResponse(true); 622 SendResponse(true);
623 } 623 }
624 } 624 }
625 625
626 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( 626 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
627 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { 627 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) {
628 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 628 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
629 sequence_token_)); 629 sequence_token_));
630 chromeos::UserImage wallpaper(*image.get()); 630 chromeos::UserImage wallpaper(*image.get());
631 if (!file_util::PathExists(thumbnail_path.DirName())) 631 if (!base::PathExists(thumbnail_path.DirName()))
632 file_util::CreateDirectory(thumbnail_path.DirName()); 632 file_util::CreateDirectory(thumbnail_path.DirName());
633 633
634 scoped_refptr<base::RefCountedBytes> data; 634 scoped_refptr<base::RefCountedBytes> data;
635 chromeos::WallpaperManager::Get()->ResizeWallpaper( 635 chromeos::WallpaperManager::Get()->ResizeWallpaper(
636 wallpaper, 636 wallpaper,
637 ash::WALLPAPER_LAYOUT_STRETCH, 637 ash::WALLPAPER_LAYOUT_STRETCH,
638 ash::kWallpaperThumbnailWidth, 638 ash::kWallpaperThumbnailWidth,
639 ash::kWallpaperThumbnailHeight, 639 ash::kWallpaperThumbnailHeight,
640 &data); 640 &data);
641 BrowserThread::PostTask( 641 BrowserThread::PostTask(
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 this, file_list)); 911 this, file_list));
912 } 912 }
913 913
914 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( 914 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete(
915 const std::vector<std::string>& file_list) { 915 const std::vector<std::string>& file_list) {
916 ListValue* results = new ListValue(); 916 ListValue* results = new ListValue();
917 results->AppendStrings(file_list); 917 results->AppendStrings(file_list);
918 SetResult(results); 918 SetResult(results);
919 SendResponse(true); 919 SendResponse(true);
920 } 920 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698