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

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

Issue 258243002: Support "Pin to taskbar" for hosted app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/web_applications/update_relaunch_details_worker_win.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/file_util.h"
11 #include "base/path_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/web_applications/web_app.h"
14 #include "chrome/browser/web_applications/web_app_win.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "ui/base/win/shell.h"
17
18 using content::BrowserThread;
19
20 namespace web_app {
21
22 UpdateRelaunchDetailsWorker::UpdateRelaunchDetailsWorker(
23 Profile* profile,
24 const extensions::Extension* extension,
25 HWND hwnd)
26 : profile_(profile), extension_(extension), hwnd_(hwnd) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28 }
29
30 UpdateRelaunchDetailsWorker::~UpdateRelaunchDetailsWorker() {}
31
32 void UpdateRelaunchDetailsWorker::Run() {
33 web_app::UpdateShortcutInfoAndIconForApp(
34 extension_,
jackhou1 2014/04/29 08:50:18 Do you really need a worker object for this code?
calamity 2014/05/19 06:11:54 Good point. HWND doesn't need to be safe????
jackhou1 2014/05/22 03:43:53 I mean that accessing a member of UpdateRelaunchDe
35 profile_,
36 base::Bind(&UpdateRelaunchDetailsWorker::OnShortcutInfoLoaded,
37 base::Unretained(this)));
38 }
39
40 void UpdateRelaunchDetailsWorker::OnShortcutInfoLoaded(
41 const ShellIntegration::ShortcutInfo& shortcut_info) {
42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
43
44 // Set window's icon to the one we're about to create/update in the web app
45 // path. The icon cache will refresh on icon creation.
46 base::FilePath web_app_path =
47 web_app::GetWebAppDataDirectory(shortcut_info.profile_path,
48 shortcut_info.extension_id,
49 shortcut_info.url);
50 base::FilePath icon_file =
51 web_app_path.Append(web_app::internals::GetSanitizedFileName(
52 shortcut_info.title))
53 .ReplaceExtension(FILE_PATH_LITERAL(".ico"));
54
55 content::BrowserThread::PostBlockingPoolTask(
56 FROM_HERE,
57 base::Bind(&UpdateRelaunchDetailsWorker::CreateIconAndSetRelaunchDetails,
58 base::Unretained(this),
59 web_app_path,
60 icon_file,
61 shortcut_info));
62 }
63
64 void UpdateRelaunchDetailsWorker::CreateIconAndSetRelaunchDetails(
65 const base::FilePath& web_app_path,
66 const base::FilePath& icon_file,
67 const ShellIntegration::ShortcutInfo& shortcut_info) {
68 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
69
70 CommandLine command_line =
71 ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url,
72 shortcut_info.extension_id,
73 shortcut_info.profile_path);
74
75 base::FilePath chrome_exe;
76 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
77 NOTREACHED();
78 return;
79 }
80 command_line.SetProgram(chrome_exe);
81 ui::win::SetRelaunchDetailsForWindow(
82 command_line.GetCommandLineString(), shortcut_info.title, hwnd_);
83
84 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) {
85 return;
86 }
87
88 ui::win::SetAppIconForWindow(icon_file.value(), hwnd_);
89 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
90
91 BrowserThread::PostTask(
92 BrowserThread::UI,
93 FROM_HERE,
94 base::Bind(&UpdateRelaunchDetailsWorker::DeleteMeOnUIThread,
95 base::Unretained(this)));
96 }
97
98 void UpdateRelaunchDetailsWorker::DeleteMeOnUIThread() {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100 delete this;
101 }
102
103 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698