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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } // namespace wallpaper_api_util | 42 } // namespace wallpaper_api_util |
43 | 43 |
44 class WallpaperFunctionBase::UnsafeWallpaperDecoder | 44 class WallpaperFunctionBase::UnsafeWallpaperDecoder |
45 : public ImageDecoder::Delegate { | 45 : public ImageDecoder::Delegate { |
46 public: | 46 public: |
47 explicit UnsafeWallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function) | 47 explicit UnsafeWallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function) |
48 : function_(function) { | 48 : function_(function) { |
49 } | 49 } |
50 | 50 |
51 void Start(const std::vector<char>& image_data) { | 51 void Start(const std::vector<char>& image_data) { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
53 | 53 |
54 // This function can only be called after user login. It is fine to use | 54 // This function can only be called after user login. It is fine to use |
55 // unsafe image decoder here. Before user login, a robust jpeg decoder will | 55 // unsafe image decoder here. Before user login, a robust jpeg decoder will |
56 // be used. | 56 // be used. |
57 CHECK(chromeos::LoginState::Get()->IsUserLoggedIn()); | 57 CHECK(chromeos::LoginState::Get()->IsUserLoggedIn()); |
58 unsafe_image_decoder_ = new ImageDecoder(this, image_data, | 58 unsafe_image_decoder_ = new ImageDecoder(this, image_data, |
59 ImageDecoder::DEFAULT_CODEC); | 59 ImageDecoder::DEFAULT_CODEC); |
60 unsafe_image_decoder_->set_shrink_to_fit(true); | 60 unsafe_image_decoder_->set_shrink_to_fit(true); |
61 | 61 |
62 scoped_refptr<base::MessageLoopProxy> task_runner = | 62 scoped_refptr<base::MessageLoopProxy> task_runner = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 WallpaperFunctionBase::UnsafeWallpaperDecoder* | 102 WallpaperFunctionBase::UnsafeWallpaperDecoder* |
103 WallpaperFunctionBase::unsafe_wallpaper_decoder_; | 103 WallpaperFunctionBase::unsafe_wallpaper_decoder_; |
104 | 104 |
105 WallpaperFunctionBase::WallpaperFunctionBase() { | 105 WallpaperFunctionBase::WallpaperFunctionBase() { |
106 } | 106 } |
107 | 107 |
108 WallpaperFunctionBase::~WallpaperFunctionBase() { | 108 WallpaperFunctionBase::~WallpaperFunctionBase() { |
109 } | 109 } |
110 | 110 |
111 void WallpaperFunctionBase::StartDecode(const std::vector<char>& data) { | 111 void WallpaperFunctionBase::StartDecode(const std::vector<char>& data) { |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
113 if (unsafe_wallpaper_decoder_) | 113 if (unsafe_wallpaper_decoder_) |
114 unsafe_wallpaper_decoder_->Cancel(); | 114 unsafe_wallpaper_decoder_->Cancel(); |
115 unsafe_wallpaper_decoder_ = new UnsafeWallpaperDecoder(this); | 115 unsafe_wallpaper_decoder_ = new UnsafeWallpaperDecoder(this); |
116 unsafe_wallpaper_decoder_->Start(data); | 116 unsafe_wallpaper_decoder_->Start(data); |
117 } | 117 } |
118 | 118 |
119 void WallpaperFunctionBase::OnCancel() { | 119 void WallpaperFunctionBase::OnCancel() { |
120 unsafe_wallpaper_decoder_ = NULL; | 120 unsafe_wallpaper_decoder_ = NULL; |
121 SetError(wallpaper_api_util::kCancelWallpaperMessage); | 121 SetError(wallpaper_api_util::kCancelWallpaperMessage); |
122 SendResponse(false); | 122 SendResponse(false); |
123 } | 123 } |
124 | 124 |
125 void WallpaperFunctionBase::OnFailure(const std::string& error) { | 125 void WallpaperFunctionBase::OnFailure(const std::string& error) { |
126 unsafe_wallpaper_decoder_ = NULL; | 126 unsafe_wallpaper_decoder_ = NULL; |
127 SetError(error); | 127 SetError(error); |
128 SendResponse(false); | 128 SendResponse(false); |
129 } | 129 } |
OLD | NEW |