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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/wallpaper_private_api.cc
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index d82c71199e0141db6106236c94edfeb0fadc2e2e..ca5316dda027f87f83f9b2eb77cbb55ac74b3947 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -426,3 +426,153 @@ bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() {
WindowStateManager::RestoreWindows();
return true;
}
+
+WallpaperGetThumbnailFunction::WallpaperGetThumbnailFunction() {
+}
+
+WallpaperGetThumbnailFunction::~WallpaperGetThumbnailFunction() {
+}
+
+bool WallpaperGetThumbnailFunction::RunImpl() {
+ std::string url;
+ 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.
+ return false;
+ }
+ std::string file_name = GURL(url).ExtractFileName();
+ sequence_token_ = BrowserThread::GetBlockingPool()->
+ GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
+ scoped_refptr<base::SequencedTaskRunner> task_runner =
+ BrowserThread::GetBlockingPool()->
+ GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
+
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(&WallpaperGetThumbnailFunction::Get,
+ this, file_name));
+ return true;
+}
+
+void WallpaperGetThumbnailFunction::Failure() {
+ 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
+ SendResponse(false);
+}
+
+void WallpaperGetThumbnailFunction::FileNotLoaded() {
+ DictionaryValue* results = new DictionaryValue();
+ results->SetBoolean("success", false);
+ SetResult(results);
+ SendResponse(true);
+}
+
+void WallpaperGetThumbnailFunction::FileLoaded(const std::string& data) {
+ DictionaryValue* results = new DictionaryValue();
+ results->SetBoolean("success", true);
+ BinaryValue* thumbnail = BinaryValue::CreateWithCopiedBuffer(data.c_str(),
+ data.size());
+ results->Set("data", thumbnail);
+ SetResult(results);
+ SendResponse(true);
+}
+
+void WallpaperGetThumbnailFunction::Get(const std::string& file_name) {
+ DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
+ sequence_token_));
+ FilePath wallpaper_thumbnails_dir;
+ CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
+ &wallpaper_thumbnails_dir));
+ if (!file_util::DirectoryExists(wallpaper_thumbnails_dir) &&
+ !file_util::CreateDirectory(wallpaper_thumbnails_dir)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperGetThumbnailFunction::Failure,
+ this));
miket_OOO 2012/11/28 00:17:19 no need to wrap (same with below)
bshe 2012/11/28 18:54:26 Done.
+ return;
+ }
+
+ FilePath file_path = wallpaper_thumbnails_dir.Append(file_name);
+ std::string data;
+ if (!file_util::PathExists(file_path) ||
+ file_util::ReadFileToString(file_path, &data) == -1) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperGetThumbnailFunction::FileNotLoaded,
+ this));
+ return;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperGetThumbnailFunction::FileLoaded,
+ this, data));
+}
+
+WallpaperSaveThumbnailFunction::WallpaperSaveThumbnailFunction() {
+}
+
+WallpaperSaveThumbnailFunction::~WallpaperSaveThumbnailFunction() {
+}
+
+bool WallpaperSaveThumbnailFunction::RunImpl() {
+ BinaryValue* input = NULL;
+ if (args_ == NULL || !args_->GetBinary(0, &input)) {
+ return false;
+ }
+ std::string url;
+ if (!args_->GetString(1, &url) || url.empty()) {
+ return false;
+ }
+ std::string file_name = GURL(url).ExtractFileName();
+ std::string data(input->GetBuffer(), input->GetSize());
+
+ sequence_token_ = BrowserThread::GetBlockingPool()->
+ GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
+ scoped_refptr<base::SequencedTaskRunner> task_runner =
+ BrowserThread::GetBlockingPool()->
+ GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
+
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(&WallpaperSaveThumbnailFunction::Save,
+ this, data, file_name));
+ return true;
+}
+
+void WallpaperSaveThumbnailFunction::Failure() {
+ 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:
+ SendResponse(false);
+}
+
+void WallpaperSaveThumbnailFunction::Success() {
+ SendResponse(true);
+}
+
+void WallpaperSaveThumbnailFunction::Save(const std::string& data,
+ 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.
+ DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
+ sequence_token_));
+ FilePath wallpaper_thumbnails_dir;
+ CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
+ &wallpaper_thumbnails_dir));
+ if (!file_util::DirectoryExists(wallpaper_thumbnails_dir) &&
+ !file_util::CreateDirectory(wallpaper_thumbnails_dir)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperSaveThumbnailFunction::Failure,
+ this));
+ return;
+ }
+ FilePath file_path = wallpaper_thumbnails_dir.Append(file_name);
+ if (!file_util::PathExists(file_path)) {
+ size_t written_bytes = file_util::WriteFile(file_path, data.c_str(),
+ data.size());
+ if (written_bytes != data.size()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperSaveThumbnailFunction::Failure,
+ 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.
+ }
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperSaveThumbnailFunction::Success,
+ this));
+}

Powered by Google App Engine
This is Rietveld 408576698