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

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

Issue 2721553002: Make web_app::ShortcutInfo RefCountedThreadSafe (1) (Closed)
Patch Set: +comment Created 3 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/sequenced_task_runner_helpers.h"
15 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
17 #include "chrome/browser/shell_integration.h" 19 #include "chrome/browser/shell_integration.h"
18 #include "chrome/common/web_application_info.h" 20 #include "chrome/common/web_application_info.h"
21 #include "content/public/browser/browser_thread.h"
19 22
20 class Profile; 23 class Profile;
21 24
22 namespace content { 25 namespace content {
23 class WebContents; 26 class WebContents;
24 } 27 }
25 28
26 namespace extensions { 29 namespace extensions {
27 class Extension; 30 class Extension;
28 } 31 }
29 32
30 namespace gfx { 33 namespace gfx {
31 class ImageFamily; 34 class ImageFamily;
32 } 35 }
33 36
34 // This namespace contains everything related to integrating Chrome apps into 37 // This namespace contains everything related to integrating Chrome apps into
35 // the OS. E.g. creating and updating shorcuts for apps, setting up file 38 // the OS. E.g. creating and updating shorcuts for apps, setting up file
36 // associations, etc. 39 // associations, etc.
37 namespace web_app { 40 namespace web_app {
38 41
39 // Represents the info required to create a shortcut for an app. 42 // Represents the info required to create a shortcut for an app.
40 struct ShortcutInfo { 43 // ShortcutInfo is passed around via scoped_refptrs, and is destroyed on UI
44 // thread. Since gfx::ImageFamily can have gfx::Image and it has ImageStorage
45 // which has a non-thread-safe ref count bound to UI thread, all ref count
46 // manipulation must happen on UI thread.
47 struct ShortcutInfo : public base::RefCountedThreadSafe<
48 ShortcutInfo,
49 content::BrowserThread::DeleteOnUIThread> {
41 ShortcutInfo(); 50 ShortcutInfo();
42 ~ShortcutInfo();
43 51
44 GURL url; 52 GURL url;
45 // If |extension_id| is non-empty, this is short cut is to an extension-app 53 // If |extension_id| is non-empty, this is short cut is to an extension-app
46 // and the launch url will be detected at start-up. In this case, |url| 54 // and the launch url will be detected at start-up. In this case, |url|
47 // is still used to generate the app id (windows app id, not chrome app id). 55 // is still used to generate the app id (windows app id, not chrome app id).
48 std::string extension_id; 56 std::string extension_id;
49 bool is_platform_app = false; 57 bool is_platform_app = false;
50 bool from_bookmark = false; 58 bool from_bookmark = false;
51 base::string16 title; 59 base::string16 title;
52 base::string16 description; 60 base::string16 description;
53 base::FilePath extension_path; 61 base::FilePath extension_path;
54 gfx::ImageFamily favicon; 62 gfx::ImageFamily favicon;
55 base::FilePath profile_path; 63 base::FilePath profile_path;
56 std::string profile_name; 64 std::string profile_name;
57 std::string version_for_display; 65 std::string version_for_display;
58 66
59 private: 67 private:
60 // ShortcutInfo must not be copied; generally it is passed around via 68 friend struct content::BrowserThread::DeleteOnThread<
61 // scoped_ptrs. This is to allow passing ShortcutInfos between threads, 69 content::BrowserThread::UI>;
62 // despite ImageFamily having a non-thread-safe reference count. 70 friend class base::DeleteHelper<ShortcutInfo>;
71 ~ShortcutInfo();
72
63 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo); 73 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo);
64 }; 74 };
65 75
66 // This specifies a folder in the system applications menu (e.g the Start Menu 76 // This specifies a folder in the system applications menu (e.g the Start Menu
67 // on Windows). 77 // on Windows).
68 // 78 //
69 // These represent the applications menu root, the "Google Chrome" folder and 79 // These represent the applications menu root, the "Google Chrome" folder and
70 // the "Chrome Apps" folder respectively. 80 // the "Chrome Apps" folder respectively.
71 // 81 //
72 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the 82 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the
(...skipping 26 matching lines...) Expand all
99 }; 109 };
100 110
101 // This encodes the cause of shortcut creation as the correct behavior in each 111 // This encodes the cause of shortcut creation as the correct behavior in each
102 // case is implementation specific. 112 // case is implementation specific.
103 enum ShortcutCreationReason { 113 enum ShortcutCreationReason {
104 SHORTCUT_CREATION_BY_USER, 114 SHORTCUT_CREATION_BY_USER,
105 SHORTCUT_CREATION_AUTOMATED, 115 SHORTCUT_CREATION_AUTOMATED,
106 }; 116 };
107 117
108 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. 118 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo.
109 typedef base::Callback<void(std::unique_ptr<ShortcutInfo>)> 119 typedef base::Callback<void(scoped_refptr<ShortcutInfo>)> ShortcutInfoCallback;
110 ShortcutInfoCallback;
111 120
112 #if defined(TOOLKIT_VIEWS) 121 #if defined(TOOLKIT_VIEWS)
113 // Extracts shortcut info of the given WebContents. 122 // Extracts shortcut info of the given WebContents.
114 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( 123 scoped_refptr<ShortcutInfo> GetShortcutInfoForTab(
115 content::WebContents* web_contents); 124 content::WebContents* web_contents);
116 #endif 125 #endif
117 126
118 // Updates web app shortcut of the WebContents. This function checks and 127 // Updates web app shortcut of the WebContents. This function checks and
119 // updates web app icon and shortcuts if needed. For icon, the check is based 128 // updates web app icon and shortcuts if needed. For icon, the check is based
120 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu 129 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu
121 // and quick launch (as well as pinned shortcut) for shortcut and only 130 // and quick launch (as well as pinned shortcut) for shortcut and only
122 // updates (recreates) them if they exits. 131 // updates (recreates) them if they exits.
123 void UpdateShortcutForTabContents(content::WebContents* web_contents); 132 void UpdateShortcutForTabContents(content::WebContents* web_contents);
124 133
125 std::unique_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( 134 scoped_refptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile(
126 const extensions::Extension* app, 135 const extensions::Extension* app,
127 Profile* profile); 136 Profile* profile);
128 137
129 // Populates a ShortcutInfo for the given |extension| in |profile| and passes 138 // Populates a ShortcutInfo for the given |extension| in |profile| and passes
130 // it to |callback| after asynchronously loading all icon representations. 139 // it to |callback| after asynchronously loading all icon representations.
131 void GetShortcutInfoForApp(const extensions::Extension* extension, 140 void GetShortcutInfoForApp(const extensions::Extension* extension,
132 Profile* profile, 141 Profile* profile,
133 const ShortcutInfoCallback& callback); 142 const ShortcutInfoCallback& callback);
134 143
135 // Whether to create a shortcut for this type of extension. 144 // Whether to create a shortcut for this type of extension.
(...skipping 25 matching lines...) Expand all
161 std::string GenerateApplicationNameFromExtensionId(const std::string& id); 170 std::string GenerateApplicationNameFromExtensionId(const std::string& id);
162 171
163 // Extracts the extension id from the app name. 172 // Extracts the extension id from the app name.
164 std::string GetExtensionIdFromApplicationName(const std::string& app_name); 173 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
165 174
166 // Create shortcuts for web application based on given shortcut data. 175 // Create shortcuts for web application based on given shortcut data.
167 // |shortcut_info| contains information about the shortcuts to create, and 176 // |shortcut_info| contains information about the shortcuts to create, and
168 // |locations| contains information about where to create them. 177 // |locations| contains information about where to create them.
169 void CreateShortcutsWithInfo(ShortcutCreationReason reason, 178 void CreateShortcutsWithInfo(ShortcutCreationReason reason,
170 const ShortcutLocations& locations, 179 const ShortcutLocations& locations,
171 std::unique_ptr<ShortcutInfo> shortcut_info); 180 scoped_refptr<ShortcutInfo> shortcut_info);
172 181
173 // Creates shortcuts for an app. This loads the app's icon from disk, and calls 182 // Creates shortcuts for an app. This loads the app's icon from disk, and calls
174 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's 183 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's
175 // icon loaded, you should use CreateShortcutsWithInfo() directly. 184 // icon loaded, you should use CreateShortcutsWithInfo() directly.
176 void CreateShortcuts(ShortcutCreationReason reason, 185 void CreateShortcuts(ShortcutCreationReason reason,
177 const ShortcutLocations& locations, 186 const ShortcutLocations& locations,
178 Profile* profile, 187 Profile* profile,
179 const extensions::Extension* app); 188 const extensions::Extension* app);
180 189
181 // Delete all shortcuts that have been created for the given profile and 190 // Delete all shortcuts that have been created for the given profile and
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 std::vector<base::FilePath> GetShortcutPaths( 231 std::vector<base::FilePath> GetShortcutPaths(
223 const ShortcutLocations& creation_locations); 232 const ShortcutLocations& creation_locations);
224 #endif 233 #endif
225 234
226 // Implemented for each platform, does the platform specific parts of creating 235 // Implemented for each platform, does the platform specific parts of creating
227 // shortcuts. Used internally by CreateShortcuts methods. 236 // shortcuts. Used internally by CreateShortcuts methods.
228 // |shortcut_data_path| is where to store any resources created for the 237 // |shortcut_data_path| is where to store any resources created for the
229 // shortcut, and is also used as the UserDataDir for platform app shortcuts. 238 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
230 // |shortcut_info| contains info about the shortcut to create, and 239 // |shortcut_info| contains info about the shortcut to create, and
231 // |creation_locations| contains information about where to create them. 240 // |creation_locations| contains information about where to create them.
232 bool CreatePlatformShortcuts( 241 bool CreatePlatformShortcuts(const base::FilePath& shortcut_data_path,
233 const base::FilePath& shortcut_data_path, 242 scoped_refptr<ShortcutInfo> shortcut_info,
234 std::unique_ptr<ShortcutInfo> shortcut_info, 243 const ShortcutLocations& creation_locations,
235 const ShortcutLocations& creation_locations, 244 ShortcutCreationReason creation_reason);
236 ShortcutCreationReason creation_reason);
237 245
238 // Delete all the shortcuts we have added for this extension. This is the 246 // Delete all the shortcuts we have added for this extension. This is the
239 // platform specific implementation of the DeleteAllShortcuts function, and 247 // platform specific implementation of the DeleteAllShortcuts function, and
240 // is executed on the FILE thread. 248 // is executed on the FILE thread.
241 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, 249 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path,
242 std::unique_ptr<ShortcutInfo> shortcut_info); 250 scoped_refptr<ShortcutInfo> shortcut_info);
243 251
244 // Updates all the shortcuts we have added for this extension. This is the 252 // Updates all the shortcuts we have added for this extension. This is the
245 // platform specific implementation of the UpdateAllShortcuts function, and 253 // platform specific implementation of the UpdateAllShortcuts function, and
246 // is executed on the FILE thread. 254 // is executed on the FILE thread.
247 void UpdatePlatformShortcuts(const base::FilePath& shortcut_data_path, 255 void UpdatePlatformShortcuts(const base::FilePath& shortcut_data_path,
248 const base::string16& old_app_title, 256 const base::string16& old_app_title,
249 std::unique_ptr<ShortcutInfo> shortcut_info); 257 scoped_refptr<ShortcutInfo> shortcut_info);
250 258
251 // Delete all the shortcuts for an entire profile. 259 // Delete all the shortcuts for an entire profile.
252 // This is executed on the FILE thread. 260 // This is executed on the FILE thread.
253 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); 261 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
254 262
255 // Sanitizes |name| and returns a version of it that is safe to use as an 263 // Sanitizes |name| and returns a version of it that is safe to use as an
256 // on-disk file name . 264 // on-disk file name .
257 base::FilePath GetSanitizedFileName(const base::string16& name); 265 base::FilePath GetSanitizedFileName(const base::string16& name);
258 266
259 } // namespace internals 267 } // namespace internals
260 268
261 } // namespace web_app 269 } // namespace web_app
262 270
263 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 271 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/update_shortcut_worker_win.h ('k') | chrome/browser/web_applications/web_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698