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

Side by Side Diff: chrome/browser/ui/web_applications/web_app_ui.cc

Issue 10914109: Refactoring and tests for the highly undertested file_util::CreateOrUpdateShortcutLink() method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: namespace s/Win/win Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/shell_integration_win.cc ('k') | chrome/browser/web_applications/web_app_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/web_applications/web_app_ui.h" 5 #include "chrome/browser/ui/web_applications/web_app_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/win/windows_version.h"
14 #include "chrome/browser/extensions/tab_helper.h" 13 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h" 14 #include "chrome/browser/favicon/favicon_tab_helper.h"
16 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
18 #include "chrome/browser/web_applications/web_app.h" 17 #include "chrome/browser/web_applications/web_app.h"
19 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 25
27 #if defined(OS_POSIX) && !defined(OS_MACOSX) 26 #if defined(OS_POSIX) && !defined(OS_MACOSX)
28 #include "base/environment.h" 27 #include "base/environment.h"
29 #endif 28 #endif
30 29
30 #if defined(OS_WIN)
31 #include "base/win/shortcut.h"
32 #include "base/win/windows_version.h"
33 #endif
34
31 using content::BrowserThread; 35 using content::BrowserThread;
32 using content::NavigationController; 36 using content::NavigationController;
33 using content::WebContents; 37 using content::WebContents;
34 38
35 namespace { 39 namespace {
36 40
37 #if defined(OS_WIN) 41 #if defined(OS_WIN)
38 // UpdateShortcutWorker holds all context data needed for update shortcut. 42 // UpdateShortcutWorker holds all context data needed for update shortcut.
39 // It schedules a pre-update check to find all shortcuts that needs to be 43 // It schedules a pre-update check to find all shortcuts that needs to be
40 // updated. If there are such shortcuts, it schedules icon download and 44 // updated. If there are such shortcuts, it schedules icon download and
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // Generates app id from web app url and profile path. 255 // Generates app id from web app url and profile path.
252 string16 app_id = ShellIntegration::GetAppModelIdForProfile( 256 string16 app_id = ShellIntegration::GetAppModelIdForProfile(
253 UTF8ToWide(web_app::GenerateApplicationNameFromURL(shortcut_info_.url)), 257 UTF8ToWide(web_app::GenerateApplicationNameFromURL(shortcut_info_.url)),
254 profile_path_); 258 profile_path_);
255 259
256 // Sanitize description 260 // Sanitize description
257 if (shortcut_info_.description.length() >= MAX_PATH) 261 if (shortcut_info_.description.length() >= MAX_PATH)
258 shortcut_info_.description.resize(MAX_PATH - 1); 262 shortcut_info_.description.resize(MAX_PATH - 1);
259 263
260 for (size_t i = 0; i < shortcut_files_.size(); ++i) { 264 for (size_t i = 0; i < shortcut_files_.size(); ++i) {
261 file_util::CreateOrUpdateShortcutLink( 265 base::win::ShortcutProperties shortcut_properties;
262 NULL, 266 shortcut_properties.set_target(shortcut_files_[i]);
263 shortcut_files_[i].value().c_str(), 267 shortcut_properties.set_description(shortcut_info_.description);
264 NULL, 268 shortcut_properties.set_icon(icon_file, 0);
265 NULL, 269 shortcut_properties.set_app_id(app_id);
266 shortcut_info_.description.c_str(), 270 base::win::CreateOrUpdateShortcutLink(
267 icon_file.value().c_str(), 271 shortcut_files_[i], shortcut_properties,
268 0, 272 base::win::SHORTCUT_UPDATE_EXISTING);
269 app_id.c_str(),
270 file_util::SHORTCUT_NO_OPTIONS);
271 } 273 }
272 } 274 }
273 275
274 OnShortcutsUpdated(true); 276 OnShortcutsUpdated(true);
275 } 277 }
276 278
277 void UpdateShortcutWorker::OnShortcutsUpdated(bool) { 279 void UpdateShortcutWorker::OnShortcutsUpdated(bool) {
278 DeleteMe(); // We are done. 280 DeleteMe(); // We are done.
279 } 281 }
280 282
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 323
322 void UpdateShortcutForTabContents(TabContents* tab_contents) { 324 void UpdateShortcutForTabContents(TabContents* tab_contents) {
323 #if defined(OS_WIN) 325 #if defined(OS_WIN)
324 // UpdateShortcutWorker will delete itself when it's done. 326 // UpdateShortcutWorker will delete itself when it's done.
325 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); 327 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents);
326 worker->Run(); 328 worker->Run();
327 #endif // defined(OS_WIN) 329 #endif // defined(OS_WIN)
328 } 330 }
329 331
330 } // namespace web_app 332 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_win.cc ('k') | chrome/browser/web_applications/web_app_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698