Skip to content

Commit

Permalink
Moved Windows-specific functions to shell_integration_win.h
Browse files Browse the repository at this point in the history
The file was recently added in another CL so it makes sense to move
everything Windows-specific there.

Review URL: https://codereview.chromium.org/1880073006

Cr-Commit-Position: refs/heads/master@{#387367}
  • Loading branch information
plmonette-zz authored and Commit bot committed Apr 14, 2016
1 parent f2eba7f commit 9e4c1a8
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 130 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/jumplist_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "chrome/browser/metrics/jumplist_metrics_win.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -277,7 +277,7 @@ JumpList::JumpList(Profile* profile)
return;

app_id_ =
shell_integration::GetChromiumModelIdForProfile(profile_->GetPath());
shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath());
icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname);

scoped_refptr<history::TopSites> top_sites =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_shortcut_manager.h"
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/product.h"
Expand Down Expand Up @@ -143,7 +143,7 @@ class ProfileShortcutManagerTest : public testing::Test {

base::win::ShortcutProperties expected_properties;
expected_properties.set_app_id(
shell_integration::GetChromiumModelIdForProfile(profile_path));
shell_integration::win::GetChromiumModelIdForProfile(profile_path));
expected_properties.set_target(GetExePath());
expected_properties.set_description(GetDistribution()->GetAppDescription());
expected_properties.set_dual_mode(false);
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/profiles/profile_shortcut_manager_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/chromium_strings.h"
Expand Down Expand Up @@ -542,8 +542,8 @@ void CreateOrUpdateDesktopShortcutsAndIconForProfile(
properties.set_arguments(base::string16());
}

properties.set_app_id(
shell_integration::GetChromiumModelIdForProfile(params.profile_path));
properties.set_app_id(shell_integration::win::GetChromiumModelIdForProfile(
params.profile_path));

ShellUtil::ShortcutOperation operation =
ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING;
Expand Down
37 changes: 0 additions & 37 deletions chrome/browser/shell_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,43 +113,6 @@ base::CommandLine CommandLineArgsForLauncher(
void AppendProfileArgs(const base::FilePath& profile_path,
base::CommandLine* command_line);

#if defined(OS_WIN)
// Generates an application user model ID (AppUserModelId) for a given app
// name and profile path. The returned app id is in the format of
// "|app_name|[.<profile_id>]". "profile_id" is appended when user override
// the default value.
// Note: If the app has an installation specific suffix (e.g. on user-level
// Chrome installs), |app_name| should already be suffixed, this method will
// then further suffix it with the profile id as described above.
base::string16 GetAppModelIdForProfile(const base::string16& app_name,
const base::FilePath& profile_path);

// Generates an application user model ID (AppUserModelId) for Chromium by
// calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
base::string16 GetChromiumModelIdForProfile(const base::FilePath& profile_path);

// Get the AppUserModelId for the App List, for the profile in |profile_path|.
base::string16 GetAppListAppModelIdForProfile(
const base::FilePath& profile_path);

// Migrates existing chrome taskbar pins by tagging them with correct app id.
// see http://crbug.com/28104
void MigrateTaskbarPins();

// Migrates all shortcuts in |path| which point to |chrome_exe| such that they
// have the appropriate AppUserModelId. Also clears the legacy dual_mode
// property from shortcuts with the default chrome app id.
// Returns the number of shortcuts migrated.
// This method should not be called prior to Windows 7.
// This method is only public for the sake of tests and shouldn't be called
// externally otherwise.
int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
const base::FilePath& path);

// Returns the path to the Start Menu shortcut for the given Chrome.
base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe);
#endif // defined(OS_WIN)

#if !defined(OS_WIN)
// TODO(calamity): replace with
// BrowserDistribution::GetStartMenuShortcutSubfolder() once
Expand Down
118 changes: 59 additions & 59 deletions chrome/browser/shell_integration_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ base::string16 GetExpectedAppId(const base::CommandLine& command_line,
}
DCHECK(!app_name.empty());

return GetAppModelIdForProfile(app_name, profile_path);
return win::GetAppModelIdForProfile(app_name, profile_path);
}

void MigrateTaskbarPinsCallback() {
Expand All @@ -160,7 +160,7 @@ void MigrateTaskbarPinsCallback() {
return;
}

MigrateShortcutsInPathInternal(chrome_exe, pins_path);
win::MigrateShortcutsInPathInternal(chrome_exe, pins_path);
}

// Windows 8 introduced a new protocol->executable binding system which cannot
Expand Down Expand Up @@ -452,6 +452,63 @@ DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) {
base::UTF8ToUTF16(protocol)));
}

namespace win {

bool SetAsDefaultBrowserUsingIntentPicker() {
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
return false;
}

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) {
LOG(ERROR) << "Failed to launch the set-default-browser Windows UI.";
return false;
}

VLOG(1) << "Set-default-browser Windows UI completed.";
return true;
}

void SetAsDefaultBrowserUsingSystemSettings(
const base::Closure& on_finished_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);

base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
on_finished_callback.Run();
return;
}

// The helper manages its own lifetime.
static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr};
OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback);

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe);
}

bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) {
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
return false;
}

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
base::string16 wprotocol(base::UTF8ToUTF16(protocol));
if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
wprotocol)) {
LOG(ERROR) << "Failed to launch the set-default-client Windows UI.";
return false;
}

VLOG(1) << "Set-default-client Windows UI completed.";
return true;
}

base::string16 GetAppModelIdForProfile(const base::string16& app_name,
const base::FilePath& profile_path) {
std::vector<base::string16> components;
Expand Down Expand Up @@ -632,63 +689,6 @@ base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe) {
return base::FilePath();
}

namespace win {

bool SetAsDefaultBrowserUsingIntentPicker() {
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
return false;
}

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) {
LOG(ERROR) << "Failed to launch the set-default-browser Windows UI.";
return false;
}

VLOG(1) << "Set-default-browser Windows UI completed.";
return true;
}

void SetAsDefaultBrowserUsingSystemSettings(
const base::Closure& on_finished_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);

base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
on_finished_callback.Run();
return;
}

// The helper manages its own lifetime.
static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr};
OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback);

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe);
}

bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) {
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED() << "Error getting app exe path";
return false;
}

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
base::string16 wprotocol(base::UTF8ToUTF16(protocol));
if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
wprotocol)) {
LOG(ERROR) << "Failed to launch the set-default-client Windows UI.";
return false;
}

VLOG(1) << "Set-default-client Windows UI completed.";
return true;
}

} // namespace win

} // namespace shell_integration
37 changes: 37 additions & 0 deletions chrome/browser/shell_integration_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <string>

#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"

namespace shell_integration {
namespace win {
Expand All @@ -34,6 +36,41 @@ void SetAsDefaultBrowserUsingSystemSettings(
// dialog will be shown and this method returns true.
bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol);

// Generates an application user model ID (AppUserModelId) for a given app
// name and profile path. The returned app id is in the format of
// "|app_name|[.<profile_id>]". "profile_id" is appended when user override
// the default value.
// Note: If the app has an installation specific suffix (e.g. on user-level
// Chrome installs), |app_name| should already be suffixed, this method will
// then further suffix it with the profile id as described above.
base::string16 GetAppModelIdForProfile(const base::string16& app_name,
const base::FilePath& profile_path);

// Generates an application user model ID (AppUserModelId) for Chromium by
// calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
base::string16 GetChromiumModelIdForProfile(const base::FilePath& profile_path);

// Get the AppUserModelId for the App List, for the profile in |profile_path|.
base::string16 GetAppListAppModelIdForProfile(
const base::FilePath& profile_path);

// Migrates existing chrome taskbar pins by tagging them with correct app id.
// see http://crbug.com/28104
void MigrateTaskbarPins();

// Migrates all shortcuts in |path| which point to |chrome_exe| such that they
// have the appropriate AppUserModelId. Also clears the legacy dual_mode
// property from shortcuts with the default chrome app id.
// Returns the number of shortcuts migrated.
// This method should not be called prior to Windows 7.
// This method is only public for the sake of tests and shouldn't be called
// externally otherwise.
int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
const base::FilePath& path);

// Returns the path to the Start Menu shortcut for the given Chrome.
base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe);

} // namespace win
} // namespace shell_integration

Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/shell_integration_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"

#include <stddef.h>

Expand All @@ -28,6 +28,7 @@
#include "testing/gtest/include/gtest/gtest.h"

namespace shell_integration {
namespace win {

namespace {

Expand Down Expand Up @@ -345,4 +346,5 @@ TEST(ShellIntegrationWinTest, GetAppListAppModelIdForProfileTest) {
GetAppListAppModelIdForProfile(profile_path));
}

} // namespace win
} // namespace shell_integration
3 changes: 2 additions & 1 deletion chrome/browser/ui/startup/startup_browser_creator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#include "base/win/windows_version.h"
#include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/shell_integration_win.h"
#include "components/search_engines/desktop_search_redirection_infobar_delegate.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
Expand Down Expand Up @@ -385,7 +386,7 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile,
// Active Setup versioning and on OS upgrades) instead of every startup.
// http://crbug.com/577697
if (process_startup)
shell_integration::MigrateTaskbarPins();
shell_integration::win::MigrateTaskbarPins();
#endif // defined(OS_WIN)

return true;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/app_list/win/app_list_service_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
#include "chrome/browser/ui/views/app_list/win/activation_tracker_win.h"
Expand Down Expand Up @@ -115,7 +115,7 @@ base::string16 GetAppModelId() {
command_line->GetSwitchValuePath(switches::kUserDataDir).AppendASCII(
chrome::kInitialProfile);
}
return shell_integration::GetAppListAppModelIdForProfile(
return shell_integration::win::GetAppListAppModelIdForProfile(
initial_profile_path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/browser/ui/views/apps/app_window_desktop_native_widget_aura_win.h"
#include "chrome/browser/ui/views/apps/glass_app_window_frame_view_win.h"
#include "chrome/browser/web_applications/web_app.h"
Expand Down Expand Up @@ -73,7 +73,7 @@ void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow(
HWND hwnd = GetNativeAppWindowHWND();
Profile* profile =
Profile::FromBrowserContext(app_window()->browser_context());
app_model_id_ = shell_integration::GetAppModelIdForProfile(
app_model_id_ = shell_integration::win::GetAppModelIdForProfile(
app_name_wide, profile->GetPath());
ui::win::SetAppIdForWindow(app_model_id_, hwnd);
web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_win.h"
Expand Down Expand Up @@ -51,9 +51,10 @@ void BrowserWindowPropertyManager::UpdateWindowProperties() {
// name. See http://crbug.com/7028.
base::string16 app_id =
browser->is_app()
? shell_integration::GetAppModelIdForProfile(
? shell_integration::win::GetAppModelIdForProfile(
base::UTF8ToWide(browser->app_name()), profile->GetPath())
: shell_integration::GetChromiumModelIdForProfile(profile->GetPath());
: shell_integration::win::GetChromiumModelIdForProfile(
profile->GetPath());
base::FilePath icon_path;
base::string16 command_line_string;
base::string16 pinned_name;
Expand Down
Loading

0 comments on commit 9e4c1a8

Please sign in to comment.