bug 1498165 - Support multistore in ScalarString r=janerik
authorChris H-C <chutten@mozilla.com>
Tue, 20 Nov 2018 19:58:04 +0000
changeset 503801 eeefb2421819f44f3f58001f72a735298122c332
parent 503800 c6176b21937b0ab446ffde1dcadff6e6aaa0e7af
child 503802 91c9a4e6d7a859f4578111b3c3b63f6af49c8e7a
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanerik
bugs1498165
milestone65.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 1498165 - Support multistore in ScalarString r=janerik Depends on D12131 Differential Revision: https://phabricator.services.mozilla.com/D12132
toolkit/components/telemetry/core/TelemetryScalar.cpp
--- a/toolkit/components/telemetry/core/TelemetryScalar.cpp
+++ b/toolkit/components/telemetry/core/TelemetryScalar.cpp
@@ -614,30 +614,32 @@ ScalarUnsigned::CheckInput(nsIVariant* a
 /**
  * The implementation for the string scalar type.
  */
 class ScalarString : public ScalarBase
 {
 public:
   using ScalarBase::SetValue;
 
-  ScalarString(const BaseScalarInfo& aInfo)
+  explicit ScalarString(const BaseScalarInfo& aInfo)
     : ScalarBase(aInfo)
-    , mStorage(EmptyString())
-  {};
+    , mStorage(aInfo.storeCount())
+  {
+    mStorage.SetLength(aInfo.storeCount());
+  };
 
   ~ScalarString() override = default;
 
   ScalarResult SetValue(nsIVariant* aValue) final;
   ScalarResult SetValue(const nsAString& aValue) final;
   nsresult GetValue(const nsACString& aStoreName, bool aClearStore, nsCOMPtr<nsIVariant>& aResult) final;
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const final;
 
 private:
-  nsString mStorage;
+  nsTArray<nsString> mStorage;
 
   // Prevent copying.
   ScalarString(const ScalarString& aOther) = delete;
   void operator=(const ScalarString& aOther) = delete;
 };
 
 ScalarResult
 ScalarString::SetValue(nsIVariant* aValue)
@@ -662,40 +664,59 @@ ScalarString::SetValue(nsIVariant* aValu
     return ScalarResult::InvalidValue;
   }
   return SetValue(convertedString);
 };
 
 ScalarResult
 ScalarString::SetValue(const nsAString& aValue)
 {
-  mStorage = Substring(aValue, 0, kMaximumStringValueLength);
+  auto str = Substring(aValue, 0, kMaximumStringValueLength);
+  for (auto& val: mStorage) {
+    val.Assign(str);
+  }
+  SetValueInStores();
   if (aValue.Length() > kMaximumStringValueLength) {
     return ScalarResult::StringTooLong;
   }
   return ScalarResult::Ok;
 }
 
 nsresult
 ScalarString::GetValue(const nsACString& aStoreName, bool aClearStore, nsCOMPtr<nsIVariant>& aResult)
 {
   nsCOMPtr<nsIWritableVariant> outVar(new nsVariant());
-  nsresult rv = outVar->SetAsAString(mStorage);
+  size_t storeIndex = 0;
+  nsresult rv = StoreIndex(aStoreName, &storeIndex);
   if (NS_FAILED(rv)) {
     return rv;
   }
+  if (!HasValueInStore(storeIndex)) {
+    return NS_ERROR_NO_CONTENT;
+  }
+  rv = outVar->SetAsAString(mStorage[storeIndex]);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  if (aClearStore) {
+    ClearValueInStore(storeIndex);
+  }
   aResult = outVar.forget();
   return NS_OK;
 }
 
 size_t
 ScalarString::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   size_t n = aMallocSizeOf(this);
-  n+= mStorage.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+  n += ScalarBase::SizeOfExcludingThis(aMallocSizeOf);
+  n += mStorage.ShallowSizeOfExcludingThis(aMallocSizeOf);
+  for (auto& val: mStorage) {
+    n += val.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+  }
   return n;
 }
 
 /**
  * The implementation for the boolean scalar type.
  */
 class ScalarBoolean : public ScalarBase
 {