OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/app_mode/kiosk_app_data.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 token, | 108 token, |
109 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 109 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
110 task_runner_->PostTask(FROM_HERE, | 110 task_runner_->PostTask(FROM_HERE, |
111 base::Bind(&IconLoader::LoadOnBlockingPool, | 111 base::Bind(&IconLoader::LoadOnBlockingPool, |
112 base::Unretained(this))); | 112 base::Unretained(this))); |
113 } | 113 } |
114 | 114 |
115 private: | 115 private: |
116 friend class base::RefCountedThreadSafe<IconLoader>; | 116 friend class base::RefCountedThreadSafe<IconLoader>; |
117 | 117 |
118 virtual ~IconLoader() {} | 118 ~IconLoader() override {} |
119 | 119 |
120 // Loads the icon from locally stored |icon_path_| on the blocking pool | 120 // Loads the icon from locally stored |icon_path_| on the blocking pool |
121 void LoadOnBlockingPool() { | 121 void LoadOnBlockingPool() { |
122 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 122 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
123 | 123 |
124 std::string data; | 124 std::string data; |
125 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { | 125 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { |
126 ReportResultOnBlockingPool(FAILED_TO_LOAD); | 126 ReportResultOnBlockingPool(FAILED_TO_LOAD); |
127 return; | 127 return; |
128 } | 128 } |
(...skipping 26 matching lines...) Expand all Loading... |
155 } | 155 } |
156 | 156 |
157 void ReportResultOnUIThread() { | 157 void ReportResultOnUIThread() { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
159 | 159 |
160 NotifyClient(); | 160 NotifyClient(); |
161 delete this; | 161 delete this; |
162 } | 162 } |
163 | 163 |
164 // ImageDecoder::Delegate overrides: | 164 // ImageDecoder::Delegate overrides: |
165 virtual void OnImageDecoded(const ImageDecoder* decoder, | 165 void OnImageDecoded(const ImageDecoder* decoder, |
166 const SkBitmap& decoded_image) override { | 166 const SkBitmap& decoded_image) override { |
167 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | 167 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); |
168 icon_.MakeThreadSafe(); | 168 icon_.MakeThreadSafe(); |
169 ReportResultOnBlockingPool(SUCCESS); | 169 ReportResultOnBlockingPool(SUCCESS); |
170 } | 170 } |
171 | 171 |
172 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) override { | 172 void OnDecodeImageFailed(const ImageDecoder* decoder) override { |
173 ReportResultOnBlockingPool(FAILED_TO_DECODE); | 173 ReportResultOnBlockingPool(FAILED_TO_DECODE); |
174 } | 174 } |
175 | 175 |
176 base::WeakPtr<KioskAppData> client_; | 176 base::WeakPtr<KioskAppData> client_; |
177 base::FilePath icon_path_; | 177 base::FilePath icon_path_; |
178 | 178 |
179 LoadResult load_result_; | 179 LoadResult load_result_; |
180 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 180 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
181 | 181 |
182 gfx::ImageSkia icon_; | 182 gfx::ImageSkia icon_; |
(...skipping 22 matching lines...) Expand all Loading... |
205 manifest, | 205 manifest, |
206 "", // No icon data. | 206 "", // No icon data. |
207 icon_url, | 207 icon_url, |
208 context_getter); | 208 context_getter); |
209 webstore_helper->Start(); | 209 webstore_helper->Start(); |
210 } | 210 } |
211 | 211 |
212 private: | 212 private: |
213 friend class base::RefCounted<WebstoreDataParser>; | 213 friend class base::RefCounted<WebstoreDataParser>; |
214 | 214 |
215 virtual ~WebstoreDataParser() {} | 215 ~WebstoreDataParser() override {} |
216 | 216 |
217 void ReportFailure() { | 217 void ReportFailure() { |
218 if (client_) | 218 if (client_) |
219 client_->OnWebstoreParseFailure(); | 219 client_->OnWebstoreParseFailure(); |
220 | 220 |
221 delete this; | 221 delete this; |
222 } | 222 } |
223 | 223 |
224 // WebstoreInstallHelper::Delegate overrides: | 224 // WebstoreInstallHelper::Delegate overrides: |
225 virtual void OnWebstoreParseSuccess( | 225 void OnWebstoreParseSuccess(const std::string& id, |
226 const std::string& id, | 226 const SkBitmap& icon, |
227 const SkBitmap& icon, | 227 base::DictionaryValue* parsed_manifest) override { |
228 base::DictionaryValue* parsed_manifest) override { | |
229 // Takes ownership of |parsed_manifest|. | 228 // Takes ownership of |parsed_manifest|. |
230 extensions::Manifest manifest( | 229 extensions::Manifest manifest( |
231 extensions::Manifest::INVALID_LOCATION, | 230 extensions::Manifest::INVALID_LOCATION, |
232 scoped_ptr<base::DictionaryValue>(parsed_manifest)); | 231 scoped_ptr<base::DictionaryValue>(parsed_manifest)); |
233 | 232 |
234 if (!IsValidKioskAppManifest(manifest)) { | 233 if (!IsValidKioskAppManifest(manifest)) { |
235 ReportFailure(); | 234 ReportFailure(); |
236 return; | 235 return; |
237 } | 236 } |
238 | 237 |
239 if (client_) | 238 if (client_) |
240 client_->OnWebstoreParseSuccess(icon); | 239 client_->OnWebstoreParseSuccess(icon); |
241 delete this; | 240 delete this; |
242 } | 241 } |
243 virtual void OnWebstoreParseFailure( | 242 void OnWebstoreParseFailure(const std::string& id, |
244 const std::string& id, | 243 InstallHelperResultCode result_code, |
245 InstallHelperResultCode result_code, | 244 const std::string& error_message) override { |
246 const std::string& error_message) override { | |
247 ReportFailure(); | 245 ReportFailure(); |
248 } | 246 } |
249 | 247 |
250 base::WeakPtr<KioskAppData> client_; | 248 base::WeakPtr<KioskAppData> client_; |
251 | 249 |
252 DISALLOW_COPY_AND_ASSIGN(WebstoreDataParser); | 250 DISALLOW_COPY_AND_ASSIGN(WebstoreDataParser); |
253 }; | 251 }; |
254 | 252 |
255 //////////////////////////////////////////////////////////////////////////////// | 253 //////////////////////////////////////////////////////////////////////////////// |
256 // KioskAppData | 254 // KioskAppData |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (!response->GetString(key, value)) { | 496 if (!response->GetString(key, value)) { |
499 LOG(ERROR) << "Webstore response error (" << key | 497 LOG(ERROR) << "Webstore response error (" << key |
500 << "): " << ValueToString(response); | 498 << "): " << ValueToString(response); |
501 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 499 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
502 return false; | 500 return false; |
503 } | 501 } |
504 return true; | 502 return true; |
505 } | 503 } |
506 | 504 |
507 } // namespace chromeos | 505 } // namespace chromeos |
OLD | NEW |