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

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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 original_sizes, requested_sizes_in_pixel, &closest_indices, NULL); 111 original_sizes, requested_sizes_in_pixel, &closest_indices, NULL);
112 112
113 SkBitmap bitmap; 113 SkBitmap bitmap;
114 if (!bitmaps.empty()) { 114 if (!bitmaps.empty()) {
115 size_t closest_index = closest_indices[0]; 115 size_t closest_index = closest_indices[0];
116 bitmap = bitmaps[closest_index]; 116 bitmap = bitmaps[closest_index];
117 } 117 }
118 118
119 if (!bitmap.isNull()) { 119 if (!bitmap.isNull()) {
120 // Update icon with download image and update shortcut. 120 // Update icon with download image and update shortcut.
121 shortcut_info_.favicon.Add(gfx::Image::CreateFrom1xBitmap(bitmap)); 121 shortcut_info_->favicon.Add(gfx::Image::CreateFrom1xBitmap(bitmap));
122 extensions::TabHelper* extensions_tab_helper = 122 extensions::TabHelper* extensions_tab_helper =
123 extensions::TabHelper::FromWebContents(web_contents_); 123 extensions::TabHelper::FromWebContents(web_contents_);
124 extensions_tab_helper->SetAppIcon(bitmap); 124 extensions_tab_helper->SetAppIcon(bitmap);
125 UpdateShortcuts(); 125 UpdateShortcuts();
126 } else { 126 } else {
127 // Try the next icon otherwise. 127 // Try the next icon otherwise.
128 DownloadIcon(); 128 DownloadIcon();
129 } 129 }
130 } 130 }
131 131
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void UpdateShortcutWorker::UpdateShortcuts() { 173 void UpdateShortcutWorker::UpdateShortcuts() {
174 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 174 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
175 base::Bind(&UpdateShortcutWorker::UpdateShortcutsOnFileThread, 175 base::Bind(&UpdateShortcutWorker::UpdateShortcutsOnFileThread,
176 base::Unretained(this))); 176 base::Unretained(this)));
177 } 177 }
178 178
179 void UpdateShortcutWorker::UpdateShortcutsOnFileThread() { 179 void UpdateShortcutWorker::UpdateShortcutsOnFileThread() {
180 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 180 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
181 181
182 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( 182 base::FilePath web_app_path = web_app::GetWebAppDataDirectory(
183 profile_path_, shortcut_info_.extension_id, shortcut_info_.url); 183 profile_path_, shortcut_info_->extension_id, shortcut_info_->url);
184 184
185 // Ensure web_app_path exists. web_app_path could be missing for a legacy 185 // Ensure web_app_path exists. web_app_path could be missing for a legacy
186 // shortcut created by Gears. 186 // shortcut created by Gears.
187 if (!base::PathExists(web_app_path) && 187 if (!base::PathExists(web_app_path) &&
188 !base::CreateDirectory(web_app_path)) { 188 !base::CreateDirectory(web_app_path)) {
189 NOTREACHED(); 189 NOTREACHED();
190 return; 190 return;
191 } 191 }
192 192
193 base::FilePath icon_file = 193 base::FilePath icon_file =
194 web_app::internals::GetIconFilePath(web_app_path, shortcut_info_.title); 194 web_app::internals::GetIconFilePath(web_app_path, shortcut_info_->title);
195 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info_.favicon, true); 195 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info_->favicon,
196 true);
196 197
197 // Update existing shortcuts' description, icon and app id. 198 // Update existing shortcuts' description, icon and app id.
198 CheckExistingShortcuts(); 199 CheckExistingShortcuts();
199 if (!shortcut_files_.empty()) { 200 if (!shortcut_files_.empty()) {
200 // Generates app id from web app url and profile path. 201 // Generates app id from web app url and profile path.
201 base::string16 app_id = ShellIntegration::GetAppModelIdForProfile( 202 base::string16 app_id = ShellIntegration::GetAppModelIdForProfile(
202 base::UTF8ToWide( 203 base::UTF8ToWide(
203 web_app::GenerateApplicationNameFromURL(shortcut_info_.url)), 204 web_app::GenerateApplicationNameFromURL(shortcut_info_->url)),
204 profile_path_); 205 profile_path_);
205 206
206 // Sanitize description 207 // Sanitize description
207 if (shortcut_info_.description.length() >= MAX_PATH) 208 if (shortcut_info_->description.length() >= MAX_PATH)
208 shortcut_info_.description.resize(MAX_PATH - 1); 209 shortcut_info_->description.resize(MAX_PATH - 1);
209 210
210 for (size_t i = 0; i < shortcut_files_.size(); ++i) { 211 for (size_t i = 0; i < shortcut_files_.size(); ++i) {
211 base::win::ShortcutProperties shortcut_properties; 212 base::win::ShortcutProperties shortcut_properties;
212 shortcut_properties.set_target(shortcut_files_[i]); 213 shortcut_properties.set_target(shortcut_files_[i]);
213 shortcut_properties.set_description(shortcut_info_.description); 214 shortcut_properties.set_description(shortcut_info_->description);
214 shortcut_properties.set_icon(icon_file, 0); 215 shortcut_properties.set_icon(icon_file, 0);
215 shortcut_properties.set_app_id(app_id); 216 shortcut_properties.set_app_id(app_id);
216 base::win::CreateOrUpdateShortcutLink( 217 base::win::CreateOrUpdateShortcutLink(
217 shortcut_files_[i], shortcut_properties, 218 shortcut_files_[i], shortcut_properties,
218 base::win::SHORTCUT_UPDATE_EXISTING); 219 base::win::SHORTCUT_UPDATE_EXISTING);
219 } 220 }
220 } 221 }
221 222
222 OnShortcutsUpdated(true); 223 OnShortcutsUpdated(true);
223 } 224 }
(...skipping 11 matching lines...) Expand all
235 base::Unretained(this))); 236 base::Unretained(this)));
236 } 237 }
237 } 238 }
238 239
239 void UpdateShortcutWorker::DeleteMeOnUIThread() { 240 void UpdateShortcutWorker::DeleteMeOnUIThread() {
240 DCHECK_CURRENTLY_ON(BrowserThread::UI); 241 DCHECK_CURRENTLY_ON(BrowserThread::UI);
241 delete this; 242 delete this;
242 } 243 }
243 244
244 } // namespace web_app 245 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/update_shortcut_worker_win.h ('k') | chrome/browser/web_applications/web_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698