| 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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return CommandLine::ForCurrentProcess()->HasSwitch( | 59 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 60 ash::switches::kAshDefaultWallpaperIsOem); | 60 ash::switches::kAshDefaultWallpaperIsOem); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Saves |data| as |file_name| to directory with |key|. Return false if the | 63 // Saves |data| as |file_name| to directory with |key|. Return false if the |
| 64 // directory can not be found/created or failed to write file. | 64 // directory can not be found/created or failed to write file. |
| 65 bool SaveData(int key, const std::string& file_name, const std::string& data) { | 65 bool SaveData(int key, const std::string& file_name, const std::string& data) { |
| 66 base::FilePath data_dir; | 66 base::FilePath data_dir; |
| 67 CHECK(PathService::Get(key, &data_dir)); | 67 CHECK(PathService::Get(key, &data_dir)); |
| 68 if (!base::DirectoryExists(data_dir) && | 68 if (!base::DirectoryExists(data_dir) && |
| 69 !file_util::CreateDirectory(data_dir)) { | 69 !base::CreateDirectory(data_dir)) { |
| 70 return false; | 70 return false; |
| 71 } | 71 } |
| 72 base::FilePath file_path = data_dir.Append(file_name); | 72 base::FilePath file_path = data_dir.Append(file_name); |
| 73 | 73 |
| 74 return base::PathExists(file_path) || | 74 return base::PathExists(file_path) || |
| 75 (file_util::WriteFile(file_path, data.c_str(), | 75 (file_util::WriteFile(file_path, data.c_str(), |
| 76 data.size()) != -1); | 76 data.size()) != -1); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Gets |file_name| from directory with |key|. Return false if the directory can | 79 // Gets |file_name| from directory with |key|. Return false if the directory can |
| 80 // not be found or failed to read file to string |data|. Note if the |file_name| | 80 // not be found or failed to read file to string |data|. Note if the |file_name| |
| 81 // can not be found in the directory, return true with empty |data|. It is | 81 // can not be found in the directory, return true with empty |data|. It is |
| 82 // expected that we may try to access file which did not saved yet. | 82 // expected that we may try to access file which did not saved yet. |
| 83 bool GetData(const base::FilePath& path, std::string* data) { | 83 bool GetData(const base::FilePath& path, std::string* data) { |
| 84 base::FilePath data_dir = path.DirName(); | 84 base::FilePath data_dir = path.DirName(); |
| 85 if (!base::DirectoryExists(data_dir) && | 85 if (!base::DirectoryExists(data_dir) && |
| 86 !file_util::CreateDirectory(data_dir)) | 86 !base::CreateDirectory(data_dir)) |
| 87 return false; | 87 return false; |
| 88 | 88 |
| 89 return !base::PathExists(path) || | 89 return !base::PathExists(path) || |
| 90 base::ReadFileToString(path, data); | 90 base::ReadFileToString(path, data); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // WindowStateManager remembers which windows have been minimized in order to | 93 // WindowStateManager remembers which windows have been minimized in order to |
| 94 // restore them when the wallpaper viewer is hidden. | 94 // restore them when the wallpaper viewer is hidden. |
| 95 class WindowStateManager : public aura::WindowObserver { | 95 class WindowStateManager : public aura::WindowObserver { |
| 96 public: | 96 public: |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 SendResponse(true); | 566 SendResponse(true); |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 | 569 |
| 570 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( | 570 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( |
| 571 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 571 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { |
| 572 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 572 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 573 sequence_token_)); | 573 sequence_token_)); |
| 574 chromeos::UserImage wallpaper(*image.get()); | 574 chromeos::UserImage wallpaper(*image.get()); |
| 575 if (!base::PathExists(thumbnail_path.DirName())) | 575 if (!base::PathExists(thumbnail_path.DirName())) |
| 576 file_util::CreateDirectory(thumbnail_path.DirName()); | 576 base::CreateDirectory(thumbnail_path.DirName()); |
| 577 | 577 |
| 578 scoped_refptr<base::RefCountedBytes> data; | 578 scoped_refptr<base::RefCountedBytes> data; |
| 579 chromeos::WallpaperManager::Get()->ResizeWallpaper( | 579 chromeos::WallpaperManager::Get()->ResizeWallpaper( |
| 580 wallpaper, | 580 wallpaper, |
| 581 ash::WALLPAPER_LAYOUT_STRETCH, | 581 ash::WALLPAPER_LAYOUT_STRETCH, |
| 582 ash::kWallpaperThumbnailWidth, | 582 ash::kWallpaperThumbnailWidth, |
| 583 ash::kWallpaperThumbnailHeight, | 583 ash::kWallpaperThumbnailHeight, |
| 584 &data); | 584 &data); |
| 585 BrowserThread::PostTask( | 585 BrowserThread::PostTask( |
| 586 BrowserThread::UI, FROM_HERE, | 586 BrowserThread::UI, FROM_HERE, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 this, file_list)); | 842 this, file_list)); |
| 843 } | 843 } |
| 844 | 844 |
| 845 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 845 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 846 const std::vector<std::string>& file_list) { | 846 const std::vector<std::string>& file_list) { |
| 847 ListValue* results = new ListValue(); | 847 ListValue* results = new ListValue(); |
| 848 results->AppendStrings(file_list); | 848 results->AppendStrings(file_list); |
| 849 SetResult(results); | 849 SetResult(results); |
| 850 SendResponse(true); | 850 SendResponse(true); |
| 851 } | 851 } |
| OLD | NEW |