Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
fbc77471
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fbc77471
编写于
2月 15, 2016
作者:
S
Sofian Hnaide
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add optinstatus event
上级
4062cc17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
3 deletion
+64
-3
src/vs/platform/telemetry/browser/mainTelemetryService.ts
src/vs/platform/telemetry/browser/mainTelemetryService.ts
+7
-3
src/vs/platform/telemetry/electron-browser/electronTelemetryService.ts
...rm/telemetry/electron-browser/electronTelemetryService.ts
+40
-0
src/vs/platform/telemetry/test/node/telemetryService.test.ts
src/vs/platform/telemetry/test/node/telemetryService.test.ts
+17
-0
未找到文件。
src/vs/platform/telemetry/browser/mainTelemetryService.ts
浏览文件 @
fbc77471
...
@@ -24,6 +24,7 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
...
@@ -24,6 +24,7 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
private
eventCount
:
number
;
private
eventCount
:
number
;
private
userIdHash
:
string
;
private
userIdHash
:
string
;
private
startTime
:
Date
;
private
startTime
:
Date
;
private
optInFriendly
:
string
[];
constructor
(
config
?:
ITelemetryServiceConfig
)
{
constructor
(
config
?:
ITelemetryServiceConfig
)
{
super
(
config
);
super
(
config
);
...
@@ -41,6 +42,9 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
...
@@ -41,6 +42,9 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
this
.
eventCount
=
0
;
this
.
eventCount
=
0
;
this
.
startTime
=
new
Date
();
this
.
startTime
=
new
Date
();
//holds a cache of predefined events that can be sent regardress of user optin status
this
.
optInFriendly
=
[
'
optInStatus
'
];
}
}
private
onUserIdle
():
void
{
private
onUserIdle
():
void
{
...
@@ -68,13 +72,13 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
...
@@ -68,13 +72,13 @@ export class MainTelemetryService extends AbstractTelemetryService implements IT
return
;
return
;
}
}
// don't send telemetry when not enabled
// don't send telemetry when
channel is
not enabled
if
(
!
this
.
config
.
enableTelemetry
)
{
if
(
!
this
.
config
.
enableTelemetry
)
{
return
;
return
;
}
}
// don't send events when
user is optout
// don't send events when
the user is optout unless the event is flaged as optin friendly
if
(
!
this
.
config
.
userOptIn
)
{
if
(
!
this
.
config
.
userOptIn
&&
this
.
optInFriendly
.
indexOf
(
eventName
)
===
-
1
)
{
return
;
return
;
}
}
...
...
src/vs/platform/telemetry/electron-browser/electronTelemetryService.ts
浏览文件 @
fbc77471
...
@@ -24,13 +24,25 @@ class StorageKeys {
...
@@ -24,13 +24,25 @@ class StorageKeys {
public
static
InstanceId
:
string
=
'
telemetry.instanceId
'
;
public
static
InstanceId
:
string
=
'
telemetry.instanceId
'
;
}
}
interface
ITelemetryEvent
{
eventName
:
string
;
data
?:
any
;
}
export
class
ElectronTelemetryService
extends
MainTelemetryService
implements
ITelemetryService
{
export
class
ElectronTelemetryService
extends
MainTelemetryService
implements
ITelemetryService
{
private
static
MAX_BUFFER_SIZE
=
100
;
private
_setupIds
:
Promise
<
ITelemetryInfo
>
;
private
_setupIds
:
Promise
<
ITelemetryInfo
>
;
private
_buffer
:
ITelemetryEvent
[];
private
_optInStatusLoaded
:
boolean
;
constructor
(@
IConfigurationService
private
configurationService
:
IConfigurationService
,
@
IStorageService
private
storageService
:
IStorageService
,
config
?:
ITelemetryServiceConfig
)
{
constructor
(@
IConfigurationService
private
configurationService
:
IConfigurationService
,
@
IStorageService
private
storageService
:
IStorageService
,
config
?:
ITelemetryServiceConfig
)
{
super
(
config
);
super
(
config
);
this
.
_buffer
=
[];
this
.
_optInStatusLoaded
=
false
;
this
.
loadOptinSettings
();
this
.
loadOptinSettings
();
this
.
_setupIds
=
this
.
setupIds
();
this
.
_setupIds
=
this
.
setupIds
();
}
}
...
@@ -41,8 +53,36 @@ export class ElectronTelemetryService extends MainTelemetryService implements IT
...
@@ -41,8 +53,36 @@ export class ElectronTelemetryService extends MainTelemetryService implements IT
public
getTelemetryInfo
():
Promise
<
ITelemetryInfo
>
{
public
getTelemetryInfo
():
Promise
<
ITelemetryInfo
>
{
return
this
.
_setupIds
;
return
this
.
_setupIds
;
}
}
/**
* override the base publicLog to prevent reporting any events before the optIn status is read from configuration
*/
public
publicLog
(
eventName
:
string
,
data
?:
any
):
void
{
if
(
this
.
_optInStatusLoaded
)
{
super
.
publicLog
(
eventName
,
data
);
}
else
{
// in case loading configuration is delayed, make sure the buffer does not grow beyond MAX_BUFFER_SIZE
if
(
this
.
_buffer
.
length
>
ElectronTelemetryService
.
MAX_BUFFER_SIZE
)
{
this
.
_buffer
=
[];
}
this
.
_buffer
.
push
({
eventName
:
eventName
,
data
:
data
});
}
}
private
flushBuffer
():
void
{
let
event
:
ITelemetryEvent
=
null
;
while
(
event
=
this
.
_buffer
.
pop
())
{
super
.
publicLog
(
event
.
eventName
,
event
.
data
);
}
}
private
loadOptinSettings
():
void
{
private
loadOptinSettings
():
void
{
this
.
configurationService
.
loadConfiguration
(
TELEMETRY_SECTION_ID
).
done
(
config
=>
{
this
.
config
.
userOptIn
=
config
?
config
.
enableTelemetry
:
this
.
config
.
userOptIn
;
this
.
_optInStatusLoaded
=
true
;
this
.
publicLog
(
'
optInStatus
'
,
{
optIn
:
this
.
config
.
userOptIn
});
this
.
flushBuffer
();
});
this
.
toUnbind
.
push
(
this
.
configurationService
.
addListener
(
ConfigurationServiceEventTypes
.
UPDATED
,
(
e
:
IConfigurationServiceEvent
)
=>
{
this
.
toUnbind
.
push
(
this
.
configurationService
.
addListener
(
ConfigurationServiceEventTypes
.
UPDATED
,
(
e
:
IConfigurationServiceEvent
)
=>
{
this
.
config
.
userOptIn
=
e
.
config
&&
e
.
config
[
TELEMETRY_SECTION_ID
]
?
e
.
config
[
TELEMETRY_SECTION_ID
].
enableTelemetry
:
this
.
config
.
userOptIn
;
this
.
config
.
userOptIn
=
e
.
config
&&
e
.
config
[
TELEMETRY_SECTION_ID
]
?
e
.
config
[
TELEMETRY_SECTION_ID
].
enableTelemetry
:
this
.
config
.
userOptIn
;
}));
}));
...
...
src/vs/platform/telemetry/test/node/telemetryService.test.ts
浏览文件 @
fbc77471
...
@@ -16,6 +16,8 @@ import Platform = require('vs/platform/platform');
...
@@ -16,6 +16,8 @@ import Platform = require('vs/platform/platform');
import
*
as
sinon
from
'
sinon
'
;
import
*
as
sinon
from
'
sinon
'
;
import
{
createSyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
createSyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
const
optInStatusEventName
:
string
=
'
optInStatus
'
;
class
TestTelemetryAppender
implements
TelemetryService
.
ITelemetryAppender
{
class
TestTelemetryAppender
implements
TelemetryService
.
ITelemetryAppender
{
public
events
:
any
[];
public
events
:
any
[];
...
@@ -778,4 +780,19 @@ suite('TelemetryService', () => {
...
@@ -778,4 +780,19 @@ suite('TelemetryService', () => {
service
.
dispose
();
service
.
dispose
();
}));
}));
test
(
'
Telemetry Service allows optin friendly events
'
,
sinon
.
test
(
function
()
{
let
service
=
new
MainTelemetryService
.
MainTelemetryService
({
userOptIn
:
false
,
enableTelemetry
:
true
});
let
testAppender
=
new
TestTelemetryAppender
();
service
.
addTelemetryAppender
(
testAppender
);
service
.
publicLog
(
'
testEvent
'
);
assert
.
equal
(
testAppender
.
getEventsCount
(),
0
);
service
.
publicLog
(
optInStatusEventName
,
{
userOptIn
:
false
});
assert
.
equal
(
testAppender
.
getEventsCount
(),
1
);
assert
.
equal
(
testAppender
.
events
[
0
].
eventName
,
optInStatusEventName
);
assert
.
equal
(
testAppender
.
events
[
0
].
data
.
userOptIn
,
false
);
service
.
dispose
();
}));
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录