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

Side by Side Diff: chrome/browser/web_applications/web_app.h

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: Move expressions out of argument lists (fix unspecified behaviour). Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "chrome/browser/shell_integration.h" 16 #include "chrome/browser/shell_integration.h"
16 #include "chrome/common/web_application_info.h" 17 #include "chrome/common/web_application_info.h"
17 #include "extensions/common/manifest_handlers/file_handler_info.h" 18 #include "extensions/common/manifest_handlers/file_handler_info.h"
18 19
19 class Profile; 20 class Profile;
20 21
21 namespace content { 22 namespace content {
22 class WebContents; 23 class WebContents;
(...skipping 22 matching lines...) Expand all
45 // and the launch url will be detected at start-up. In this case, |url| 46 // and the launch url will be detected at start-up. In this case, |url|
46 // is still used to generate the app id (windows app id, not chrome app id). 47 // is still used to generate the app id (windows app id, not chrome app id).
47 std::string extension_id; 48 std::string extension_id;
48 bool is_platform_app; 49 bool is_platform_app;
49 base::string16 title; 50 base::string16 title;
50 base::string16 description; 51 base::string16 description;
51 base::FilePath extension_path; 52 base::FilePath extension_path;
52 gfx::ImageFamily favicon; 53 gfx::ImageFamily favicon;
53 base::FilePath profile_path; 54 base::FilePath profile_path;
54 std::string profile_name; 55 std::string profile_name;
56
57 private:
58 // ShortcutInfo must not be copied; generally it is passed around via
59 // scoped_ptrs. This is to allow passing ShortcutInfos between threads,
60 // despite ImageFamily having a non-thread-safe reference count.
61 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo);
55 }; 62 };
56 63
57 // This specifies a folder in the system applications menu (e.g the Start Menu 64 // This specifies a folder in the system applications menu (e.g the Start Menu
58 // on Windows). 65 // on Windows).
59 // 66 //
60 // These represent the applications menu root, the "Google Chrome" folder and 67 // These represent the applications menu root, the "Google Chrome" folder and
61 // the "Chrome Apps" folder respectively. 68 // the "Chrome Apps" folder respectively.
62 // 69 //
63 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the 70 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the
64 // app with the OS (in order to give its windows shelf icons, and correct icons 71 // app with the OS (in order to give its windows shelf icons, and correct icons
(...skipping 25 matching lines...) Expand all
90 }; 97 };
91 98
92 // This encodes the cause of shortcut creation as the correct behavior in each 99 // This encodes the cause of shortcut creation as the correct behavior in each
93 // case is implementation specific. 100 // case is implementation specific.
94 enum ShortcutCreationReason { 101 enum ShortcutCreationReason {
95 SHORTCUT_CREATION_BY_USER, 102 SHORTCUT_CREATION_BY_USER,
96 SHORTCUT_CREATION_AUTOMATED, 103 SHORTCUT_CREATION_AUTOMATED,
97 }; 104 };
98 105
99 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo. 106 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo.
100 typedef base::Callback<void(const ShortcutInfo&, 107 typedef base::Callback<void(scoped_ptr<ShortcutInfo>,
101 const extensions::FileHandlersInfo&)> InfoCallback; 108 const extensions::FileHandlersInfo&)> InfoCallback;
102 109
103 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. 110 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo.
104 typedef base::Callback<void(const ShortcutInfo&)> ShortcutInfoCallback; 111 typedef base::Callback<void(scoped_ptr<ShortcutInfo>)> ShortcutInfoCallback;
105 112
106 #if defined(TOOLKIT_VIEWS) 113 #if defined(TOOLKIT_VIEWS)
107 // Extracts shortcut info of the given WebContents. 114 // Extracts shortcut info of the given WebContents.
108 void GetShortcutInfoForTab(content::WebContents* web_contents, 115 void GetShortcutInfoForTab(content::WebContents* web_contents,
109 ShortcutInfo* info); 116 ShortcutInfo* info);
110 #endif 117 #endif
111 118
112 // Updates web app shortcut of the WebContents. This function checks and 119 // Updates web app shortcut of the WebContents. This function checks and
113 // updates web app icon and shortcuts if needed. For icon, the check is based 120 // updates web app icon and shortcuts if needed. For icon, the check is based
114 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu 121 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu
115 // and quick launch (as well as pinned shortcut) for shortcut and only 122 // and quick launch (as well as pinned shortcut) for shortcut and only
116 // updates (recreates) them if they exits. 123 // updates (recreates) them if they exits.
117 void UpdateShortcutForTabContents(content::WebContents* web_contents); 124 void UpdateShortcutForTabContents(content::WebContents* web_contents);
118 125
119 ShortcutInfo ShortcutInfoForExtensionAndProfile( 126 scoped_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile(
120 const extensions::Extension* app, 127 const extensions::Extension* app,
121 Profile* profile); 128 Profile* profile);
122 129
123 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in 130 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in
124 // |profile| and passes them to |callback| after asynchronously loading all icon 131 // |profile| and passes them to |callback| after asynchronously loading all icon
125 // representations. 132 // representations.
126 void GetInfoForApp(const extensions::Extension* extension, 133 void GetInfoForApp(const extensions::Extension* extension,
127 Profile* profile, 134 Profile* profile,
128 const InfoCallback& callback); 135 const InfoCallback& callback);
129 136
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Extracts the extension id from the app name. 172 // Extracts the extension id from the app name.
166 std::string GetExtensionIdFromApplicationName(const std::string& app_name); 173 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
167 174
168 // Create shortcuts for web application based on given shortcut data. 175 // Create shortcuts for web application based on given shortcut data.
169 // |shortcut_info| contains information about the shortcuts to create, and 176 // |shortcut_info| contains information about the shortcuts to create, and
170 // |locations| contains information about where to create them, while 177 // |locations| contains information about where to create them, while
171 // |file_handlers_info| contains information about the file handlers to create. 178 // |file_handlers_info| contains information about the file handlers to create.
172 void CreateShortcutsWithInfo( 179 void CreateShortcutsWithInfo(
173 ShortcutCreationReason reason, 180 ShortcutCreationReason reason,
174 const ShortcutLocations& locations, 181 const ShortcutLocations& locations,
175 const ShortcutInfo& shortcut_info, 182 scoped_ptr<ShortcutInfo> shortcut_info,
176 const extensions::FileHandlersInfo& file_handlers_info); 183 const extensions::FileHandlersInfo& file_handlers_info);
177 184
178 // Currently only called by app_list_service_mac to create a shim for the 185 // Currently only called by app_list_service_mac to create a shim for the
179 // app launcher. 186 // app launcher.
180 void CreateNonAppShortcut(const ShortcutLocations& locations, 187 void CreateNonAppShortcut(const ShortcutLocations& locations,
181 const ShortcutInfo& shortcut_info); 188 scoped_ptr<ShortcutInfo> shortcut_info);
182 189
183 // Creates shortcuts for an app. This loads the app's icon from disk, and calls 190 // Creates shortcuts for an app. This loads the app's icon from disk, and calls
184 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's 191 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's
185 // icon loaded, you should use CreateShortcutsWithInfo() directly. 192 // icon loaded, you should use CreateShortcutsWithInfo() directly.
186 void CreateShortcuts(ShortcutCreationReason reason, 193 void CreateShortcuts(ShortcutCreationReason reason,
187 const ShortcutLocations& locations, 194 const ShortcutLocations& locations,
188 Profile* profile, 195 Profile* profile,
189 const extensions::Extension* app); 196 const extensions::Extension* app);
190 197
191 // Delete all shortcuts that have been created for the given profile and 198 // Delete all shortcuts that have been created for the given profile and
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 #endif 238 #endif
232 239
233 // Implemented for each platform, does the platform specific parts of creating 240 // Implemented for each platform, does the platform specific parts of creating
234 // shortcuts. Used internally by CreateShortcuts methods. 241 // shortcuts. Used internally by CreateShortcuts methods.
235 // |shortcut_data_path| is where to store any resources created for the 242 // |shortcut_data_path| is where to store any resources created for the
236 // shortcut, and is also used as the UserDataDir for platform app shortcuts. 243 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
237 // |shortcut_info| contains info about the shortcut to create, and 244 // |shortcut_info| contains info about the shortcut to create, and
238 // |creation_locations| contains information about where to create them. 245 // |creation_locations| contains information about where to create them.
239 bool CreatePlatformShortcuts( 246 bool CreatePlatformShortcuts(
240 const base::FilePath& shortcut_data_path, 247 const base::FilePath& shortcut_data_path,
241 const ShortcutInfo& shortcut_info, 248 scoped_ptr<ShortcutInfo> shortcut_info,
242 const extensions::FileHandlersInfo& file_handlers_info, 249 const extensions::FileHandlersInfo& file_handlers_info,
243 const ShortcutLocations& creation_locations, 250 const ShortcutLocations& creation_locations,
244 ShortcutCreationReason creation_reason); 251 ShortcutCreationReason creation_reason);
245 252
246 // Delete all the shortcuts we have added for this extension. This is the 253 // Delete all the shortcuts we have added for this extension. This is the
247 // platform specific implementation of the DeleteAllShortcuts function, and 254 // platform specific implementation of the DeleteAllShortcuts function, and
248 // is executed on the FILE thread. 255 // is executed on the FILE thread.
249 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, 256 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path,
250 const ShortcutInfo& shortcut_info); 257 scoped_ptr<ShortcutInfo> shortcut_info);
251 258
252 // Updates all the shortcuts we have added for this extension. This is the 259 // Updates all the shortcuts we have added for this extension. This is the
253 // platform specific implementation of the UpdateAllShortcuts function, and 260 // platform specific implementation of the UpdateAllShortcuts function, and
254 // is executed on the FILE thread. 261 // is executed on the FILE thread.
255 void UpdatePlatformShortcuts( 262 void UpdatePlatformShortcuts(
256 const base::FilePath& shortcut_data_path, 263 const base::FilePath& shortcut_data_path,
257 const base::string16& old_app_title, 264 const base::string16& old_app_title,
258 const ShortcutInfo& shortcut_info, 265 scoped_ptr<ShortcutInfo> shortcut_info,
259 const extensions::FileHandlersInfo& file_handlers_info); 266 const extensions::FileHandlersInfo& file_handlers_info);
260 267
261 // Delete all the shortcuts for an entire profile. 268 // Delete all the shortcuts for an entire profile.
262 // This is executed on the FILE thread. 269 // This is executed on the FILE thread.
263 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); 270 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
264 271
265 // Sanitizes |name| and returns a version of it that is safe to use as an 272 // Sanitizes |name| and returns a version of it that is safe to use as an
266 // on-disk file name . 273 // on-disk file name .
267 base::FilePath GetSanitizedFileName(const base::string16& name); 274 base::FilePath GetSanitizedFileName(const base::string16& name);
268 275
269 } // namespace internals 276 } // namespace internals
270 277
271 } // namespace web_app 278 } // namespace web_app
272 279
273 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 280 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698