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

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

Issue 1067593005: Fix race conditions in ImageDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use TestBrowserThreadBundle, cleanup tests Created 5 years, 8 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
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/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 27 matching lines...) Expand all
38 // Default to use CENTER layout. 38 // Default to use CENTER layout.
39 return wallpaper::WALLPAPER_LAYOUT_CENTER; 39 return wallpaper::WALLPAPER_LAYOUT_CENTER;
40 } 40 }
41 41
42 } // namespace wallpaper_api_util 42 } // namespace wallpaper_api_util
43 43
44 class WallpaperFunctionBase::UnsafeWallpaperDecoder 44 class WallpaperFunctionBase::UnsafeWallpaperDecoder
45 : public ImageDecoder::ImageRequest { 45 : public ImageDecoder::ImageRequest {
46 public: 46 public:
47 explicit UnsafeWallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function) 47 explicit UnsafeWallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function)
48 : ImageRequest( 48 : function_(function) {}
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
50 function_(function) {}
51 49
52 void Start(const std::vector<char>& image_data) { 50 void Start(const std::vector<char>& image_data) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI); 51 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54 52
55 // This function can only be called after user login. It is fine to use 53 // This function can only be called after user login. It is fine to use
56 // unsafe image decoder here. Before user login, a robust jpeg decoder will 54 // unsafe image decoder here. Before user login, a robust jpeg decoder will
57 // be used. 55 // be used.
58 CHECK(chromeos::LoginState::Get()->IsUserLoggedIn()); 56 CHECK(chromeos::LoginState::Get()->IsUserLoggedIn());
59 std::string image_data_str(image_data.begin(), image_data.end()); 57 std::string image_data_str(image_data.begin(), image_data.end());
60 ImageDecoder::StartWithOptions(this, image_data_str, 58 ImageDecoder::StartWithOptions(this, image_data_str,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 unsafe_wallpaper_decoder_ = NULL; 113 unsafe_wallpaper_decoder_ = NULL;
116 SetError(wallpaper_api_util::kCancelWallpaperMessage); 114 SetError(wallpaper_api_util::kCancelWallpaperMessage);
117 SendResponse(false); 115 SendResponse(false);
118 } 116 }
119 117
120 void WallpaperFunctionBase::OnFailure(const std::string& error) { 118 void WallpaperFunctionBase::OnFailure(const std::string& error) {
121 unsafe_wallpaper_decoder_ = NULL; 119 unsafe_wallpaper_decoder_ = NULL;
122 SetError(error); 120 SetError(error);
123 SendResponse(false); 121 SendResponse(false);
124 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698