Skip to content

Commit c16a901

Browse files
authored
Service lookup should use interface (#757)
* Resolve service using interface and initialize just once. The ServiceManager basically maps interface types to implementations based off of the plugin.xml. Make sure to retrieve the implementations using the interface type and not the implementation type. I'm also moving the initialization to the constructor since the client type should never change at runtime. * remove redundant import * added constructor javdoc
1 parent e6721c4 commit c16a901

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

google-account-plugin/src/com/google/cloud/tools/intellij/stats/GoogleUsageTracker.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.cloud.tools.intellij.stats;
1818

19-
import com.google.cloud.tools.intellij.IdeaAccountPluginInfoService;
19+
import com.google.cloud.tools.intellij.AccountPluginInfoService;
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.Lists;
2222

@@ -51,9 +51,16 @@ public class GoogleUsageTracker implements UsageTracker {
5151
private static final String ANALYTICS_URL = "https://ssl.google-analytics.com/collect";
5252

5353
private final String analyticsId;
54+
private String externalPluginName;
5455

56+
/**
57+
* Constructs a usage tracker configured with analytics and plugin name configured from its
58+
* environment.
59+
*/
5560
public GoogleUsageTracker() {
56-
this.analyticsId = UsageTrackerManager.getInstance().getAnalyticsProperty();
61+
analyticsId = UsageTrackerManager.getInstance().getAnalyticsProperty();
62+
externalPluginName = ServiceManager.getService(AccountPluginInfoService.class)
63+
.getExternalPluginName();
5764
}
5865

5966
private static final List<BasicNameValuePair> analyticsBaseData = ImmutableList
@@ -80,9 +87,6 @@ public void trackEvent(@NotNull String eventCategory,
8087

8188
List<BasicNameValuePair> postData = Lists.newArrayList(analyticsBaseData);
8289
postData.add(new BasicNameValuePair("tid", analyticsId));
83-
84-
String externalPluginName =
85-
ServiceManager.getService(IdeaAccountPluginInfoService.class).getExternalPluginName();
8690
postData.add(new BasicNameValuePair("cd19", externalPluginName)); // Event type
8791
postData.add(new BasicNameValuePair("cd20", eventAction)); // Event name
8892
postData.add(new BasicNameValuePair("cd16", "0")); // Internal user? No.

0 commit comments

Comments
 (0)