Commit 9ec8c701 authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

Refactor GetBrowserModelId so it doesn't call BuildAppModelId.

GetChromiumModelIdForProfile passes the result of GetBrowserModelId to
BuildAppModelId, but GetBrowserModelId calls BuildAppModelId.
Conceptually, it's cleaner if BuildAppModelId is always the last step in
computing an app model id. To do this, we have to extract out a method
to shorten an app model id component, so that GetBrowserModelId can use
it, instead of using BuildAppModelId.

Change-Id: I633c41b83bfc14c52bb4b5e364bce8dfc68cdde2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304162
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789976}
parent 379b25ac
...@@ -1482,6 +1482,15 @@ bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, ...@@ -1482,6 +1482,15 @@ bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
return true; return true;
} }
// Return a shortened version of |component|. Cut in the middle to try
// to avoid losing the unique parts of |component| (which are usually
// at the beginning or end for things like usernames and paths).
base::string16 ShortenAppModelIdComponent(const base::string16& component,
int desired_length) {
return component.substr(0, desired_length / 2) +
component.substr(component.length() - ((desired_length + 1) / 2));
}
} // namespace } // namespace
const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon";
...@@ -1856,11 +1865,10 @@ base::string16 ShellUtil::GetBrowserModelId(bool is_per_user_install) { ...@@ -1856,11 +1865,10 @@ base::string16 ShellUtil::GetBrowserModelId(bool is_per_user_install) {
} else if (is_per_user_install && !GetUserSpecificRegistrySuffix(&suffix)) { } else if (is_per_user_install && !GetUserSpecificRegistrySuffix(&suffix)) {
NOTREACHED(); NOTREACHED();
} }
// There is only one component (i.e. the suffixed appid) in this case, but it app_id.append(suffix);
// is still necessary to go through the appid constructor to make sure the if (app_id.length() <= installer::kMaxAppModelIdLength)
// returned appid is truncated if necessary. return app_id;
std::vector<base::string16> components(1, app_id.append(suffix)); return ShortenAppModelIdComponent(app_id, installer::kMaxAppModelIdLength);
return BuildAppModelId(components);
} }
base::string16 ShellUtil::BuildAppModelId( base::string16 ShellUtil::BuildAppModelId(
...@@ -1890,13 +1898,8 @@ base::string16 ShellUtil::BuildAppModelId( ...@@ -1890,13 +1898,8 @@ base::string16 ShellUtil::BuildAppModelId(
const base::string16& component = *it; const base::string16& component = *it;
DCHECK(!component.empty()); DCHECK(!component.empty());
if (component.length() > max_component_length) { if (component.length() > max_component_length) {
// Append a shortened version of this component. Cut in the middle to try app_id.append(
// to avoid losing the unique parts of this component (which are usually ShortenAppModelIdComponent(component, max_component_length));
// at the beginning or end for things like usernames and paths).
app_id.append(component, 0, max_component_length / 2);
app_id.append(component,
component.length() - ((max_component_length + 1) / 2),
base::string16::npos);
} else { } else {
app_id.append(component); app_id.append(component);
} }
......
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