| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/app_mode/kiosk_app_data_base.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/task_scheduler/post_task.h" | 11 #include "base/task_scheduler/post_task.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 15 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Keys for local state data. | 26 // Keys for local state data. |
| 26 constexpr char kKeyName[] = "name"; | 27 constexpr char kKeyName[] = "name"; |
| 27 constexpr char kKeyIcon[] = "icon"; | 28 constexpr char kKeyIcon[] = "icon"; |
| 28 | 29 |
| 29 // Icon file extension. | 30 // Icon file extension. |
| 30 constexpr char kIconFileExtension[] = ".png"; | 31 constexpr char kIconFileExtension[] = ".png"; |
| 31 | 32 |
| 32 // Save |raw_icon| for given |app_id|. | 33 // Save |raw_icon| for given |app_id|. |
| 33 void SaveIconToLocalOnBlockingPool(const base::FilePath& icon_path, | 34 void SaveIconToLocalOnBlockingPool(const base::FilePath& icon_path, |
| 34 std::vector<unsigned char> image_data) { | 35 std::vector<unsigned char> image_data) { |
| 35 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 36 base::ThreadRestrictions::AssertIOAllowed(); |
| 36 | |
| 37 const base::FilePath dir = icon_path.DirName(); | 37 const base::FilePath dir = icon_path.DirName(); |
| 38 if (!base::PathExists(dir) && !base::CreateDirectory(dir)) { | 38 if (!base::PathExists(dir) && !base::CreateDirectory(dir)) { |
| 39 LOG(ERROR) << "Failed to create directory to store kiosk icons"; | 39 LOG(ERROR) << "Failed to create directory to store kiosk icons"; |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 | 42 |
| 43 const int wrote = base::WriteFile( | 43 const int wrote = base::WriteFile( |
| 44 icon_path, reinterpret_cast<char*>(image_data.data()), image_data.size()); | 44 icon_path, reinterpret_cast<char*>(image_data.data()), image_data.size()); |
| 45 if (wrote != static_cast<int>(image_data.size())) { | 45 if (wrote != static_cast<int>(image_data.size())) { |
| 46 LOG(ERROR) << "Failed to write kiosk icon file"; | 46 LOG(ERROR) << "Failed to write kiosk icon file"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 dict_update->Remove(app_key, nullptr); | 119 dict_update->Remove(app_key, nullptr); |
| 120 | 120 |
| 121 if (!icon_path_.empty()) { | 121 if (!icon_path_.empty()) { |
| 122 base::PostTaskWithTraits( | 122 base::PostTaskWithTraits( |
| 123 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, | 123 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 124 base::Bind(base::IgnoreResult(&base::DeleteFile), icon_path_, false)); | 124 base::Bind(base::IgnoreResult(&base::DeleteFile), icon_path_, false)); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace chromeos | 128 } // namespace chromeos |
| OLD | NEW |