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

Side by Side Diff: chrome/browser/web_applications/update_shortcut_worker_win.cc

Issue 1038573002: Fixed thread-unsafe use of gfx::Image in app shortcut creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/web_applications/update_shortcut_worker_win.h" 5 #include "chrome/browser/web_applications/update_shortcut_worker_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 21 matching lines...) Expand all
32 using content::WebContents; 32 using content::WebContents;
33 33
34 namespace web_app { 34 namespace web_app {
35 35
36 UpdateShortcutWorker::UpdateShortcutWorker(WebContents* web_contents) 36 UpdateShortcutWorker::UpdateShortcutWorker(WebContents* web_contents)
37 : web_contents_(web_contents), 37 : web_contents_(web_contents),
38 profile_path_(Profile::FromBrowserContext( 38 profile_path_(Profile::FromBrowserContext(
39 web_contents->GetBrowserContext())->GetPath()) { 39 web_contents->GetBrowserContext())->GetPath()) {
40 extensions::TabHelper* extensions_tab_helper = 40 extensions::TabHelper* extensions_tab_helper =
41 extensions::TabHelper::FromWebContents(web_contents); 41 extensions::TabHelper::FromWebContents(web_contents);
42 web_app::GetShortcutInfoForTab(web_contents_, &shortcut_info_); 42 shortcut_info_ = web_app::GetShortcutInfoForTab(web_contents_);
43 web_app::GetIconsInfo(extensions_tab_helper->web_app_info(), 43 web_app::GetIconsInfo(extensions_tab_helper->web_app_info(),
44 &unprocessed_icons_); 44 &unprocessed_icons_);
45 file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_.title); 45 file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_->title);
46 46
47 registrar_.Add( 47 registrar_.Add(
48 this, 48 this,
49 chrome::NOTIFICATION_TAB_CLOSING, 49 chrome::NOTIFICATION_TAB_CLOSING,
50 content::Source<NavigationController>(&web_contents->GetController())); 50 content::Source<NavigationController>(&web_contents->GetController()));
51 } 51 }
52 52
53 void UpdateShortcutWorker::Run() { 53 void UpdateShortcutWorker::Run() {
54 // Starting by downloading app icon. 54 // Starting by downloading app icon.
55 DownloadIcon(); 55 DownloadIcon();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 original_sizes, requested_sizes_in_pixel, &closest_indices, NULL); 110 original_sizes, requested_sizes_in_pixel, &closest_indices, NULL);
111 111
112 SkBitmap bitmap; 112 SkBitmap bitmap;
113 if (!bitmaps.empty()) { 113 if (!bitmaps.empty()) {
114 size_t closest_index = closest_indices[0]; 114 size_t closest_index = closest_indices[0];
115 bitmap = bitmaps[closest_index]; 115 bitmap = bitmaps[closest_index];
116 } 116 }
117 117
118 if (!bitmap.isNull()) { 118 if (!bitmap.isNull()) {
119 // Update icon with download image and update shortcut. 119 // Update icon with download image and update shortcut.
120 shortcut_info_.favicon.Add(gfx::Image::CreateFrom1xBitmap(bitmap)); 120 shortcut_info_->favicon.Add(gfx::Image::CreateFrom1xBitmap(bitmap));
121 extensions::TabHelper* extensions_tab_helper = 121 extensions::TabHelper* extensions_tab_helper =
122 extensions::TabHelper::FromWebContents(web_contents_); 122 extensions::TabHelper::FromWebContents(web_contents_);
123 extensions_tab_helper->SetAppIcon(bitmap); 123 extensions_tab_helper->SetAppIcon(bitmap);
124 UpdateShortcuts(); 124 UpdateShortcuts();
125 } else { 125 } else {
126 // Try the next icon otherwise. 126 // Try the next icon otherwise.
127 DownloadIcon(); 127 DownloadIcon();
128 } 128 }
129 } 129 }
130 130
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void UpdateShortcutWorker::UpdateShortcuts() { 172 void UpdateShortcutWorker::UpdateShortcuts() {
173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
174 base::Bind(&UpdateShortcutWorker::UpdateShortcutsOnFileThread, 174 base::Bind(&UpdateShortcutWorker::UpdateShortcutsOnFileThread,
175 base::Unretained(this))); 175 base::Unretained(this)));
176 } 176 }
177 177
178 void UpdateShortcutWorker::UpdateShortcutsOnFileThread() { 178 void UpdateShortcutWorker::UpdateShortcutsOnFileThread() {
179 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 179 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
180 180
181 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( 181 base::FilePath web_app_path = web_app::GetWebAppDataDirectory(
182 profile_path_, shortcut_info_.extension_id, shortcut_info_.url); 182 profile_path_, shortcut_info_->extension_id, shortcut_info_->url);
183 183
184 // Ensure web_app_path exists. web_app_path could be missing for a legacy 184 // Ensure web_app_path exists. web_app_path could be missing for a legacy
185 // shortcut created by Gears. 185 // shortcut created by Gears.
186 if (!base::PathExists(web_app_path) && 186 if (!base::PathExists(web_app_path) &&
187 !base::CreateDirectory(web_app_path)) { 187 !base::CreateDirectory(web_app_path)) {
188 NOTREACHED(); 188 NOTREACHED();
189 return; 189 return;
190 } 190 }
191 191
192 base::FilePath icon_file = 192 base::FilePath icon_file =
193 web_app::internals::GetIconFilePath(web_app_path, shortcut_info_.title); 193 web_app::internals::GetIconFilePath(web_app_path, shortcut_info_->title);
194 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info_.favicon, true); 194 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info_->favicon,
195 true);
195 196
196 // Update existing shortcuts' description, icon and app id. 197 // Update existing shortcuts' description, icon and app id.
197 CheckExistingShortcuts(); 198 CheckExistingShortcuts();
198 if (!shortcut_files_.empty()) { 199 if (!shortcut_files_.empty()) {
199 // Generates app id from web app url and profile path. 200 // Generates app id from web app url and profile path.
200 base::string16 app_id = ShellIntegration::GetAppModelIdForProfile( 201 base::string16 app_id = ShellIntegration::GetAppModelIdForProfile(
201 base::UTF8ToWide( 202 base::UTF8ToWide(
202 web_app::GenerateApplicationNameFromURL(shortcut_info_.url)), 203 web_app::GenerateApplicationNameFromURL(shortcut_info_->url)),
203 profile_path_); 204 profile_path_);
204 205
205 // Sanitize description 206 // Sanitize description
206 if (shortcut_info_.description.length() >= MAX_PATH) 207 if (shortcut_info_->description.length() >= MAX_PATH)
207 shortcut_info_.description.resize(MAX_PATH - 1); 208 shortcut_info_->description.resize(MAX_PATH - 1);
208 209
209 for (size_t i = 0; i < shortcut_files_.size(); ++i) { 210 for (size_t i = 0; i < shortcut_files_.size(); ++i) {
210 base::win::ShortcutProperties shortcut_properties; 211 base::win::ShortcutProperties shortcut_properties;
211 shortcut_properties.set_target(shortcut_files_[i]); 212 shortcut_properties.set_target(shortcut_files_[i]);
212 shortcut_properties.set_description(shortcut_info_.description); 213 shortcut_properties.set_description(shortcut_info_->description);
213 shortcut_properties.set_icon(icon_file, 0); 214 shortcut_properties.set_icon(icon_file, 0);
214 shortcut_properties.set_app_id(app_id); 215 shortcut_properties.set_app_id(app_id);
215 base::win::CreateOrUpdateShortcutLink( 216 base::win::CreateOrUpdateShortcutLink(
216 shortcut_files_[i], shortcut_properties, 217 shortcut_files_[i], shortcut_properties,
217 base::win::SHORTCUT_UPDATE_EXISTING); 218 base::win::SHORTCUT_UPDATE_EXISTING);
218 } 219 }
219 } 220 }
220 221
221 OnShortcutsUpdated(true); 222 OnShortcutsUpdated(true);
222 } 223 }
(...skipping 11 matching lines...) Expand all
234 base::Unretained(this))); 235 base::Unretained(this)));
235 } 236 }
236 } 237 }
237 238
238 void UpdateShortcutWorker::DeleteMeOnUIThread() { 239 void UpdateShortcutWorker::DeleteMeOnUIThread() {
239 DCHECK_CURRENTLY_ON(BrowserThread::UI); 240 DCHECK_CURRENTLY_ON(BrowserThread::UI);
240 delete this; 241 delete this;
241 } 242 }
242 243
243 } // namespace web_app 244 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698