diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 02:59:38 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 02:59:38 +0000 |
commit | 3a3e72c985805759875bb9abfe3547171e05eb85 (patch) | |
tree | 40d4f2d981d01f28d8018a00f1ad1b033cd48e94 /chrome | |
parent | 2fca6001b3253cae81487b257e7f465b68da7c5a (diff) | |
download | chromium_src-3a3e72c985805759875bb9abfe3547171e05eb85.zip chromium_src-3a3e72c985805759875bb9abfe3547171e05eb85.tar.gz chromium_src-3a3e72c985805759875bb9abfe3547171e05eb85.tar.bz2 |
base::Bind: Convert the following files:
* template_url_service_test_util.cc.
* shell_integration_win.cc.
BUG=none
TEST=none
R=groby@chromium.org
Review URL: http://codereview.chromium.org/8726024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/search_engines/template_url_service_test_util.cc | 24 | ||||
-rw-r--r-- | chrome/browser/shell_integration_win.cc | 244 |
2 files changed, 110 insertions, 158 deletions
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc index a7a3390..098e50c 100644 --- a/chrome/browser/search_engines/template_url_service_test_util.cc +++ b/chrome/browser/search_engines/template_url_service_test_util.cc @@ -4,6 +4,7 @@ #include "chrome/browser/search_engines/template_url_service_test_util.h" +#include "base/bind.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/scoped_temp_dir.h" @@ -21,30 +22,21 @@ using content::BrowserThread; namespace { -// A Task used to coordinate when the database has finished processing +// A callback used to coordinate when the database has finished processing // requests. See note in BlockTillServiceProcessesRequests for details. // -// When Run() schedules a QuitTask on the message loop it was created with. -class QuitTask2 : public Task { - public: - QuitTask2() : main_loop_(MessageLoop::current()) {} - - virtual void Run() { - main_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - } - - private: - MessageLoop* main_loop_; -}; +// Schedules a QuitClosure on the message loop it was created with. +void QuitCallback(MessageLoop* message_loop) { + message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); +} // Blocks the caller until thread has finished servicing all pending // requests. static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) { // Schedule a task on the thread that is processed after all // pending requests on the thread. - BrowserThread::PostTask(identifier, FROM_HERE, new QuitTask2()); - // Run the current message loop. QuitTask2, when run, invokes Quit, - // which unblocks this. + BrowserThread::PostTask(identifier, FROM_HERE, + base::Bind(&QuitCallback, MessageLoop::current())); MessageLoop::current()->Run(); } diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc index 15baa3e..762cfa6 100644 --- a/chrome/browser/shell_integration_win.cc +++ b/chrome/browser/shell_integration_win.cc @@ -9,6 +9,7 @@ #include <propkey.h> #include <propvarutil.h> +#include "base/bind.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/message_loop.h" @@ -16,7 +17,6 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" -#include "base/task.h" #include "base/utf_string_conversions.h" #include "base/win/registry.h" #include "base/win/scoped_comptr.h" @@ -76,92 +76,88 @@ std::wstring GetProfileIdFromPath(const FilePath& profile_path) { return profile_id; } -// Migrates existing chromium shortucts for Win7. -class MigrateChromiumShortcutsTask : public Task { - public: - MigrateChromiumShortcutsTask() { } - - virtual void Run(); +bool GetShortcutAppId(IShellLink* shell_link, std::wstring* app_id) { + DCHECK(shell_link); + DCHECK(app_id); - private: - void MigrateWin7Shortcuts(); - void MigrateWin7ShortcutsInPath(const FilePath& path) const; + app_id->clear(); - // Get expected app id for given chrome shortcut. - // Returns true if the shortcut point to chrome and expected app id is - // successfully derived. - bool GetExpectedAppId(IShellLink* shell_link, - std::wstring* expected_app_id) const; + base::win::ScopedComPtr<IPropertyStore> property_store; + if (FAILED(property_store.QueryFrom(shell_link))) + return false; - // Get app id associated with given shortcut. - bool GetShortcutAppId(IShellLink* shell_link, std::wstring* app_id) const; + PROPVARIANT appid_value; + PropVariantInit(&appid_value); + if (FAILED(property_store->GetValue(PKEY_AppUserModel_ID, &appid_value))) + return false; - FilePath chrome_exe_; + if (appid_value.vt == VT_LPWSTR || appid_value.vt == VT_BSTR) + app_id->assign(appid_value.pwszVal); - DISALLOW_COPY_AND_ASSIGN(MigrateChromiumShortcutsTask); -}; + PropVariantClear(&appid_value); + return true; +} -void MigrateChromiumShortcutsTask::Run() { - // This should run on the file thread. - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); +// Gets expected app id for given chrome shortcut. Returns true if the shortcut +// points to chrome and expected app id is successfully derived. +bool GetExpectedAppId(const FilePath& chrome_exe, + IShellLink* shell_link, + std::wstring* expected_app_id) { + DCHECK(shell_link); + DCHECK(expected_app_id); - MigrateWin7Shortcuts(); -} + expected_app_id->clear(); -void MigrateChromiumShortcutsTask::MigrateWin7Shortcuts() { - // Get full path of chrome. - if (!PathService::Get(base::FILE_EXE, &chrome_exe_)) - return; + // Check if the shortcut points to chrome_exe. + std::wstring source; + if (FAILED(shell_link->GetPath(WriteInto(&source, MAX_PATH), MAX_PATH, NULL, + SLGP_RAWPATH)) || + lstrcmpi(chrome_exe.value().c_str(), source.c_str())) + return false; - // Locations to check for shortcuts migration. - static const struct { - int location_id; - const wchar_t* sub_dir; - } kLocations[] = { - { - base::DIR_APP_DATA, - L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar" - }, { - chrome::DIR_USER_DESKTOP, - NULL - }, { - base::DIR_START_MENU, - NULL - }, { - base::DIR_APP_DATA, - L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\StartMenu" - } - }; + std::wstring arguments; + if (FAILED(shell_link->GetArguments(WriteInto(&arguments, MAX_PATH), + MAX_PATH))) + return false; - for (int i = 0; i < arraysize(kLocations); ++i) { - FilePath path; - if (!PathService::Get(kLocations[i].location_id, &path)) { - NOTREACHED(); - continue; - } + // Get expected app id from shortcut command line. + CommandLine command_line = CommandLine::FromString(base::StringPrintf( + L"\"%ls\" %ls", source.c_str(), arguments.c_str())); - if (kLocations[i].sub_dir) - path = path.Append(kLocations[i].sub_dir); + FilePath profile_path; + if (command_line.HasSwitch(switches::kUserDataDir)) { + profile_path = + command_line.GetSwitchValuePath(switches::kUserDataDir).AppendASCII( + chrome::kInitialProfile); + } - MigrateWin7ShortcutsInPath(path); + std::wstring app_name; + if (command_line.HasSwitch(switches::kApp)) { + app_name = UTF8ToWide(web_app::GenerateApplicationNameFromURL( + GURL(command_line.GetSwitchValueASCII(switches::kApp)))); + } else if (command_line.HasSwitch(switches::kAppId)) { + app_name = UTF8ToWide(web_app::GenerateApplicationNameFromExtensionId( + command_line.GetSwitchValueASCII(switches::kAppId))); + } else { + app_name = BrowserDistribution::GetDistribution()->GetBrowserAppId(); } + + expected_app_id->assign(ShellIntegration::GetAppId(app_name, profile_path)); + return true; } -void MigrateChromiumShortcutsTask::MigrateWin7ShortcutsInPath( - const FilePath& path) const { +void MigrateWin7ShortcutsInPath( + const FilePath& chrome_exe, const FilePath& path) { // Enumerate all pinned shortcuts in the given path directly. file_util::FileEnumerator shortcuts_enum( - path, - false, // not recursive - file_util::FileEnumerator::FILES, - FILE_PATH_LITERAL("*.lnk")); + path, false, // not recursive + file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); for (FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); shortcut = shortcuts_enum.Next()) { // Load the shortcut. base::win::ScopedComPtr<IShellLink> shell_link; - if (FAILED(shell_link.CreateInstance(CLSID_ShellLink, - NULL, + if (FAILED(shell_link.CreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER))) { NOTREACHED(); return; @@ -176,7 +172,7 @@ void MigrateChromiumShortcutsTask::MigrateWin7ShortcutsInPath( // Get expected app id from shortcut. std::wstring expected_app_id; - if (!GetExpectedAppId(shell_link, &expected_app_id) || + if (!GetExpectedAppId(chrome_exe, shell_link, &expected_app_id) || expected_app_id.empty()) continue; @@ -185,93 +181,56 @@ void MigrateChromiumShortcutsTask::MigrateWin7ShortcutsInPath( GetShortcutAppId(shell_link, &existing_app_id); if (expected_app_id != existing_app_id) { - file_util::UpdateShortcutLink(NULL, - shortcut.value().c_str(), - NULL, - NULL, - NULL, - NULL, - 0, - expected_app_id.c_str()); + file_util::UpdateShortcutLink(NULL, shortcut.value().c_str(), NULL, NULL, + NULL, NULL, 0, expected_app_id.c_str()); } } } -bool MigrateChromiumShortcutsTask::GetExpectedAppId( - IShellLink* shell_link, - std::wstring* expected_app_id) const { - DCHECK(shell_link); - DCHECK(expected_app_id); - - expected_app_id->clear(); +void MigrateChromiumShortcutsCallback() { + // This should run on the file thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - // Check if the shortcut points to chrome_exe. - std::wstring source; - if (FAILED(shell_link->GetPath(WriteInto(&source, MAX_PATH), - MAX_PATH, - NULL, - SLGP_RAWPATH)) || - lstrcmpi(chrome_exe_.value().c_str(), source.c_str())) - return false; + // Get full path of chrome. + FilePath chrome_exe; + if (!PathService::Get(base::FILE_EXE, &chrome_exe)) + return; - std::wstring arguments; - if (FAILED(shell_link->GetArguments(WriteInto(&arguments, MAX_PATH), - MAX_PATH))) - return false; + // Locations to check for shortcuts migration. + static const struct { + int location_id; + const wchar_t* sub_dir; + } kLocations[] = { + { + base::DIR_APP_DATA, + L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar" + }, { + chrome::DIR_USER_DESKTOP, + NULL + }, { + base::DIR_START_MENU, + NULL + }, { + base::DIR_APP_DATA, + L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\StartMenu" + } + }; - // Get expected app id from shortcut command line. - CommandLine command_line = CommandLine::FromString(base::StringPrintf( - L"\"%ls\" %ls", source.c_str(), arguments.c_str())); + for (int i = 0; i < arraysize(kLocations); ++i) { + FilePath path; + if (!PathService::Get(kLocations[i].location_id, &path)) { + NOTREACHED(); + continue; + } - FilePath profile_path; - if (command_line.HasSwitch(switches::kUserDataDir)) { - profile_path = - command_line.GetSwitchValuePath(switches::kUserDataDir).AppendASCII( - chrome::kInitialProfile); - } + if (kLocations[i].sub_dir) + path = path.Append(kLocations[i].sub_dir); - std::wstring app_name; - if (command_line.HasSwitch(switches::kApp)) { - app_name = UTF8ToWide(web_app::GenerateApplicationNameFromURL( - GURL(command_line.GetSwitchValueASCII(switches::kApp)))); - } else if (command_line.HasSwitch(switches::kAppId)) { - app_name = UTF8ToWide(web_app::GenerateApplicationNameFromExtensionId( - command_line.GetSwitchValueASCII(switches::kAppId))); - } else { - app_name = BrowserDistribution::GetDistribution()->GetBrowserAppId(); + MigrateWin7ShortcutsInPath(chrome_exe, path); } - - expected_app_id->assign(ShellIntegration::GetAppId(app_name, profile_path)); - return true; -} - -bool MigrateChromiumShortcutsTask::GetShortcutAppId( - IShellLink* shell_link, - std::wstring* app_id) const { - DCHECK(shell_link); - DCHECK(app_id); - - app_id->clear(); - - base::win::ScopedComPtr<IPropertyStore> property_store; - if (FAILED(property_store.QueryFrom(shell_link))) - return false; - - PROPVARIANT appid_value; - PropVariantInit(&appid_value); - if (FAILED(property_store->GetValue(PKEY_AppUserModel_ID, - &appid_value))) - return false; - - if (appid_value.vt == VT_LPWSTR || - appid_value.vt == VT_BSTR) - app_id->assign(appid_value.pwszVal); - - PropVariantClear(&appid_value); - return true; } -}; +} // namespace bool ShellIntegration::CanSetAsDefaultBrowser() { return BrowserDistribution::GetDistribution()->CanSetAsDefault(); @@ -544,5 +503,6 @@ void ShellIntegration::MigrateChromiumShortcuts() { return; BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, new MigrateChromiumShortcutsTask()); + BrowserThread::FILE, FROM_HERE, + base::Bind(&MigrateChromiumShortcutsCallback)); } |