Skip to content

Commit 004905c

Browse files
wychenCommit bot
authored and
Commit bot
committed
Fix Extensions.AppLaunchSource off-by-one error
BUG=661405 Review-Url: https://codereview.chromium.org/2486453002 Cr-Commit-Position: refs/heads/master@{#432638}
1 parent 286d35b commit 004905c

File tree

4 files changed

+67
-69
lines changed

4 files changed

+67
-69
lines changed

extensions/browser/api/app_runtime/app_runtime_api.cc

+36-47
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void DispatchOnLaunchedEventImpl(
5252
app_runtime::LaunchSource source,
5353
std::unique_ptr<base::DictionaryValue> launch_data,
5454
BrowserContext* context) {
55-
UMA_HISTOGRAM_ENUMERATION(
56-
"Extensions.AppLaunchSource", source, NUM_APP_LAUNCH_SOURCES);
55+
UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchSource", source,
56+
app_runtime::LaunchSource::LAUNCH_SOURCE_LAST + 1);
5757

5858
// "Forced app mode" is true for Chrome OS kiosk mode.
5959
launch_data->SetBoolean(
@@ -76,53 +76,42 @@ void DispatchOnLaunchedEventImpl(
7676
->SetLastLaunchTime(extension_id, base::Time::Now());
7777
}
7878

79+
#define ASSERT_ENUM_EQUAL(Name) ASSERT_ENUM_EQUAL_FULL(Name, Name)
80+
81+
#define ASSERT_ENUM_EQUAL_FULL(Name, Name2) \
82+
static_assert(static_cast<int>(extensions::Name) == \
83+
static_cast<int>(app_runtime::LAUNCH_##Name2), \
84+
"The value of extensions::" #Name \
85+
" and app_runtime::LAUNCH_" #Name2 " should be the same");
86+
7987
app_runtime::LaunchSource GetLaunchSourceEnum(
8088
extensions::AppLaunchSource source) {
81-
switch (source) {
82-
case extensions::SOURCE_UNTRACKED:
83-
return app_runtime::LAUNCH_SOURCE_UNTRACKED;
84-
case extensions::SOURCE_APP_LAUNCHER:
85-
return app_runtime::LAUNCH_SOURCE_APP_LAUNCHER;
86-
case extensions::SOURCE_NEW_TAB_PAGE:
87-
return app_runtime::LAUNCH_SOURCE_NEW_TAB_PAGE;
88-
case extensions::SOURCE_RELOAD:
89-
return app_runtime::LAUNCH_SOURCE_RELOAD;
90-
case extensions::SOURCE_RESTART:
91-
return app_runtime::LAUNCH_SOURCE_RESTART;
92-
case extensions::SOURCE_LOAD_AND_LAUNCH:
93-
return app_runtime::LAUNCH_SOURCE_LOAD_AND_LAUNCH;
94-
case extensions::SOURCE_COMMAND_LINE:
95-
return app_runtime::LAUNCH_SOURCE_COMMAND_LINE;
96-
case extensions::SOURCE_FILE_HANDLER:
97-
return app_runtime::LAUNCH_SOURCE_FILE_HANDLER;
98-
case extensions::SOURCE_URL_HANDLER:
99-
return app_runtime::LAUNCH_SOURCE_URL_HANDLER;
100-
case extensions::SOURCE_SYSTEM_TRAY:
101-
return app_runtime::LAUNCH_SOURCE_SYSTEM_TRAY;
102-
case extensions::SOURCE_ABOUT_PAGE:
103-
return app_runtime::LAUNCH_SOURCE_ABOUT_PAGE;
104-
case extensions::SOURCE_KEYBOARD:
105-
return app_runtime::LAUNCH_SOURCE_KEYBOARD;
106-
case extensions::SOURCE_EXTENSIONS_PAGE:
107-
return app_runtime::LAUNCH_SOURCE_EXTENSIONS_PAGE;
108-
case extensions::SOURCE_MANAGEMENT_API:
109-
return app_runtime::LAUNCH_SOURCE_MANAGEMENT_API;
110-
case extensions::SOURCE_EPHEMERAL_APP_DEPRECATED:
111-
return app_runtime::LAUNCH_SOURCE_EPHEMERAL_APP;
112-
case extensions::SOURCE_BACKGROUND:
113-
return app_runtime::LAUNCH_SOURCE_BACKGROUND;
114-
case extensions::SOURCE_KIOSK:
115-
return app_runtime::LAUNCH_SOURCE_KIOSK;
116-
case extensions::SOURCE_CHROME_INTERNAL:
117-
return app_runtime::LAUNCH_SOURCE_CHROME_INTERNAL;
118-
case extensions::SOURCE_TEST:
119-
return app_runtime::LAUNCH_SOURCE_TEST;
120-
case extensions::SOURCE_INSTALLED_NOTIFICATION:
121-
return app_runtime::LAUNCH_SOURCE_INSTALLED_NOTIFICATION;
122-
123-
default:
124-
return app_runtime::LAUNCH_SOURCE_NONE;
125-
}
89+
ASSERT_ENUM_EQUAL(SOURCE_NONE);
90+
ASSERT_ENUM_EQUAL(SOURCE_UNTRACKED);
91+
ASSERT_ENUM_EQUAL(SOURCE_APP_LAUNCHER);
92+
ASSERT_ENUM_EQUAL(SOURCE_NEW_TAB_PAGE);
93+
ASSERT_ENUM_EQUAL(SOURCE_RELOAD);
94+
ASSERT_ENUM_EQUAL(SOURCE_RESTART);
95+
ASSERT_ENUM_EQUAL(SOURCE_LOAD_AND_LAUNCH);
96+
ASSERT_ENUM_EQUAL(SOURCE_COMMAND_LINE);
97+
ASSERT_ENUM_EQUAL(SOURCE_FILE_HANDLER);
98+
ASSERT_ENUM_EQUAL(SOURCE_URL_HANDLER);
99+
ASSERT_ENUM_EQUAL(SOURCE_SYSTEM_TRAY);
100+
ASSERT_ENUM_EQUAL(SOURCE_ABOUT_PAGE);
101+
ASSERT_ENUM_EQUAL(SOURCE_KEYBOARD);
102+
ASSERT_ENUM_EQUAL(SOURCE_EXTENSIONS_PAGE);
103+
ASSERT_ENUM_EQUAL(SOURCE_MANAGEMENT_API);
104+
ASSERT_ENUM_EQUAL_FULL(SOURCE_EPHEMERAL_APP_DEPRECATED, SOURCE_EPHEMERAL_APP);
105+
ASSERT_ENUM_EQUAL(SOURCE_BACKGROUND);
106+
ASSERT_ENUM_EQUAL(SOURCE_KIOSK);
107+
ASSERT_ENUM_EQUAL(SOURCE_CHROME_INTERNAL);
108+
ASSERT_ENUM_EQUAL(SOURCE_TEST);
109+
ASSERT_ENUM_EQUAL(SOURCE_INSTALLED_NOTIFICATION);
110+
static_assert(extensions::NUM_APP_LAUNCH_SOURCES ==
111+
app_runtime::LaunchSource::LAUNCH_SOURCE_LAST + 1,
112+
"");
113+
114+
return static_cast<app_runtime::LaunchSource>(source);
126115
}
127116

128117
} // namespace

extensions/common/api/app_runtime.idl

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ namespace app.runtime {
1616
};
1717

1818
// Enumeration of app launch sources.
19+
// This should be kept in sync with AppLaunchSource in
20+
// extensions/common/constants.h, and GetLaunchSourceEnum() in
21+
// extensions/browser/api/app_runtime/app_runtime_api.cc.
22+
// Note the enumeration is used in UMA histogram so entries
23+
// should not be re-ordered or removed.
1924
enum LaunchSource {
2025
untracked,
2126
app_launcher,

extensions/common/constants.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,14 @@ extern const uint8_t kWebstoreSignaturesPublicKey[];
117117
extern const int kWebstoreSignaturesPublicKeySize;
118118

119119
// Enumeration of possible app launch sources.
120+
// This should be kept in sync with LaunchSource in
121+
// extensions/common/api/app_runtime.idl, and GetLaunchSourceEnum() in
122+
// extensions/browser/api/app_runtime/app_runtime_api.cc.
120123
// Note the enumeration is used in UMA histogram so entries
121124
// should not be re-ordered or removed.
122125
enum AppLaunchSource {
123-
SOURCE_UNTRACKED = 0,
126+
SOURCE_NONE,
127+
SOURCE_UNTRACKED,
124128
SOURCE_APP_LAUNCHER,
125129
SOURCE_NEW_TAB_PAGE,
126130
SOURCE_RELOAD,
@@ -140,7 +144,6 @@ enum AppLaunchSource {
140144
SOURCE_CHROME_INTERNAL,
141145
SOURCE_TEST,
142146
SOURCE_INSTALLED_NOTIFICATION,
143-
144147
NUM_APP_LAUNCH_SOURCES
145148
};
146149

tools/metrics/histograms/histograms.xml

+21-20
Original file line numberDiff line numberDiff line change
@@ -74280,26 +74280,27 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
7428074280
</enum>
7428174281

7428274282
<enum name="AppLaunchSource" type="int">
74283-
<int value="0" label="SOURCE_UNTRACKED"/>
74284-
<int value="1" label="SOURCE_APP_LAUNCHER"/>
74285-
<int value="2" label="SOURCE_NEW_TAB_PAGE"/>
74286-
<int value="3" label="SOURCE_RELOAD"/>
74287-
<int value="4" label="SOURCE_RESTART"/>
74288-
<int value="5" label="SOURCE_LOAD_AND_LAUNCH"/>
74289-
<int value="6" label="SOURCE_COMMAND_LINE"/>
74290-
<int value="7" label="SOURCE_FILE_HANDLER"/>
74291-
<int value="8" label="SOURCE_URL_HANDLER"/>
74292-
<int value="9" label="SOURCE_SYSTEM_TRAY"/>
74293-
<int value="10" label="SOURCE_ABOUT_PAGE"/>
74294-
<int value="11" label="SOURCE_KEYBOARD"/>
74295-
<int value="12" label="SOURCE_EXTENSIONS_PAGE"/>
74296-
<int value="13" label="SOURCE_MANAGEMENT_API"/>
74297-
<int value="14" label="SOURCE_EPHEMERAL_APP_DEPRECATED"/>
74298-
<int value="15" label="SOURCE_BACKGROUND"/>
74299-
<int value="16" label="SOURCE_KIOSK"/>
74300-
<int value="17" label="SOURCE_CHROME_INTERNAL"/>
74301-
<int value="18" label="SOURCE_TEST"/>
74302-
<int value="19" label="SOURCE_INSTALLED_NOTIFICATION"/>
74283+
<int value="0" label="LAUNCH_SOURCE_NONE"/>
74284+
<int value="1" label="LAUNCH_SOURCE_UNTRACKED"/>
74285+
<int value="2" label="LAUNCH_SOURCE_APP_LAUNCHER"/>
74286+
<int value="3" label="LAUNCH_SOURCE_NEW_TAB_PAGE"/>
74287+
<int value="4" label="LAUNCH_SOURCE_RELOAD"/>
74288+
<int value="5" label="LAUNCH_SOURCE_RESTART"/>
74289+
<int value="6" label="LAUNCH_SOURCE_LOAD_AND_LAUNCH"/>
74290+
<int value="7" label="LAUNCH_SOURCE_COMMAND_LINE"/>
74291+
<int value="8" label="LAUNCH_SOURCE_FILE_HANDLER"/>
74292+
<int value="9" label="LAUNCH_SOURCE_URL_HANDLER"/>
74293+
<int value="10" label="LAUNCH_SOURCE_SYSTEM_TRAY"/>
74294+
<int value="11" label="LAUNCH_SOURCE_ABOUT_PAGE"/>
74295+
<int value="12" label="LAUNCH_SOURCE_KEYBOARD"/>
74296+
<int value="13" label="LAUNCH_SOURCE_EXTENSIONS_PAGE"/>
74297+
<int value="14" label="LAUNCH_SOURCE_MANAGEMENT_API"/>
74298+
<int value="15" label="LAUNCH_SOURCE_EPHEMERAL_APP"/>
74299+
<int value="16" label="LAUNCH_SOURCE_BACKGROUND"/>
74300+
<int value="17" label="LAUNCH_SOURCE_KIOSK"/>
74301+
<int value="18" label="LAUNCH_SOURCE_CHROME_INTERNAL"/>
74302+
<int value="19" label="LAUNCH_SOURCE_TEST"/>
74303+
<int value="20" label="LAUNCH_SOURCE_INSTALLED_NOTIFICATION"/>
7430374304
</enum>
7430474305

7430574306
<enum name="AppleScriptCommandEvents" type="int">

0 commit comments

Comments
 (0)