| 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/extensions/wallpaper_function_base.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" |
| 6 | 6 |
| 7 #include "base/synchronization/cancellation_flag.h" | 7 #include "base/synchronization/cancellation_flag.h" |
| 8 #include "chrome/browser/image_decoder.h" | 8 #include "chrome/browser/image_decoder.h" |
| 9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 10 #include "chromeos/login/login_state.h" | 10 #include "chromeos/login/login_state.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 scoped_refptr<base::MessageLoopProxy> task_runner = | 61 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 62 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 62 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 63 unsafe_image_decoder_->Start(task_runner); | 63 unsafe_image_decoder_->Start(task_runner); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Cancel() { | 66 void Cancel() { |
| 67 cancel_flag_.Set(); | 67 cancel_flag_.Set(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void OnImageDecoded(const ImageDecoder* decoder, | 70 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 71 const SkBitmap& decoded_image) OVERRIDE { | 71 const SkBitmap& decoded_image) override { |
| 72 // Make the SkBitmap immutable as we won't modify it. This is important | 72 // Make the SkBitmap immutable as we won't modify it. This is important |
| 73 // because otherwise it gets duplicated during painting, wasting memory. | 73 // because otherwise it gets duplicated during painting, wasting memory. |
| 74 SkBitmap immutable(decoded_image); | 74 SkBitmap immutable(decoded_image); |
| 75 immutable.setImmutable(); | 75 immutable.setImmutable(); |
| 76 gfx::ImageSkia final_image = gfx::ImageSkia::CreateFrom1xBitmap(immutable); | 76 gfx::ImageSkia final_image = gfx::ImageSkia::CreateFrom1xBitmap(immutable); |
| 77 final_image.MakeThreadSafe(); | 77 final_image.MakeThreadSafe(); |
| 78 if (cancel_flag_.IsSet()) { | 78 if (cancel_flag_.IsSet()) { |
| 79 function_->OnCancel(); | 79 function_->OnCancel(); |
| 80 delete this; | 80 delete this; |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 function_->OnWallpaperDecoded(final_image); | 83 function_->OnWallpaperDecoded(final_image); |
| 84 delete this; | 84 delete this; |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { | 87 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) override { |
| 88 function_->OnFailure( | 88 function_->OnFailure( |
| 89 l10n_util::GetStringUTF8(IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER)); | 89 l10n_util::GetStringUTF8(IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER)); |
| 90 delete this; | 90 delete this; |
| 91 } | 91 } |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 scoped_refptr<WallpaperFunctionBase> function_; | 94 scoped_refptr<WallpaperFunctionBase> function_; |
| 95 scoped_refptr<ImageDecoder> unsafe_image_decoder_; | 95 scoped_refptr<ImageDecoder> unsafe_image_decoder_; |
| 96 base::CancellationFlag cancel_flag_; | 96 base::CancellationFlag cancel_flag_; |
| 97 | 97 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 unsafe_wallpaper_decoder_ = NULL; | 119 unsafe_wallpaper_decoder_ = NULL; |
| 120 SetError(wallpaper_api_util::kCancelWallpaperMessage); | 120 SetError(wallpaper_api_util::kCancelWallpaperMessage); |
| 121 SendResponse(false); | 121 SendResponse(false); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void WallpaperFunctionBase::OnFailure(const std::string& error) { | 124 void WallpaperFunctionBase::OnFailure(const std::string& error) { |
| 125 unsafe_wallpaper_decoder_ = NULL; | 125 unsafe_wallpaper_decoder_ = NULL; |
| 126 SetError(error); | 126 SetError(error); |
| 127 SendResponse(false); | 127 SendResponse(false); |
| 128 } | 128 } |
| OLD | NEW |