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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" | 12 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "components/user_manager/user_image/user_image.h" | 14 #include "components/user_manager/user_image/user_image.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
17 | 17 |
18 using content::BrowserThread; | 18 using content::BrowserThread; |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char* kWhitelistedFiles[] = { | 23 const char* kWhitelistedFiles[] = { |
24 "fcc.png" | 24 "fcc/label.png" |
25 }; | 25 }; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 ImageSource::ImageSource() : weak_factory_(this) { | 29 ImageSource::ImageSource() : weak_factory_(this) { |
30 base::SequencedWorkerPool* blocking_pool = | 30 base::SequencedWorkerPool* blocking_pool = |
31 BrowserThread::GetBlockingPool(); | 31 BrowserThread::GetBlockingPool(); |
32 task_runner_ = blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 32 task_runner_ = blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
33 blocking_pool->GetSequenceToken(), | 33 blocking_pool->GetSequenceToken(), |
34 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 34 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
35 } | 35 } |
36 | 36 |
37 ImageSource::~ImageSource() { | 37 ImageSource::~ImageSource() { |
38 } | 38 } |
39 | 39 |
40 std::string ImageSource::GetSource() const { | 40 std::string ImageSource::GetSource() const { |
41 return chrome::kChromeUILocalImageHost; | 41 return chrome::kChromeOSAssetHost; |
42 } | 42 } |
43 | 43 |
44 void ImageSource::StartDataRequest( | 44 void ImageSource::StartDataRequest( |
45 const std::string& path, | 45 const std::string& path, |
46 int render_process_id, | 46 int render_process_id, |
47 int render_frame_id, | 47 int render_frame_id, |
48 const content::URLDataSource::GotDataCallback& callback) { | 48 const content::URLDataSource::GotDataCallback& callback) { |
49 if (!IsWhitelisted(path)) { | 49 if (!IsWhitelisted(path)) { |
50 callback.Run(NULL); | 50 callback.Run(NULL); |
51 return; | 51 return; |
(...skipping 12 matching lines...) Expand all Loading... |
64 if (!ext.empty()) | 64 if (!ext.empty()) |
65 net::GetWellKnownMimeTypeFromExtension(ext.substr(1), &mime_type); | 65 net::GetWellKnownMimeTypeFromExtension(ext.substr(1), &mime_type); |
66 return mime_type; | 66 return mime_type; |
67 } | 67 } |
68 | 68 |
69 void ImageSource::StartOnFileThread( | 69 void ImageSource::StartOnFileThread( |
70 const std::string& path, | 70 const std::string& path, |
71 const content::URLDataSource::GotDataCallback& callback) { | 71 const content::URLDataSource::GotDataCallback& callback) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
73 | 73 |
74 base::FilePath file_path(chrome::kChromeUILocalImagePath + path); | 74 base::FilePath file_path(chrome::kChromeOSAssetPath + path); |
75 if (!base::PathExists(file_path)) { | 75 if (!base::PathExists(file_path)) { |
76 callback.Run(NULL); | 76 callback.Run(NULL); |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 image_loader_ = new UserImageLoader(ImageDecoder::DEFAULT_CODEC, | 80 image_loader_ = new UserImageLoader(ImageDecoder::DEFAULT_CODEC, |
81 task_runner_); | 81 task_runner_); |
82 image_loader_->Start(file_path.value(), | 82 image_loader_->Start(file_path.value(), |
83 0, | 83 0, |
84 base::Bind(&ImageSource::ImageLoaded, | 84 base::Bind(&ImageSource::ImageLoaded, |
85 weak_factory_.GetWeakPtr(), | 85 weak_factory_.GetWeakPtr(), |
86 callback)); | 86 callback)); |
87 } | 87 } |
88 | 88 |
89 void ImageSource::ImageLoaded( | 89 void ImageSource::ImageLoaded( |
90 const content::URLDataSource::GotDataCallback& callback, | 90 const content::URLDataSource::GotDataCallback& callback, |
91 const user_manager::UserImage& user_image) const { | 91 const user_manager::UserImage& user_image) const { |
92 if (user_image.has_raw_image()) | 92 if (user_image.has_raw_image()) |
93 callback.Run(new base::RefCountedBytes(user_image.raw_image())); | 93 callback.Run(new base::RefCountedBytes(user_image.raw_image())); |
94 else | 94 else |
95 callback.Run(NULL); | 95 callback.Run(NULL); |
96 } | 96 } |
97 | 97 |
98 bool ImageSource::IsWhitelisted(const std::string& path) const { | 98 bool ImageSource::IsWhitelisted(const std::string& path) const { |
99 const char** end = kWhitelistedFiles + arraysize(kWhitelistedFiles); | 99 const char** end = kWhitelistedFiles + arraysize(kWhitelistedFiles); |
100 return std::find(kWhitelistedFiles, end, path) != end; | 100 return std::find(kWhitelistedFiles, end, path) != end; |
101 } | 101 } |
102 | 102 |
103 } // namespace chromeos | 103 } // namespace chromeos |
OLD | NEW |