Index: chrome/browser/web_applications/update_relaunch_details_worker_win.cc |
diff --git a/chrome/browser/web_applications/update_relaunch_details_worker_win.cc b/chrome/browser/web_applications/update_relaunch_details_worker_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..32176e0f460b490d3d0c47ad86ad4c068c2ac48f |
--- /dev/null |
+++ b/chrome/browser/web_applications/update_relaunch_details_worker_win.cc |
@@ -0,0 +1,103 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/web_applications/update_relaunch_details_worker_win.h" |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/command_line.h" |
+#include "base/file_util.h" |
+#include "base/path_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/web_applications/web_app.h" |
+#include "chrome/browser/web_applications/web_app_win.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "ui/base/win/shell.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace web_app { |
+ |
+UpdateRelaunchDetailsWorker::UpdateRelaunchDetailsWorker( |
+ Profile* profile, |
+ const extensions::Extension* extension, |
+ HWND hwnd) |
+ : profile_(profile), extension_(extension), hwnd_(hwnd) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+} |
+ |
+UpdateRelaunchDetailsWorker::~UpdateRelaunchDetailsWorker() {} |
+ |
+void UpdateRelaunchDetailsWorker::Run() { |
+ web_app::UpdateShortcutInfoAndIconForApp( |
+ 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
|
+ profile_, |
+ base::Bind(&UpdateRelaunchDetailsWorker::OnShortcutInfoLoaded, |
+ base::Unretained(this))); |
+} |
+ |
+void UpdateRelaunchDetailsWorker::OnShortcutInfoLoaded( |
+ const ShellIntegration::ShortcutInfo& shortcut_info) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ |
+ // Set window's icon to the one we're about to create/update in the web app |
+ // path. The icon cache will refresh on icon creation. |
+ base::FilePath web_app_path = |
+ web_app::GetWebAppDataDirectory(shortcut_info.profile_path, |
+ shortcut_info.extension_id, |
+ shortcut_info.url); |
+ base::FilePath icon_file = |
+ web_app_path.Append(web_app::internals::GetSanitizedFileName( |
+ shortcut_info.title)) |
+ .ReplaceExtension(FILE_PATH_LITERAL(".ico")); |
+ |
+ content::BrowserThread::PostBlockingPoolTask( |
+ FROM_HERE, |
+ base::Bind(&UpdateRelaunchDetailsWorker::CreateIconAndSetRelaunchDetails, |
+ base::Unretained(this), |
+ web_app_path, |
+ icon_file, |
+ shortcut_info)); |
+} |
+ |
+void UpdateRelaunchDetailsWorker::CreateIconAndSetRelaunchDetails( |
+ const base::FilePath& web_app_path, |
+ const base::FilePath& icon_file, |
+ const ShellIntegration::ShortcutInfo& shortcut_info) { |
+ DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
+ |
+ CommandLine command_line = |
+ ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
+ shortcut_info.extension_id, |
+ shortcut_info.profile_path); |
+ |
+ base::FilePath chrome_exe; |
+ if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ command_line.SetProgram(chrome_exe); |
+ ui::win::SetRelaunchDetailsForWindow( |
+ command_line.GetCommandLineString(), shortcut_info.title, hwnd_); |
+ |
+ if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) { |
+ return; |
+ } |
+ |
+ ui::win::SetAppIconForWindow(icon_file.value(), hwnd_); |
+ web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&UpdateRelaunchDetailsWorker::DeleteMeOnUIThread, |
+ base::Unretained(this))); |
+} |
+ |
+void UpdateRelaunchDetailsWorker::DeleteMeOnUIThread() { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ delete this; |
+} |
+ |
+} // namespace web_app |