Use std::string_view as a parameter of ErrorScopeStack::HandleError()

Bug: dawn:1336
Change-Id: Id5b599509f3ec0119b2c060f7855443c7f87754f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/175623
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 34c98d7..60c1326 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -632,7 +632,6 @@
         type = InternalErrorType::DeviceLost;
     }
 
-    // TODO(lokokung) Update call sites that take the c-string to take string_view.
     const std::string messageStr = error->GetFormattedMessage();
     if (type == InternalErrorType::DeviceLost) {
         // The device was lost, schedule the application callback's executation.
@@ -653,12 +652,12 @@
         mCallbackTaskManager->HandleDeviceLoss();
 
         // Still forward device loss errors to the error scopes so they all reject.
-        mErrorScopeStack->HandleError(ToWGPUErrorType(type), messageStr.c_str());
+        mErrorScopeStack->HandleError(ToWGPUErrorType(type), messageStr);
     } else {
         // Pass the error to the error scope stack and call the uncaptured error callback
         // if it isn't handled. DeviceLost is not handled here because it should be
         // handled by the lost callback.
-        bool captured = mErrorScopeStack->HandleError(ToWGPUErrorType(type), messageStr.c_str());
+        bool captured = mErrorScopeStack->HandleError(ToWGPUErrorType(type), messageStr);
         if (!captured && mUncapturedErrorCallback != nullptr) {
             mUncapturedErrorCallback(static_cast<WGPUErrorType>(ToWGPUErrorType(type)),
                                      messageStr.c_str(), mUncapturedErrorUserdata);
diff --git a/src/dawn/native/ErrorScope.cpp b/src/dawn/native/ErrorScope.cpp
index 63ab77d..a3774df 100644
--- a/src/dawn/native/ErrorScope.cpp
+++ b/src/dawn/native/ErrorScope.cpp
@@ -82,7 +82,7 @@
     return mScopes.empty();
 }
 
-bool ErrorScopeStack::HandleError(wgpu::ErrorType type, const char* message) {
+bool ErrorScopeStack::HandleError(wgpu::ErrorType type, std::string_view message) {
     for (auto it = mScopes.rbegin(); it != mScopes.rend(); ++it) {
         if (it->mMatchedErrorType != type) {
             // Error filter does not match. Move on to the next scope.
diff --git a/src/dawn/native/ErrorScope.h b/src/dawn/native/ErrorScope.h
index f40934a..650b852 100644
--- a/src/dawn/native/ErrorScope.h
+++ b/src/dawn/native/ErrorScope.h
@@ -64,7 +64,7 @@
     // Pass an error to the scopes in the stack. Returns true if one of the scopes
     // captured the error. Returns false if the error should be forwarded to the
     // uncaptured error callback.
-    bool HandleError(wgpu::ErrorType type, const char* message);
+    bool HandleError(wgpu::ErrorType type, std::string_view message);
 
   private:
     std::vector<ErrorScope> mScopes;