From 124901f5b506c98e87391e81f73f280e21708614 Mon Sep 17 00:00:00 2001 From: "calamity@chromium.org" Date: Wed, 27 Mar 2013 14:42:10 +0000 Subject: Move v2 app pinning to correct thread DCHECK was being thrown by ShellIntegration::CommandLineArgsForLauncher when --user-data-dir flag was present. Added a thread restriction check to ShellIntegration::CommandLineArgsForLauncher so others won't make the same mistake. BUG=224065 Review URL: https://chromiumcodereview.appspot.com/13078003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190933 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/shell_integration.cc | 2 + .../ui/views/extensions/native_app_window_views.cc | 52 ++++++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc index ba67750..ff0ec58 100644 --- a/chrome/browser/shell_integration.cc +++ b/chrome/browser/shell_integration.cc @@ -10,6 +10,7 @@ #include "base/path_service.h" #include "base/prefs/pref_service.h" #include "base/string_util.h" +#include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/policy/policy_path_parser.h" #include "chrome/common/chrome_paths.h" @@ -61,6 +62,7 @@ CommandLine ShellIntegration::CommandLineArgsForLauncher( const GURL& url, const std::string& extension_app_id, const base::FilePath& profile_path) { + base::ThreadRestrictions::AssertIOAllowed(); const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); CommandLine new_cmd_line(CommandLine::NO_PROGRAM); diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.cc b/chrome/browser/ui/views/extensions/native_app_window_views.cc index cdc44aa..cdd6d92 100644 --- a/chrome/browser/ui/views/extensions/native_app_window_views.cc +++ b/chrome/browser/ui/views/extensions/native_app_window_views.cc @@ -75,15 +75,37 @@ const std::map& GetAcceleratorTable() { } #if defined(OS_WIN) -void CreateIconForApp(const base::FilePath web_app_path, - const base::FilePath icon_file, - const SkBitmap& image) { +void CreateIconAndSetRelaunchDetails( + const base::FilePath web_app_path, + const base::FilePath icon_file, + const ShellIntegration::ShortcutInfo& shortcut_info, + const HWND hwnd) { DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); + + // Set the relaunch data so "Pin this program to taskbar" has the app's + // information. + CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher( + shortcut_info.url, + shortcut_info.extension_id, + shortcut_info.profile_path); + + // TODO(benwells): Change this to use app_host.exe. + base::FilePath chrome_exe; + if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { + NOTREACHED(); + return; + } + command_line.SetProgram(CommandLine::ForCurrentProcess()->GetProgram()); + ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), + shortcut_info.title, hwnd); + if (!file_util::PathExists(web_app_path) && !file_util::CreateDirectory(web_app_path)) { return; } - web_app::internals::CheckAndSaveIcon(icon_file, image); + ui::win::SetAppIconForWindow(icon_file.value(), hwnd); + web_app::internals::CheckAndSaveIcon(icon_file, + *shortcut_info.favicon.ToSkBitmap()); } #endif @@ -187,29 +209,11 @@ void NativeAppWindowViews::OnShortcutInfoLoaded( base::FilePath icon_file = web_app_path .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) .ReplaceExtension(FILE_PATH_LITERAL(".ico")); - ui::win::SetAppIconForWindow(icon_file.value(), hwnd); - - // Set the relaunch data so "Pin this program to taskbar" has the app's - // information. - CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher( - shortcut_info.url, - shortcut_info.extension_id, - shortcut_info.profile_path); - - // TODO(benwells): Change this to use app_host.exe. - base::FilePath chrome_exe; - if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { - NOTREACHED(); - return; - } - command_line.SetProgram(CommandLine::ForCurrentProcess()->GetProgram()); - ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), - shortcut_info.title, hwnd); content::BrowserThread::PostBlockingPoolTask( FROM_HERE, - base::Bind(&CreateIconForApp, web_app_path, icon_file, - *shortcut_info.favicon.ToSkBitmap())); + base::Bind(&CreateIconAndSetRelaunchDetails, + web_app_path, icon_file, shortcut_info, hwnd)); } HWND NativeAppWindowViews::GetNativeAppWindowHWND() const { -- cgit v1.1