Bug 1274046 - Add FailureId to gfxConfig (FeatureState). r=dvander draft
authorBenoit Girard <b56girard@gmail.com>
Fri, 20 May 2016 13:18:44 -0400
changeset 369234 d08b65582a8fa46cb8f1594009fd640eb3e3845e
parent 369197 7871e153914b76f7c8081b7529a2c02626bc7d2a
child 369235 31e3444cba670f40dae4ecd3463896f475fd1868
push id18805
push userb56girard@gmail.com
push dateFri, 20 May 2016 21:45:30 +0000
reviewersdvander
bugs1274046
milestone49.0a1
Bug 1274046 - Add FailureId to gfxConfig (FeatureState). r=dvander MozReview-Commit-ID: 4OhSLwipqdA
gfx/config/gfxConfig.cpp
gfx/config/gfxConfig.h
gfx/config/gfxFeature.cpp
gfx/config/gfxFeature.h
--- a/gfx/config/gfxConfig.cpp
+++ b/gfx/config/gfxConfig.cpp
@@ -214,10 +214,24 @@ void
 gfxConfig::ForEachFallbackImpl(const FallbackIterCallback& aCallback)
 {
   for (size_t i = 0; i < mNumFallbackLogEntries; i++) {
     const FallbackLogEntry& entry = mFallbackLog[i];
     aCallback(sFallbackNames[size_t(entry.mFallback)], entry.mMessage);
   }
 }
 
+/* static */ void
+gfxConfig::SetFailureId(Feature aFeature, const nsACString& aFailureId)
+{
+  FeatureState& state = sConfig.GetState(aFeature);
+  state.SetFailureId(aFailureId);
+}
+
+/* static */ const nsACString&
+gfxConfig::GetFailureId(Feature aFeature)
+{
+  const FeatureState& state = sConfig.GetState(aFeature);
+  return state.GetFailureId();
+}
+
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/config/gfxConfig.h
+++ b/gfx/config/gfxConfig.h
@@ -158,16 +158,20 @@ public:
                                  FeatureState& aFeature)> FeatureIterCallback;
   static void ForEachFeature(const FeatureIterCallback& aCallback);
 
   // Run a callback for each enabled fallback.
   typedef mozilla::function<void(const char* aName, const char* aMsg)> 
     FallbackIterCallback;
   static void ForEachFallback(const FallbackIterCallback& aCallback);
 
+  static void SetFailureId(Feature aFeature, const nsACString& aFailureId);
+
+  static const nsACString& GetFailureId(Feature aFeature);
+
 private:
   void ForEachFallbackImpl(const FallbackIterCallback& aCallback);
 
 private:
   FeatureState& GetState(Feature aFeature) {
     MOZ_ASSERT(size_t(aFeature) < kNumFeatures);
     return mFeatures[size_t(aFeature)];
   }
--- a/gfx/config/gfxFeature.cpp
+++ b/gfx/config/gfxFeature.cpp
@@ -229,16 +229,31 @@ FeatureState::ForEachStatusChange(const 
     aCallback("env", mEnvironment.mStatus, mEnvironment.Message());
   }
   if (mRuntime.IsInitialized()) {
     aCallback("runtime", mRuntime.mStatus, mRuntime.Message());
   }
 }
 
 void
+FeatureState::SetFailureId(const nsACString& aFailureId)
+{
+  if (mFailureId.IsEmpty()) {
+    mFailureId = aFailureId;
+  }
+}
+
+const nsACString&
+FeatureState::GetFailureId() const
+{
+  MOZ_ASSERT(!IsEnabled());
+  return mFailureId;
+}
+
+void
 FeatureState::Instance::Set(FeatureStatus aStatus, const char* aMessage /* = nullptr */)
 {
   mStatus = aStatus;
   if (aMessage) {
     PR_snprintf(mMessage, sizeof(mMessage), "%s", aMessage);
   }
 }
 
--- a/gfx/config/gfxFeature.h
+++ b/gfx/config/gfxFeature.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef mozilla_gfx_config_gfxFeature_h
 #define mozilla_gfx_config_gfxFeature_h
 
 #include <stdint.h>
 #include "gfxTelemetry.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Function.h"
+#include "nsString.h"
 
 namespace mozilla {
 namespace gfx {
 
 #define GFX_FEATURE_MAP(_)                                                        \
   /* Name,                        Type,         Description */                    \
   _(HW_COMPOSITING,               Feature,      "Compositing")                    \
   _(D3D11_COMPOSITING,            Feature,      "Direct3D11 Compositing")         \
@@ -60,16 +61,19 @@ class FeatureState
 
   // aType is "base", "user", "env", or "runtime".
   // aMessage may be null.
   typedef mozilla::function<void(const char* aType,
                                  FeatureStatus aStatus,
                                  const char* aMessage)> StatusIterCallback;
   void ForEachStatusChange(const StatusIterCallback& aCallback) const;
 
+  void SetFailureId(const nsACString& aFailureId);
+  const nsACString& GetFailureId() const;
+
  private:
   void SetUser(FeatureStatus aStatus, const char* aMessage);
   void SetEnvironment(FeatureStatus aStatus, const char* aMessage);
   void SetRuntime(FeatureStatus aStatus, const char* aMessage);
   bool IsForcedOnByUser() const;
   bool DisabledByDefault() const;
   const char* GetRuntimeMessage() const;
   bool IsInitialized() const {
@@ -106,14 +110,17 @@ class FeatureState
   // The environment state factors in any additional decisions made, such as
   // availability or blacklisting.
   //
   // The runtime state factors in any problems discovered at runtime.
   Instance mDefault;
   Instance mUser;
   Instance mEnvironment;
   Instance mRuntime;
+
+  // Store the first reported failureId
+  nsCString mFailureId;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif // mozilla_gfx_config_gfxFeature_h