Commit 5eec1b65 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

MacPWAs: Re-create app shims when arch changes

In crbug.com/353047, we encountered the problem where Chrome
would upgrade itself from 32-bit to 64-bit, but app shims
would be stuck on 32-bit. A mechanism was added to upgrade
the shims "when needed", based on a  kAppShortcutsVersion local
preference. This number has been incremented several times for
various incompatibilities.

Add a separate kAppShortcutsArch preference which saves the
architecture that apps have been being created in. Whenever
this does not match base::SysInfo::OperatingSystemArchitecture,
re-create all shims.

This will fix the situation whereby a user data dir, including
all of its local prefs, is copied from an Intel mac to an ARM
mac.

A few caveats:
- This will only re-create PWA shims. Legacy apps will need to
  be re-launched from Chrome.
- This only fixes the issue if the user launches Chrome before
  launching a PWA. The PWA shim copied from x86, if it succeeds
  in running, will start Chrome with the start URL for the PWA.

Bug: 1117599
Change-Id: I4d9e1a87e91c1d461b592b0a8250b22120368d94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444130
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813631}
parent 78d150eb
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/one_shot_event.h" #include "base/one_shot_event.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
...@@ -36,13 +37,23 @@ using extensions::Extension; ...@@ -36,13 +37,23 @@ using extensions::Extension;
namespace { namespace {
#if defined(OS_MAC)
// This version number is stored in local prefs to check whether app shortcuts // This version number is stored in local prefs to check whether app shortcuts
// need to be recreated. This might happen when we change various aspects of app // need to be recreated. This might happen when we change various aspects of app
// shortcuts like command-line flags or associated icons, binaries, etc. // shortcuts like command-line flags or associated icons, binaries, etc.
#if defined(OS_MAC)
const int kCurrentAppShortcutsVersion = APP_SHIM_VERSION_NUMBER; const int kCurrentAppShortcutsVersion = APP_SHIM_VERSION_NUMBER;
// The architecture that was last used to create app shortcuts for this user
// directory.
std::string CurrentAppShortcutsArch() {
return base::SysInfo::OperatingSystemArchitecture();
}
#else #else
// Non-mac platforms do not update shortcuts.
const int kCurrentAppShortcutsVersion = 0; const int kCurrentAppShortcutsVersion = 0;
std::string CurrentAppShortcutsArch() {
return "";
}
#endif #endif
// Delay in seconds before running UpdateShortcutsForAllApps. // Delay in seconds before running UpdateShortcutsForAllApps.
...@@ -75,6 +86,7 @@ void AppShortcutManager::RegisterProfilePrefs( ...@@ -75,6 +86,7 @@ void AppShortcutManager::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
// Indicates whether app shortcuts have been created. // Indicates whether app shortcuts have been created.
registry->RegisterIntegerPref(prefs::kAppShortcutsVersion, 0); registry->RegisterIntegerPref(prefs::kAppShortcutsVersion, 0);
registry->RegisterStringPref(prefs::kAppShortcutsArch, "");
} }
AppShortcutManager::AppShortcutManager(Profile* profile) AppShortcutManager::AppShortcutManager(Profile* profile)
...@@ -169,6 +181,8 @@ void AppShortcutManager::UpdateShortcutsForAllAppsNow() { ...@@ -169,6 +181,8 @@ void AppShortcutManager::UpdateShortcutsForAllAppsNow() {
void AppShortcutManager::SetCurrentAppShortcutsVersion() { void AppShortcutManager::SetCurrentAppShortcutsVersion() {
profile_->GetPrefs()->SetInteger(prefs::kAppShortcutsVersion, profile_->GetPrefs()->SetInteger(prefs::kAppShortcutsVersion,
kCurrentAppShortcutsVersion); kCurrentAppShortcutsVersion);
profile_->GetPrefs()->SetString(prefs::kAppShortcutsArch,
CurrentAppShortcutsArch());
} }
void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() {
...@@ -179,8 +193,13 @@ void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { ...@@ -179,8 +193,13 @@ void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() {
int last_version = int last_version =
profile_->GetPrefs()->GetInteger(prefs::kAppShortcutsVersion); profile_->GetPrefs()->GetInteger(prefs::kAppShortcutsVersion);
if (last_version >= kCurrentAppShortcutsVersion) std::string last_arch =
profile_->GetPrefs()->GetString(prefs::kAppShortcutsArch);
if (last_version == kCurrentAppShortcutsVersion &&
last_arch == CurrentAppShortcutsArch()) {
return; return;
}
content::GetUIThreadTaskRunner({})->PostDelayedTask( content::GetUIThreadTaskRunner({})->PostDelayedTask(
FROM_HERE, FROM_HERE,
......
...@@ -2602,6 +2602,12 @@ const char kAppListLocalState[] = "app_list.local_state"; ...@@ -2602,6 +2602,12 @@ const char kAppListLocalState[] = "app_list.local_state";
// Increasing this causes all app shortcuts to be recreated. // Increasing this causes all app shortcuts to be recreated.
const char kAppShortcutsVersion[] = "apps.shortcuts_version"; const char kAppShortcutsVersion[] = "apps.shortcuts_version";
// A string indicating the architecture in which app shortcuts have been
// created. If this changes (e.g, due to migrating one's home directory
// from an Intel mac to an ARM mac), then this will cause all shortcuts to be
// re-created.
const char kAppShortcutsArch[] = "apps.shortcuts_arch";
// A string pref for storing the salt used to compute the pepper device ID. // A string pref for storing the salt used to compute the pepper device ID.
const char kDRMSalt[] = "settings.privacy.drm_salt"; const char kDRMSalt[] = "settings.privacy.drm_salt";
// A boolean pref that enables the (private) pepper GetDeviceID() call and // A boolean pref that enables the (private) pepper GetDeviceID() call and
......
...@@ -873,6 +873,7 @@ extern const char kAppListLocalState[]; ...@@ -873,6 +873,7 @@ extern const char kAppListLocalState[];
#endif #endif
extern const char kAppShortcutsVersion[]; extern const char kAppShortcutsVersion[];
extern const char kAppShortcutsArch[];
extern const char kDRMSalt[]; extern const char kDRMSalt[];
extern const char kEnableDRM[]; extern const char kEnableDRM[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment