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

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 11348215: Make wallpaper picker manifest and thumbnails available when offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment nits Created 8 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/wallpaper_private_api.h" 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_cycle_controller.h" 10 #include "ash/wm/window_cycle_controller.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 420
421 WallpaperRestoreMinimizedWindowsFunction:: 421 WallpaperRestoreMinimizedWindowsFunction::
422 ~WallpaperRestoreMinimizedWindowsFunction() { 422 ~WallpaperRestoreMinimizedWindowsFunction() {
423 } 423 }
424 424
425 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { 425 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() {
426 WindowStateManager::RestoreWindows(); 426 WindowStateManager::RestoreWindows();
427 return true; 427 return true;
428 } 428 }
429
430 WallpaperGetThumbnailFunction::WallpaperGetThumbnailFunction() {
431 }
432
433 WallpaperGetThumbnailFunction::~WallpaperGetThumbnailFunction() {
434 }
435
436 bool WallpaperGetThumbnailFunction::RunImpl() {
437 std::string url;
438 if (args_ == NULL || !args_->GetString(0, &url) || url.empty()) {
miket_OOO 2012/11/28 00:17:19 You ought to be able to use EXTENSION_FUNCTION_VAL
bshe 2012/11/28 18:54:26 Done.
439 return false;
440 }
441 std::string file_name = GURL(url).ExtractFileName();
442 sequence_token_ = BrowserThread::GetBlockingPool()->
443 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
444 scoped_refptr<base::SequencedTaskRunner> task_runner =
445 BrowserThread::GetBlockingPool()->
446 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
447 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
448
449 task_runner->PostTask(FROM_HERE,
450 base::Bind(&WallpaperGetThumbnailFunction::Get,
451 this, file_name));
452 return true;
453 }
454
455 void WallpaperGetThumbnailFunction::Failure() {
456 SetError("Failed to create wallpaper thumbnails directory.");
flackr 2012/11/27 22:04:36 Not localized, is this displayed to the user?
bshe 2012/11/28 18:54:26 It is not displayed to user. The js console and ch
457 SendResponse(false);
458 }
459
460 void WallpaperGetThumbnailFunction::FileNotLoaded() {
461 DictionaryValue* results = new DictionaryValue();
462 results->SetBoolean("success", false);
463 SetResult(results);
464 SendResponse(true);
465 }
466
467 void WallpaperGetThumbnailFunction::FileLoaded(const std::string& data) {
468 DictionaryValue* results = new DictionaryValue();
469 results->SetBoolean("success", true);
470 BinaryValue* thumbnail = BinaryValue::CreateWithCopiedBuffer(data.c_str(),
471 data.size());
472 results->Set("data", thumbnail);
473 SetResult(results);
474 SendResponse(true);
475 }
476
477 void WallpaperGetThumbnailFunction::Get(const std::string& file_name) {
478 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
479 sequence_token_));
480 FilePath wallpaper_thumbnails_dir;
481 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
482 &wallpaper_thumbnails_dir));
483 if (!file_util::DirectoryExists(wallpaper_thumbnails_dir) &&
484 !file_util::CreateDirectory(wallpaper_thumbnails_dir)) {
485 BrowserThread::PostTask(
486 BrowserThread::UI, FROM_HERE,
487 base::Bind(&WallpaperGetThumbnailFunction::Failure,
488 this));
miket_OOO 2012/11/28 00:17:19 no need to wrap (same with below)
bshe 2012/11/28 18:54:26 Done.
489 return;
490 }
491
492 FilePath file_path = wallpaper_thumbnails_dir.Append(file_name);
493 std::string data;
494 if (!file_util::PathExists(file_path) ||
495 file_util::ReadFileToString(file_path, &data) == -1) {
496 BrowserThread::PostTask(
497 BrowserThread::UI, FROM_HERE,
498 base::Bind(&WallpaperGetThumbnailFunction::FileNotLoaded,
499 this));
500 return;
501 }
502 BrowserThread::PostTask(
503 BrowserThread::UI, FROM_HERE,
504 base::Bind(&WallpaperGetThumbnailFunction::FileLoaded,
505 this, data));
506 }
507
508 WallpaperSaveThumbnailFunction::WallpaperSaveThumbnailFunction() {
509 }
510
511 WallpaperSaveThumbnailFunction::~WallpaperSaveThumbnailFunction() {
512 }
513
514 bool WallpaperSaveThumbnailFunction::RunImpl() {
515 BinaryValue* input = NULL;
516 if (args_ == NULL || !args_->GetBinary(0, &input)) {
517 return false;
518 }
519 std::string url;
520 if (!args_->GetString(1, &url) || url.empty()) {
521 return false;
522 }
523 std::string file_name = GURL(url).ExtractFileName();
524 std::string data(input->GetBuffer(), input->GetSize());
525
526 sequence_token_ = BrowserThread::GetBlockingPool()->
527 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
528 scoped_refptr<base::SequencedTaskRunner> task_runner =
529 BrowserThread::GetBlockingPool()->
530 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
531 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
532
533 task_runner->PostTask(FROM_HERE,
534 base::Bind(&WallpaperSaveThumbnailFunction::Save,
535 this, data, file_name));
536 return true;
537 }
538
539 void WallpaperSaveThumbnailFunction::Failure() {
540 SetError("Failed to save thumbnail");
flackr 2012/11/27 22:04:36 ditto.
bshe 2012/11/28 18:54:26 ditto. On 2012/11/27 22:04:36, flackr wrote:
541 SendResponse(false);
542 }
543
544 void WallpaperSaveThumbnailFunction::Success() {
545 SendResponse(true);
546 }
547
548 void WallpaperSaveThumbnailFunction::Save(const std::string& data,
549 const std::string& file_name) {
flackr 2012/11/27 22:04:36 Seems like you should be able to share this saving
bshe 2012/11/28 18:54:26 Done.
550 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
551 sequence_token_));
552 FilePath wallpaper_thumbnails_dir;
553 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
554 &wallpaper_thumbnails_dir));
555 if (!file_util::DirectoryExists(wallpaper_thumbnails_dir) &&
556 !file_util::CreateDirectory(wallpaper_thumbnails_dir)) {
557 BrowserThread::PostTask(
558 BrowserThread::UI, FROM_HERE,
559 base::Bind(&WallpaperSaveThumbnailFunction::Failure,
560 this));
561 return;
562 }
563 FilePath file_path = wallpaper_thumbnails_dir.Append(file_name);
564 if (!file_util::PathExists(file_path)) {
565 size_t written_bytes = file_util::WriteFile(file_path, data.c_str(),
566 data.size());
567 if (written_bytes != data.size()) {
568 BrowserThread::PostTask(
569 BrowserThread::UI, FROM_HERE,
570 base::Bind(&WallpaperSaveThumbnailFunction::Failure,
571 this));
flackr 2012/11/27 22:04:36 return; ? Won't this proceed to post a success me
miket_OOO 2012/11/28 00:17:19 Good catch.
bshe 2012/11/28 18:54:26 right. I must accidentally replaced the return wit
bshe 2012/11/28 18:54:26 Done.
572 }
573 }
574 BrowserThread::PostTask(
575 BrowserThread::UI, FROM_HERE,
576 base::Bind(&WallpaperSaveThumbnailFunction::Success,
577 this));
578 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698