Bug 958341 - Present "motivating service" to /account/create calls. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Tue, 26 Aug 2014 17:49:44 -0700
changeset 223407 ff9659baf12b6096579d86cb4465f1ad4754f072
parent 223406 12b02422dd35161ccc31032715192c3e4cc76c23
child 223408 6f233e72cb494d4599592006f604253f6fc0bef8
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs958341
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 958341 - Present "motivating service" to /account/create calls. r=rnewman ======== https://github.com/mozilla-services/android-sync/commit/f9d27162dcb20e460a0d79f6eb46862bbf3cfb5b Author: Nick Alexander <nalexander@mozilla.com> Date: Tue Aug 26 17:47:33 2014 -0700 Bug 958341 - Test and review comments. ======== https://github.com/mozilla-services/android-sync/commit/7b8289836322faf13c8f99e4f18c85b9dcde7841 Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Aug 18 14:53:54 2014 -0700 Bug 958341 - Present "motivating service" to /account/create calls. This is used for metrics and for personalizing the welcome emails. Since no email gets sent for /account/login, it is not needed there.
mobile/android/base/background/fxa/FxAccountClient20.java
--- a/mobile/android/base/background/fxa/FxAccountClient20.java
+++ b/mobile/android/base/background/fxa/FxAccountClient20.java
@@ -1,15 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.background.fxa;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
 import java.util.concurrent.Executor;
 
 import org.json.simple.JSONObject;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.Utils;
@@ -89,23 +92,45 @@ public class FxAccountClient20 extends F
           return;
         }
       }
     };
 
     post(resource, body, delegate);
   }
 
-  public void createAccount(final byte[] emailUTF8, final byte[] quickStretchedPW, final boolean getKeys, final boolean preVerified,
+  /**
+   * Create account/create URI, encoding query parameters carefully.
+   * <p>
+   * This is equivalent to <code>android.net.Uri.Builder</code>, which is not
+   * present in our JUnit 4 tests.
+   */
+  protected URI getCreateAccountURI(final boolean getKeys, final String service) throws UnsupportedEncodingException, URISyntaxException {
+    if (service == null) {
+      throw new IllegalArgumentException("service must not be null");
+    }
+    final StringBuilder sb = new StringBuilder(serverURI); // serverURI always has a trailing slash.
+    sb.append("account/create?service=");
+    // Be very careful that query parameters are encoded correctly!
+    sb.append(URLEncoder.encode(service, "UTF-8"));
+    if (getKeys) {
+      sb.append("&keys=true");
+    }
+    return new URI(sb.toString());
+  }
+
+  public void createAccount(final byte[] emailUTF8, final byte[] quickStretchedPW,
+      final boolean getKeys,
+      final boolean preVerified,
+      final String service,
       final RequestDelegate<LoginResponse> delegate) {
-    BaseResource resource;
-    JSONObject body;
-    final String path = getKeys ? "account/create?keys=true" : "account/create";
+    final BaseResource resource;
+    final JSONObject body;
     try {
-      resource = new BaseResource(new URI(serverURI + path));
+      resource = new BaseResource(getCreateAccountURI(getKeys, service));
       body = new FxAccount20CreateDelegate(emailUTF8, quickStretchedPW, preVerified).getCreateBody();
     } catch (Exception e) {
       invokeHandleError(delegate, e);
       return;
     }
 
     // This is very similar to login, except verified is not required.
     resource.delegate = new ResourceDelegate<LoginResponse>(resource, delegate) {
@@ -139,17 +164,17 @@ public class FxAccountClient20 extends F
 
     post(resource, body, delegate);
   }
 
   @Override
   public void createAccountAndGetKeys(byte[] emailUTF8, PasswordStretcher passwordStretcher, RequestDelegate<LoginResponse> delegate) {
     try {
       byte[] quickStretchedPW = passwordStretcher.getQuickStretchedPW(emailUTF8);
-      createAccount(emailUTF8, quickStretchedPW, true, false, delegate);
+      createAccount(emailUTF8, quickStretchedPW, true, false, "sync", delegate);
     } catch (Exception e) {
       invokeHandleError(delegate, e);
       return;
     }
   }
 
   @Override
   public void loginAndGetKeys(byte[] emailUTF8, PasswordStretcher passwordStretcher, RequestDelegate<LoginResponse> delegate) {