Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_data.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Kiosk apps fixed. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 10 #include "base/file_util.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 DISALLOW_COPY_AND_ASSIGN(WebstoreDataParser); 242 DISALLOW_COPY_AND_ASSIGN(WebstoreDataParser);
243 }; 243 };
244 244
245 //////////////////////////////////////////////////////////////////////////////// 245 ////////////////////////////////////////////////////////////////////////////////
246 // KioskAppData 246 // KioskAppData
247 247
248 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, 248 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate,
249 const std::string& app_id) 249 const std::string& app_id)
250 : delegate_(delegate), 250 : delegate_(delegate),
251 status_(STATUS_INIT), 251 status_(STATUS_INIT),
252 id_(app_id) { 252 app_id_(app_id) {
253 } 253 }
254 254
255 KioskAppData::~KioskAppData() {} 255 KioskAppData::~KioskAppData() {}
256 256
257 void KioskAppData::Load() { 257 void KioskAppData::Load() {
258 SetStatus(STATUS_LOADING); 258 SetStatus(STATUS_LOADING);
259 259
260 if (LoadFromCache()) 260 if (LoadFromCache())
261 return; 261 return;
262 262
263 StartFetch(); 263 StartFetch();
264 } 264 }
265 265
266 void KioskAppData::ClearCache() { 266 void KioskAppData::ClearCache() {
267 PrefService* local_state = g_browser_process->local_state(); 267 PrefService* local_state = g_browser_process->local_state();
268 268
269 DictionaryPrefUpdate dict_update(local_state, 269 DictionaryPrefUpdate dict_update(local_state,
270 KioskAppManager::kKioskDictionaryName); 270 KioskAppManager::kKioskDictionaryName);
271 271
272 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + id_; 272 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + app_id_;
273 dict_update->Remove(app_key, NULL); 273 dict_update->Remove(app_key, NULL);
274 274
275 if (!icon_path_.empty()) { 275 if (!icon_path_.empty()) {
276 BrowserThread::PostBlockingPoolTask( 276 BrowserThread::PostBlockingPoolTask(
277 FROM_HERE, 277 FROM_HERE,
278 base::Bind(base::IgnoreResult(&file_util::Delete), icon_path_, false)); 278 base::Bind(base::IgnoreResult(&file_util::Delete), icon_path_, false));
279 } 279 }
280 } 280 }
281 281
282 bool KioskAppData::IsLoading() const { 282 bool KioskAppData::IsLoading() const {
283 return status_ == STATUS_LOADING; 283 return status_ == STATUS_LOADING;
284 } 284 }
285 285
286 void KioskAppData::SetStatus(Status status) { 286 void KioskAppData::SetStatus(Status status) {
287 if (status_ == status) 287 if (status_ == status)
288 return; 288 return;
289 289
290 status_ = status; 290 status_ = status;
291 291
292 if (!delegate_) 292 if (!delegate_)
293 return; 293 return;
294 294
295 switch (status_) { 295 switch (status_) {
296 case STATUS_INIT: 296 case STATUS_INIT:
297 break; 297 break;
298 case STATUS_LOADING: 298 case STATUS_LOADING:
299 case STATUS_LOADED: 299 case STATUS_LOADED:
300 delegate_->OnKioskAppDataChanged(id_); 300 delegate_->OnKioskAppDataChanged(app_id_);
301 break; 301 break;
302 case STATUS_ERROR: 302 case STATUS_ERROR:
303 delegate_->OnKioskAppDataLoadFailure(id_); 303 delegate_->OnKioskAppDataLoadFailure(app_id_);
304 break; 304 break;
305 }; 305 };
306 } 306 }
307 307
308 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { 308 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() {
309 return g_browser_process->system_request_context(); 309 return g_browser_process->system_request_context();
310 } 310 }
311 311
312 bool KioskAppData::LoadFromCache() { 312 bool KioskAppData::LoadFromCache() {
313 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + id_; 313 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + app_id_;
314 std::string name_key = app_key + '.' + kKeyName; 314 std::string name_key = app_key + '.' + kKeyName;
315 std::string icon_path_key = app_key + '.' + kKeyIcon; 315 std::string icon_path_key = app_key + '.' + kKeyIcon;
316 316
317 PrefService* local_state = g_browser_process->local_state(); 317 PrefService* local_state = g_browser_process->local_state();
318 const base::DictionaryValue* dict = 318 const base::DictionaryValue* dict =
319 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); 319 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName);
320 320
321 icon_path_.clear(); 321 icon_path_.clear();
322 std::string icon_path_string; 322 std::string icon_path_string;
323 if (!dict->GetString(name_key, &name_) || 323 if (!dict->GetString(name_key, &name_) ||
324 !dict->GetString(icon_path_key, &icon_path_string)) { 324 !dict->GetString(icon_path_key, &icon_path_string)) {
325 return false; 325 return false;
326 } 326 }
327 icon_path_ = base::FilePath(icon_path_string); 327 icon_path_ = base::FilePath(icon_path_string);
328 328
329 // IconLoader deletes itself when done. 329 // IconLoader deletes itself when done.
330 (new IconLoader(AsWeakPtr(), icon_path_))->Start(); 330 (new IconLoader(AsWeakPtr(), icon_path_))->Start();
331 return true; 331 return true;
332 } 332 }
333 333
334 void KioskAppData::SetCache(const std::string& name, 334 void KioskAppData::SetCache(const std::string& name,
335 const base::FilePath& icon_path) { 335 const base::FilePath& icon_path) {
336 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + id_; 336 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + app_id_;
337 std::string name_key = app_key + '.' + kKeyName; 337 std::string name_key = app_key + '.' + kKeyName;
338 std::string icon_path_key = app_key + '.' + kKeyIcon; 338 std::string icon_path_key = app_key + '.' + kKeyIcon;
339 339
340 PrefService* local_state = g_browser_process->local_state(); 340 PrefService* local_state = g_browser_process->local_state();
341 DictionaryPrefUpdate dict_update(local_state, 341 DictionaryPrefUpdate dict_update(local_state,
342 KioskAppManager::kKioskDictionaryName); 342 KioskAppManager::kKioskDictionaryName);
343 dict_update->SetString(name_key, name); 343 dict_update->SetString(name_key, name);
344 dict_update->SetString(icon_path_key, icon_path.value()); 344 dict_update->SetString(icon_path_key, icon_path.value());
345 icon_path_ = icon_path; 345 icon_path_ = icon_path;
346 } 346 }
(...skipping 19 matching lines...) Expand all
366 std::vector<unsigned char> image_data; 366 std::vector<unsigned char> image_data;
367 CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &image_data)); 367 CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &image_data));
368 raw_icon_ = new base::RefCountedString; 368 raw_icon_ = new base::RefCountedString;
369 raw_icon_->data().assign(image_data.begin(), image_data.end()); 369 raw_icon_->data().assign(image_data.begin(), image_data.end());
370 370
371 base::FilePath cache_dir; 371 base::FilePath cache_dir;
372 if (delegate_) 372 if (delegate_)
373 delegate_->GetKioskAppIconCacheDir(&cache_dir); 373 delegate_->GetKioskAppIconCacheDir(&cache_dir);
374 374
375 base::FilePath icon_path = 375 base::FilePath icon_path =
376 cache_dir.AppendASCII(id_).AddExtension(kIconFileExtension); 376 cache_dir.AppendASCII(app_id_).AddExtension(kIconFileExtension);
377 BrowserThread::GetBlockingPool()->PostTask( 377 BrowserThread::GetBlockingPool()->PostTask(
378 FROM_HERE, 378 FROM_HERE,
379 base::Bind(&SaveIconToLocalOnBlockingPool, icon_path, raw_icon_)); 379 base::Bind(&SaveIconToLocalOnBlockingPool, icon_path, raw_icon_));
380 380
381 SetCache(name_, icon_path); 381 SetCache(name_, icon_path);
382 SetStatus(STATUS_LOADED); 382 SetStatus(STATUS_LOADED);
383 } 383 }
384 384
385 void KioskAppData::OnWebstoreParseFailure() { 385 void KioskAppData::OnWebstoreParseFailure() {
386 SetStatus(STATUS_ERROR); 386 SetStatus(STATUS_ERROR);
387 } 387 }
388 388
389 void KioskAppData::StartFetch() { 389 void KioskAppData::StartFetch() {
390 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher( 390 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher(
391 this, 391 this,
392 GetRequestContextGetter(), 392 GetRequestContextGetter(),
393 GURL(), 393 GURL(),
394 id_)); 394 app_id_));
395 webstore_fetcher_->Start(); 395 webstore_fetcher_->Start();
396 } 396 }
397 397
398 void KioskAppData::OnWebstoreRequestFailure() { 398 void KioskAppData::OnWebstoreRequestFailure() {
399 SetStatus(STATUS_ERROR); 399 SetStatus(STATUS_ERROR);
400 } 400 }
401 401
402 void KioskAppData::OnWebstoreResponseParseSuccess( 402 void KioskAppData::OnWebstoreResponseParseSuccess(
403 base::DictionaryValue* webstore_data) { 403 base::DictionaryValue* webstore_data) {
404 // Takes ownership of |webstore_data|. 404 // Takes ownership of |webstore_data|.
(...skipping 18 matching lines...) Expand all
423 return; 423 return;
424 } 424 }
425 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( 425 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve(
426 icon_url_string); 426 icon_url_string);
427 if (!icon_url.is_valid()) { 427 if (!icon_url.is_valid()) {
428 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); 428 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError);
429 return; 429 return;
430 } 430 }
431 431
432 // WebstoreDataParser deletes itself when done. 432 // WebstoreDataParser deletes itself when done.
433 (new WebstoreDataParser(AsWeakPtr()))->Start(id_, 433 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_,
434 manifest, 434 manifest,
435 icon_url, 435 icon_url,
436 GetRequestContextGetter()); 436 GetRequestContextGetter());
437 } 437 }
438 438
439 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { 439 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) {
440 webstore_fetcher_.reset(); 440 webstore_fetcher_.reset();
441 SetStatus(STATUS_ERROR); 441 SetStatus(STATUS_ERROR);
442 } 442 }
443 443
444 } // namespace chromeos 444 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698