| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/chromeos/image_source.h" | 5 #include "chrome/browser/ui/webui/chromeos/image_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 const char* kWhitelistedDirectories[] = { | 31 const char* kWhitelistedDirectories[] = { |
| 32 "regulatory_labels" | 32 "regulatory_labels" |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // Callback for user_manager::UserImageLoader. | 35 // Callback for user_manager::UserImageLoader. |
| 36 void ImageLoaded( | 36 void ImageLoaded( |
| 37 const content::URLDataSource::GotDataCallback& got_data_callback, | 37 const content::URLDataSource::GotDataCallback& got_data_callback, |
| 38 std::unique_ptr<user_manager::UserImage> user_image) { | 38 std::unique_ptr<user_manager::UserImage> user_image) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 | 40 |
| 41 // TODO(crbug.com/593251): Remove the data copy. | |
| 42 if (user_image->has_image_bytes()) | 41 if (user_image->has_image_bytes()) |
| 43 got_data_callback.Run(new base::RefCountedBytes(user_image->image_bytes())); | 42 got_data_callback.Run(user_image->image_bytes()); |
| 44 else | 43 else |
| 45 got_data_callback.Run(NULL); | 44 got_data_callback.Run(nullptr); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 ImageSource::ImageSource() : weak_factory_(this) { | 49 ImageSource::ImageSource() : weak_factory_(this) { |
| 51 base::SequencedWorkerPool* blocking_pool = | 50 base::SequencedWorkerPool* blocking_pool = |
| 52 BrowserThread::GetBlockingPool(); | 51 BrowserThread::GetBlockingPool(); |
| 53 task_runner_ = blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 52 task_runner_ = blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 54 blocking_pool->GetSequenceToken(), | 53 blocking_pool->GetSequenceToken(), |
| 55 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 54 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 56 } | 55 } |
| 57 | 56 |
| 58 ImageSource::~ImageSource() { | 57 ImageSource::~ImageSource() { |
| 59 } | 58 } |
| 60 | 59 |
| 61 std::string ImageSource::GetSource() const { | 60 std::string ImageSource::GetSource() const { |
| 62 return chrome::kChromeOSAssetHost; | 61 return chrome::kChromeOSAssetHost; |
| 63 } | 62 } |
| 64 | 63 |
| 65 void ImageSource::StartDataRequest( | 64 void ImageSource::StartDataRequest( |
| 66 const std::string& path, | 65 const std::string& path, |
| 67 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 66 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 68 const content::URLDataSource::GotDataCallback& got_data_callback) { | 67 const content::URLDataSource::GotDataCallback& got_data_callback) { |
| 69 if (!IsWhitelisted(path)) { | 68 if (!IsWhitelisted(path)) { |
| 70 got_data_callback.Run(NULL); | 69 got_data_callback.Run(nullptr); |
| 71 return; | 70 return; |
| 72 } | 71 } |
| 73 | 72 |
| 74 const base::FilePath asset_dir(FILE_PATH_LITERAL(chrome::kChromeOSAssetPath)); | 73 const base::FilePath asset_dir(FILE_PATH_LITERAL(chrome::kChromeOSAssetPath)); |
| 75 const base::FilePath image_path = asset_dir.AppendASCII(path); | 74 const base::FilePath image_path = asset_dir.AppendASCII(path); |
| 76 base::PostTaskAndReplyWithResult( | 75 base::PostTaskAndReplyWithResult( |
| 77 content::BrowserThread::GetBlockingPool(), | 76 content::BrowserThread::GetBlockingPool(), |
| 78 FROM_HERE, | 77 FROM_HERE, |
| 79 base::Bind(&base::PathExists, image_path), | 78 base::Bind(&base::PathExists, image_path), |
| 80 base::Bind(&ImageSource::StartDataRequestAfterPathExists, | 79 base::Bind(&ImageSource::StartDataRequestAfterPathExists, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return false; | 116 return false; |
| 118 | 117 |
| 119 for (size_t i = 0; i < arraysize(kWhitelistedDirectories); i++) { | 118 for (size_t i = 0; i < arraysize(kWhitelistedDirectories); i++) { |
| 120 if (components[0] == kWhitelistedDirectories[i]) | 119 if (components[0] == kWhitelistedDirectories[i]) |
| 121 return true; | 120 return true; |
| 122 } | 121 } |
| 123 return false; | 122 return false; |
| 124 } | 123 } |
| 125 | 124 |
| 126 } // namespace chromeos | 125 } // namespace chromeos |
| OLD | NEW |