Replace const std::string& with string_view for aggregation_service

This is now preferred. Also updates some Private Aggregation unittests
to match and some constexpr char arrays. Sql queries are also adapted
to use base::c_stringview instead of char*.

Change-Id: If96577d9cf67e49a60c54fa34b1762f8f2d60d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5783696
Reviewed-by: Qingxin Wu <[email protected]>
Reviewed-by: Nan Lin <[email protected]>
Commit-Queue: Alex Turner <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1341913}
diff --git a/components/aggregation_service/aggregation_coordinator_utils.cc b/components/aggregation_service/aggregation_coordinator_utils.cc
index a2240e00..75a362a7 100644
--- a/components/aggregation_service/aggregation_coordinator_utils.cc
+++ b/components/aggregation_service/aggregation_coordinator_utils.cc
@@ -4,7 +4,6 @@
 
 #include "components/aggregation_service/aggregation_coordinator_utils.h"
 
-#include <string>
 #include <string_view>
 #include <utility>
 #include <vector>
@@ -28,7 +27,7 @@
           url::Origin::Create(GURL(kDefaultAggregationCoordinatorGcpCloud))};
 }
 
-std::vector<url::Origin> Parse(const std::string& unparsed) {
+std::vector<url::Origin> Parse(std::string_view unparsed) {
   std::vector<url::Origin> parsed;
 
   std::vector<std::string_view> tokens = base::SplitStringPiece(
@@ -53,7 +52,7 @@
   CoordinatorOrigins() = default;
   ~CoordinatorOrigins() = default;
 
-  explicit CoordinatorOrigins(const std::string& unparsed)
+  explicit CoordinatorOrigins(std::string_view unparsed)
       : CoordinatorOrigins(Parse(unparsed)) {}
 
   explicit CoordinatorOrigins(std::vector<url::Origin> origins)
diff --git a/components/aggregation_service/aggregation_coordinator_utils.h b/components/aggregation_service/aggregation_coordinator_utils.h
index 437a90b7..ea56428d 100644
--- a/components/aggregation_service/aggregation_coordinator_utils.h
+++ b/components/aggregation_service/aggregation_coordinator_utils.h
@@ -5,6 +5,7 @@
 #ifndef COMPONENTS_AGGREGATION_SERVICE_AGGREGATION_COORDINATOR_UTILS_H_
 #define COMPONENTS_AGGREGATION_SERVICE_AGGREGATION_COORDINATOR_UTILS_H_
 
+#include <string_view>
 #include <vector>
 
 #include "base/component_export.h"
@@ -12,10 +13,10 @@
 
 namespace aggregation_service {
 
-constexpr char kDefaultAggregationCoordinatorAwsCloud[] =
+inline constexpr std::string_view kDefaultAggregationCoordinatorAwsCloud =
     "https://publickeyservice.msmt.aws.privacysandboxservices.com";
 
-constexpr char kDefaultAggregationCoordinatorGcpCloud[] =
+inline constexpr std::string_view kDefaultAggregationCoordinatorGcpCloud =
     "https://publickeyservice.msmt.gcp.privacysandboxservices.com";
 
 COMPONENT_EXPORT(AGGREGATION_SERVICE)
diff --git a/components/aggregation_service/parsing_utils.cc b/components/aggregation_service/parsing_utils.cc
index 633dfa4..b3f327b 100644
--- a/components/aggregation_service/parsing_utils.cc
+++ b/components/aggregation_service/parsing_utils.cc
@@ -5,7 +5,7 @@
 #include "components/aggregation_service/parsing_utils.h"
 
 #include <optional>
-#include <string>
+#include <string_view>
 
 #include "components/aggregation_service/aggregation_coordinator_utils.h"
 #include "url/gurl.h"
@@ -13,7 +13,7 @@
 
 namespace aggregation_service {
 
-std::optional<url::Origin> ParseAggregationCoordinator(const std::string& str) {
+std::optional<url::Origin> ParseAggregationCoordinator(std::string_view str) {
   auto origin = url::Origin::Create(GURL(str));
   if (IsAggregationCoordinatorOriginAllowed(origin)) {
     return origin;
diff --git a/components/aggregation_service/parsing_utils.h b/components/aggregation_service/parsing_utils.h
index afc3ca5..3e8ec2a 100644
--- a/components/aggregation_service/parsing_utils.h
+++ b/components/aggregation_service/parsing_utils.h
@@ -6,7 +6,7 @@
 #define COMPONENTS_AGGREGATION_SERVICE_PARSING_UTILS_H_
 
 #include <optional>
-#include <string>
+#include <string_view>
 
 #include "base/component_export.h"
 
@@ -19,7 +19,7 @@
 // Parses aggregation coordinator identifier. Returns `kDefault` if `str` is
 // nullptr or is not a pre-defined value.
 COMPONENT_EXPORT(AGGREGATION_SERVICE)
-std::optional<url::Origin> ParseAggregationCoordinator(const std::string& str);
+std::optional<url::Origin> ParseAggregationCoordinator(std::string_view str);
 
 }  // namespace aggregation_service
 
diff --git a/content/browser/aggregation_service/aggregatable_report.cc b/content/browser/aggregation_service/aggregatable_report.cc
index 917abb1..a29d148 100644
--- a/content/browser/aggregation_service/aggregatable_report.cc
+++ b/content/browser/aggregation_service/aggregatable_report.cc
@@ -13,6 +13,7 @@
 #include <optional>
 #include <ostream>
 #include <string>
+#include <string_view>
 #include <type_traits>
 #include <utility>
 #include <vector>
@@ -61,8 +62,8 @@
 constexpr size_t kBitsPerByte = 8;
 
 // Payload contents:
-constexpr char kHistogramValue[] = "histogram";
-constexpr char kOperationKey[] = "operation";
+constexpr std::string_view kHistogramValue = "histogram";
+constexpr std::string_view kOperationKey = "operation";
 
 std::vector<GURL> GetDefaultProcessingUrls(
     blink::mojom::AggregationServiceMode aggregation_mode,
@@ -582,7 +583,7 @@
 
 GURL GetAggregationServiceProcessingUrl(const url::Origin& origin) {
   GURL::Replacements replacements;
-  static constexpr char kEndpointPath[] =
+  static constexpr std::string_view kEndpointPath =
       ".well-known/aggregation-service/v1/public-keys";
   replacements.SetPathStr(kEndpointPath);
   return origin.GetURL().ReplaceComponents(replacements);
diff --git a/content/browser/aggregation_service/aggregatable_report.h b/content/browser/aggregation_service/aggregatable_report.h
index 56c5cf3..cc9b20d 100644
--- a/content/browser/aggregation_service/aggregatable_report.h
+++ b/content/browser/aggregation_service/aggregatable_report.h
@@ -212,7 +212,7 @@
   const std::vector<AggregationServicePayload>& payloads() const {
     return payloads_;
   }
-  const std::string& shared_info() const { return shared_info_; }
+  std::string_view shared_info() const { return shared_info_; }
   std::optional<uint64_t> debug_key() const { return debug_key_; }
   const base::flat_map<std::string, std::string>& additional_fields() const {
     return additional_fields_;
@@ -391,7 +391,7 @@
   const AggregatableReportSharedInfo& shared_info() const {
     return shared_info_;
   }
-  const std::string& reporting_path() const { return reporting_path_; }
+  std::string_view reporting_path() const { return reporting_path_; }
   std::optional<uint64_t> debug_key() const { return debug_key_; }
   const base::flat_map<std::string, std::string>& additional_fields() const {
     return additional_fields_;
diff --git a/content/browser/aggregation_service/aggregatable_report_assembler_unittest.cc b/content/browser/aggregation_service/aggregatable_report_assembler_unittest.cc
index d0ee5d5..c56a4db 100644
--- a/content/browser/aggregation_service/aggregatable_report_assembler_unittest.cc
+++ b/content/browser/aggregation_service/aggregatable_report_assembler_unittest.cc
@@ -8,6 +8,7 @@
 
 #include <memory>
 #include <optional>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -43,7 +44,7 @@
 using PublicKeyFetchStatus = AggregationServiceKeyFetcher::PublicKeyFetchStatus;
 using AssemblyStatus = AggregatableReportAssembler::AssemblyStatus;
 
-constexpr char kReportAssemblerStatusHistogramName[] =
+constexpr std::string_view kReportAssemblerStatusHistogramName =
     "PrivacySandbox.AggregationService.ReportAssembler.Status";
 
 auto CloneRequestAndReturnReport(std::optional<AggregatableReportRequest>* out,
diff --git a/content/browser/aggregation_service/aggregatable_report_unittest.cc b/content/browser/aggregation_service/aggregatable_report_unittest.cc
index 5c00fe6..4a7a8c8 100644
--- a/content/browser/aggregation_service/aggregatable_report_unittest.cc
+++ b/content/browser/aggregation_service/aggregatable_report_unittest.cc
@@ -11,6 +11,7 @@
 #include <limits>
 #include <optional>
 #include <string>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -47,7 +48,7 @@
 
 testing::AssertionResult CborMapContainsKeyAndType(
     const cbor::Value::MapValue& map,
-    const std::string& key,
+    std::string_view key,
     cbor::Value::Type value_type) {
   const auto it = map.find(cbor::Value(key));
   if (it == map.end()) {
diff --git a/content/browser/aggregation_service/aggregation_service_key_fetcher_unittest.cc b/content/browser/aggregation_service/aggregation_service_key_fetcher_unittest.cc
index 79713bc..1b0752c90 100644
--- a/content/browser/aggregation_service/aggregation_service_key_fetcher_unittest.cc
+++ b/content/browser/aggregation_service/aggregation_service_key_fetcher_unittest.cc
@@ -6,6 +6,7 @@
 
 #include <memory>
 #include <optional>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -35,7 +36,7 @@
 using NetworkFetchCallback =
     AggregationServiceKeyFetcher::NetworkFetcher::NetworkFetchCallback;
 
-constexpr char kExampleUrl[] = "https://a.com/keys";
+constexpr std::string_view kExampleUrl = "https://a.com/keys";
 
 // NetworkFetcher that manages the public keys in memory.
 class MockNetworkFetcher : public AggregationServiceKeyFetcher::NetworkFetcher {
diff --git a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.cc b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.cc
index c8761ce..5eff70d 100644
--- a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.cc
+++ b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.cc
@@ -249,7 +249,7 @@
     const GURL& url,
     NetworkFetchCallback callback,
     FetchStatus error,
-    const std::string& error_msg) {
+    std::string_view error_msg) {
   CHECK_NE(error, FetchStatus::kSuccess);
   RecordFetchStatus(error);
 
diff --git a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.h b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.h
index 18e3d3d..c834a0cc 100644
--- a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.h
+++ b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl.h
@@ -7,7 +7,7 @@
 
 #include <list>
 #include <memory>
-#include <string>
+#include <string_view>
 
 #include "base/memory/raw_ptr.h"
 #include "base/memory/raw_ref.h"
@@ -103,7 +103,7 @@
   void OnError(const GURL& url,
                NetworkFetchCallback callback,
                FetchStatus status,
-               const std::string& error_msg);
+               std::string_view error_msg);
 
   void RecordFetchStatus(FetchStatus status) const;
 
diff --git a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl_unittest.cc b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl_unittest.cc
index 5cdaeeb..caeefa8 100644
--- a/content/browser/aggregation_service/aggregation_service_network_fetcher_impl_unittest.cc
+++ b/content/browser/aggregation_service/aggregation_service_network_fetcher_impl_unittest.cc
@@ -6,6 +6,7 @@
 
 #include <memory>
 #include <string>
+#include <string_view>
 #include <vector>
 
 #include "base/barrier_closure.h"
@@ -56,10 +57,10 @@
 const std::vector<PublicKey> kExamplePublicKeys = {
     kExampleHpkeKey.GetPublicKey()};
 
-constexpr char kKeyFetcherStatusHistogramName[] =
+constexpr std::string_view kKeyFetcherStatusHistogramName =
     "PrivacySandbox.AggregationService.KeyFetcher.Status2";
 
-constexpr char kKeyFetcherHttpResponseOrNetErrorCodeHistogramName[] =
+constexpr std::string_view kKeyFetcherHttpResponseOrNetErrorCodeHistogramName =
     "PrivacySandbox.AggregationService.KeyFetcher.HttpResponseOrNetErrorCode";
 
 }  // namespace
diff --git a/content/browser/aggregation_service/aggregation_service_storage_sql.cc b/content/browser/aggregation_service/aggregation_service_storage_sql.cc
index ba44885..b361ac91 100644
--- a/content/browser/aggregation_service/aggregation_service_storage_sql.cc
+++ b/content/browser/aggregation_service/aggregation_service_storage_sql.cc
@@ -24,6 +24,7 @@
 #include "base/logging.h"
 #include "base/metrics/histogram_functions.h"
 #include "base/sequence_checker.h"
+#include "base/strings/cstring_view.h"
 #include "base/time/clock.h"
 #include "base/time/time.h"
 #include "base/timer/elapsed_timer.h"
@@ -76,7 +77,7 @@
 // `reporting_origin` should match the corresponding proto field, but is
 // maintained separately for data deletion.
 // `request_proto` is a serialized AggregatableReportRequest proto.
-static constexpr char kReportRequestsCreateTableSql[] =
+static constexpr base::cstring_view kReportRequestsCreateTableSql =
     // clang-format off
     "CREATE TABLE IF NOT EXISTS report_requests("
         "request_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
@@ -87,18 +88,18 @@
 // clang-format on
 
 // Used to optimize report request lookup by report_time.
-static constexpr char kReportTimeIndexSql[] =
+static constexpr base::cstring_view kReportTimeIndexSql =
     "CREATE INDEX IF NOT EXISTS report_time_idx ON "
     "report_requests(report_time)";
 
 // Will be used to optimize report request lookup by creation_time for data
 // clearing, see crbug.com/1340053.
-static constexpr char kCreationTimeIndexSql[] =
+static constexpr base::cstring_view kCreationTimeIndexSql =
     "CREATE INDEX IF NOT EXISTS creation_time_idx ON "
     "report_requests(creation_time)";
 
 // Used to optimize checking whether there is capacity for the reporting origin.
-static constexpr char kReportingOriginIndexSql[] =
+static constexpr base::cstring_view kReportingOriginIndexSql =
     "CREATE INDEX IF NOT EXISTS reporting_origin_idx ON "
     "report_requests(reporting_origin)";
 
diff --git a/content/browser/aggregation_service/aggregation_service_test_utils.cc b/content/browser/aggregation_service/aggregation_service_test_utils.cc
index 7f6e464..ce479b7 100644
--- a/content/browser/aggregation_service/aggregation_service_test_utils.cc
+++ b/content/browser/aggregation_service/aggregation_service_test_utils.cc
@@ -10,6 +10,7 @@
 #include <optional>
 #include <ostream>
 #include <string>
+#include <string_view>
 #include <tuple>
 #include <vector>
 
@@ -302,7 +303,7 @@
   return AggregatableReportRequest::CreateForTesting(
              request.processing_urls(), request.payload_contents(),
              request.shared_info().Clone(), request.delay_type(),
-             request.reporting_path(), request.debug_key(),
+             std::string(request.reporting_path()), request.debug_key(),
              request.additional_fields(), request.failed_send_attempts())
       .value();
 }
@@ -314,7 +315,8 @@
                           payload.debug_cleartext_payload);
   }
 
-  return AggregatableReport(std::move(payloads), report.shared_info(),
+  return AggregatableReport(std::move(payloads),
+                            std::string(report.shared_info()),
                             report.debug_key(), report.additional_fields(),
                             report.aggregation_coordinator_origin());
 }
@@ -375,7 +377,7 @@
 std::vector<uint8_t> DecryptPayloadWithHpke(
     base::span<const uint8_t> payload,
     const EVP_HPKE_KEY& key,
-    const std::string& expected_serialized_shared_info) {
+    std::string_view expected_serialized_shared_info) {
   base::span<const uint8_t> enc = payload.first<X25519_PUBLIC_VALUE_LEN>();
 
   std::string authenticated_info_str =
diff --git a/content/browser/aggregation_service/aggregation_service_test_utils.h b/content/browser/aggregation_service/aggregation_service_test_utils.h
index 3a7535d..1638575 100644
--- a/content/browser/aggregation_service/aggregation_service_test_utils.h
+++ b/content/browser/aggregation_service/aggregation_service_test_utils.h
@@ -115,7 +115,7 @@
 std::vector<uint8_t> DecryptPayloadWithHpke(
     base::span<const uint8_t> payload,
     const EVP_HPKE_KEY& key,
-    const std::string& expected_serialized_shared_info);
+    std::string_view expected_serialized_shared_info);
 
 MATCHER_P(RequestIdIs, matcher, "") {
   return ExplainMatchResult(matcher, arg.id, result_listener);
diff --git a/content/browser/interest_group/ad_auction_service_impl_unittest.cc b/content/browser/interest_group/ad_auction_service_impl_unittest.cc
index e405508..e9b733f0 100644
--- a/content/browser/interest_group/ad_auction_service_impl_unittest.cc
+++ b/content/browser/interest_group/ad_auction_service_impl_unittest.cc
@@ -1597,7 +1597,9 @@
 })",
           kOriginStringA, kOriginStringA, kOriginStringA, kOriginStringA,
           kOriginStringA, kOriginStringA,
-          aggregation_service::kDefaultAggregationCoordinatorAwsCloud));
+          std::string(
+              aggregation_service::kDefaultAggregationCoordinatorAwsCloud)
+              .c_str()));
 
   blink::InterestGroup interest_group = CreateInterestGroup();
   interest_group.priority = 2.0;
diff --git a/content/browser/private_aggregation/private_aggregation_internals_browsertest.cc b/content/browser/private_aggregation/private_aggregation_internals_browsertest.cc
index e7e6d89..24a49a2 100644
--- a/content/browser/private_aggregation/private_aggregation_internals_browsertest.cc
+++ b/content/browser/private_aggregation/private_aggregation_internals_browsertest.cc
@@ -4,7 +4,7 @@
 
 #include <memory>
 #include <optional>
-#include <string>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -36,10 +36,10 @@
 using GetPendingReportsCallback = base::OnceCallback<void(
     std::vector<AggregationServiceStorage::RequestAndId>)>;
 
-constexpr char kPrivateAggregationInternalsUrl[] =
+constexpr std::string_view kPrivateAggregationInternalsUrl =
     "chrome://private-aggregation-internals/";
 
-const std::u16string kCompleteTitle = u"Complete";
+constexpr std::u16string_view kCompleteTitle = u"Complete";
 
 class PrivateAggregationInternalsWebUiBrowserTest : public ContentBrowserTest {
  public:
@@ -67,15 +67,15 @@
   // Executing javascript in the WebUI requires using an isolated world in which
   // to execute the script because WebUI has a default CSP policy denying
   // "eval()", which is what EvalJs uses under the hood.
-  bool ExecJsInWebUI(const std::string& script) {
+  bool ExecJsInWebUI(std::string_view script) {
     return ExecJs(shell()->web_contents()->GetPrimaryMainFrame(), script,
                   EXECUTE_SCRIPT_DEFAULT_OPTIONS, /*world_id=*/1);
   }
 
   // Registers a mutation observer that sets the window title to `title` when
   // the report table is empty.
-  void SetTitleOnReportsTableEmpty(const std::u16string& title) {
-    static constexpr char kObserveEmptyReportsTableScript[] = R"(
+  void SetTitleOnReportsTableEmpty(std::u16string_view title) {
+    static constexpr std::string_view kObserveEmptyReportsTableScript = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const obs = new MutationObserver((_, obs) => {
@@ -185,7 +185,7 @@
       AggregationServiceObserver::ReportStatus::kFailedToSend);
 
   {
-    static constexpr char wait_script[] = R"(
+    static constexpr std::string_view wait_script = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const cell = (a, b) => table.children[a]?.children[b]?.textContent;
@@ -216,7 +216,7 @@
   }
 
   {
-    static constexpr char wait_script[] = R"(
+    static constexpr std::string_view wait_script = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const cell = (a, b) => table.children[a]?.children[b]?.textContent;
@@ -232,7 +232,7 @@
       });
       obs.observe(table, {'childList': true});)";
 
-    const std::u16string kCompleteTitle2 = u"Complete2";
+    const std::u16string_view kCompleteTitle2 = u"Complete2";
     EXPECT_TRUE(ExecJsInWebUI(JsReplace(wait_script, kCompleteTitle2)));
 
     TitleWatcher title_watcher(shell()->web_contents(), kCompleteTitle2);
@@ -244,7 +244,7 @@
   }
 
   {
-    static constexpr char wait_script[] = R"(
+    static constexpr std::string_view wait_script = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const cell = (a, b) => table.children[a]?.children[b]?.textContent;
@@ -260,7 +260,7 @@
       });
       obs.observe(table, {'childList': true});)";
 
-    const std::u16string kCompleteTitle3 = u"Complete3";
+    const std::u16string_view kCompleteTitle3 = u"Complete3";
     EXPECT_TRUE(ExecJsInWebUI(JsReplace(wait_script, kCompleteTitle3)));
 
     TitleWatcher title_watcher(shell()->web_contents(), kCompleteTitle3);
@@ -299,7 +299,7 @@
                   testing::_))
       .WillOnce(base::test::RunOnceCallback<1>());
 
-  static constexpr char wait_script[] = R"(
+  static constexpr std::string_view wait_script = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const obs = new MutationObserver((_, obs) => {
@@ -317,7 +317,7 @@
   EXPECT_EQ(kCompleteTitle, title_watcher.WaitAndGetTitle());
 
   // Click the send reports button and expect that the report table is emptied.
-  const std::u16string kSentTitle = u"Sent";
+  constexpr std::u16string_view kSentTitle = u"Sent";
   TitleWatcher sent_title_watcher(shell()->web_contents(), kSentTitle);
   SetTitleOnReportsTableEmpty(kSentTitle);
 
@@ -367,7 +367,7 @@
       .WillOnce(base::test::RunOnceCallback<3>());
 
   // Verify both rows get rendered.
-  static constexpr char wait_script[] = R"(
+  static constexpr std::string_view wait_script = R"(
       const table = document.querySelector('#reportTable')
           .shadowRoot.querySelector('tbody');
       const obs = new MutationObserver((_, obs) => {
@@ -387,7 +387,7 @@
   EXPECT_EQ(kCompleteTitle, title_watcher.WaitAndGetTitle());
 
   // Click the clear-data button and expect that the report table is emptied.
-  const std::u16string kDeleteTitle = u"Delete";
+  constexpr std::u16string_view kDeleteTitle = u"Delete";
   TitleWatcher delete_title_watcher(shell()->web_contents(), kDeleteTitle);
   SetTitleOnReportsTableEmpty(kDeleteTitle);
 
diff --git a/content/browser/private_aggregation/private_aggregation_report_golden_unittest.cc b/content/browser/private_aggregation/private_aggregation_report_golden_unittest.cc
index 96f2f70f..8612e4c 100644
--- a/content/browser/private_aggregation/private_aggregation_report_golden_unittest.cc
+++ b/content/browser/private_aggregation/private_aggregation_report_golden_unittest.cc
@@ -56,7 +56,7 @@
 namespace content {
 namespace {
 
-constexpr char kKeyAggregationServicePayloads[] =
+constexpr std::string_view kKeyAggregationServicePayloads =
     "aggregation_service_payloads";
 
 std::string ReadStringFromFile(const base::FilePath& file, bool trim = false) {
@@ -186,7 +186,7 @@
   testing::AssertionResult VerifyReport(
       base::Value::Dict actual_report,
       base::Value::Dict expected_report,
-      const std::string& base64_encoded_expected_cleartext_payload) {
+      std::string_view base64_encoded_expected_cleartext_payload) {
     std::optional<base::Value> actual_payloads =
         actual_report.Extract(kKeyAggregationServicePayloads);
     if (!actual_payloads) {
@@ -209,7 +209,7 @@
                 "the aggregation service payloads";
     }
 
-    static constexpr char kKeySharedInfo[] = "shared_info";
+    static constexpr std::string_view kKeySharedInfo = "shared_info";
     const std::string* shared_info = expected_report.FindString(kKeySharedInfo);
     if (!shared_info) {
       return testing::AssertionFailure()
@@ -236,8 +236,8 @@
   testing::AssertionResult VerifyAggregationServicePayloads(
       base::Value::List actual_payloads,
       base::Value::List expected_payloads,
-      const std::string& base64_encoded_expected_cleartext_payload,
-      const std::string& shared_info) {
+      std::string_view base64_encoded_expected_cleartext_payload,
+      std::string_view shared_info) {
     if (actual_payloads.size() != 1u) {
       return testing::AssertionFailure()
              << kKeyAggregationServicePayloads
@@ -264,7 +264,7 @@
              << "[0] not a dictionary in the expected report";
     }
 
-    static constexpr char kKeyPayload[] = "payload";
+    static constexpr std::string_view kKeyPayload = "payload";
 
     std::optional<base::Value> actual_encrypted_payload =
         actual_payload->Extract(kKeyPayload);
@@ -321,8 +321,8 @@
 
   // Returns empty vector in case of an error.
   std::vector<uint8_t> DecryptPayload(
-      const std::string& base64_encoded_encrypted_payload,
-      const std::string& shared_info) {
+      std::string_view base64_encoded_encrypted_payload,
+      std::string_view shared_info) {
     std::optional<std::vector<uint8_t>> encrypted_payload =
         base::Base64Decode(base64_encoded_encrypted_payload);
     if (!encrypted_payload) {
diff --git a/tools/aggregation_service/aggregation_service_tool.cc b/tools/aggregation_service/aggregation_service_tool.cc
index d59fb7dd..b2227b9 100644
--- a/tools/aggregation_service/aggregation_service_tool.cc
+++ b/tools/aggregation_service/aggregation_service_tool.cc
@@ -6,6 +6,7 @@
 
 #include <functional>
 #include <string>
+#include <string_view>
 #include <utility>
 
 #include "base/check.h"
@@ -32,7 +33,7 @@
 namespace {
 
 std::optional<content::TestAggregationService::Operation> ConvertToOperation(
-    const std::string& operation_string) {
+    std::string_view operation_string) {
   if (operation_string == "histogram")
     return content::TestAggregationService::Operation::kHistogram;
 
@@ -40,7 +41,7 @@
 }
 
 std::optional<content::TestAggregationService::AggregationMode>
-ConvertToAggregationMode(const std::string& aggregation_mode_string) {
+ConvertToAggregationMode(std::string_view aggregation_mode_string) {
   if (aggregation_mode_string == "tee-based")
     return content::TestAggregationService::AggregationMode::kTeeBased;
   if (aggregation_mode_string == "experimental-poplar")
@@ -92,7 +93,7 @@
 
 bool AggregationServiceTool::SetPublicKeysFromFile(
     const GURL& url,
-    const std::string& json_file_path) {
+    std::string_view json_file_path) {
 #if BUILDFLAG(IS_WIN)
   base::FilePath json_file(base::UTF8ToWide(json_file_path));
 #else
diff --git a/tools/aggregation_service/aggregation_service_tool.h b/tools/aggregation_service/aggregation_service_tool.h
index 13fbe39..3fd512926 100644
--- a/tools/aggregation_service/aggregation_service_tool.h
+++ b/tools/aggregation_service/aggregation_service_tool.h
@@ -7,6 +7,7 @@
 
 #include <memory>
 #include <string>
+#include <string_view>
 #include <vector>
 
 #include "base/strings/string_split.h"
@@ -76,8 +77,7 @@
                          const base::FilePath& filename);
 
  private:
-  bool SetPublicKeysFromFile(const GURL& url,
-                             const std::string& json_file_path);
+  bool SetPublicKeysFromFile(const GURL& url, std::string_view json_file_path);
 
   ToolNetworkInitializer network_initializer_;
   std::unique_ptr<content::TestAggregationService> agg_service_;
diff --git a/tools/aggregation_service/aggregation_service_tool_main.cc b/tools/aggregation_service/aggregation_service_tool_main.cc
index 1c0f94e..ae66614 100644
--- a/tools/aggregation_service/aggregation_service_tool_main.cc
+++ b/tools/aggregation_service/aggregation_service_tool_main.cc
@@ -4,6 +4,7 @@
 
 #include <iterator>
 #include <string>
+#include <string_view>
 
 #include "base/command_line.h"
 #include "base/containers/contains.h"
@@ -26,27 +27,28 @@
 
 // If you change any of the switch strings, update the `kHelpMsg`,
 // `kAllowedSwitches` and `kRequiredSwitches` accordingly.
-constexpr char kSwitchHelp[] = "help";
-constexpr char kSwitchHelpShort[] = "h";
-constexpr char kSwitchOperation[] = "operation";
-constexpr char kSwitchBucket[] = "bucket";
-constexpr char kSwitchValue[] = "value";
-constexpr char kSwitchAlternativeAggregationMode[] =
+constexpr std::string_view kSwitchHelp = "help";
+constexpr std::string_view kSwitchHelpShort = "h";
+constexpr std::string_view kSwitchOperation = "operation";
+constexpr std::string_view kSwitchBucket = "bucket";
+constexpr std::string_view kSwitchValue = "value";
+constexpr std::string_view kSwitchAlternativeAggregationMode =
     "alternative-aggregation-mode";
-constexpr char kSwitchReportingOrigin[] = "reporting-origin";
-constexpr char kSwitchHelperKeyUrls[] = "helper-key-urls";
-constexpr char kSwitchHelperKeyFiles[] = "helper-key-files";
-constexpr char kSwitchOutputFile[] = "output-file";
-constexpr char kSwitchOutputUrl[] = "output-url";
-constexpr char kSwitchDisablePayloadEncryption[] = "disable-payload-encryption";
-constexpr char kSwitchAdditionalFields[] = "additional-fields";
-constexpr char kSwitchAdditionalSharedInfoFields[] =
+constexpr std::string_view kSwitchReportingOrigin = "reporting-origin";
+constexpr std::string_view kSwitchHelperKeyUrls = "helper-key-urls";
+constexpr std::string_view kSwitchHelperKeyFiles = "helper-key-files";
+constexpr std::string_view kSwitchOutputFile = "output-file";
+constexpr std::string_view kSwitchOutputUrl = "output-url";
+constexpr std::string_view kSwitchDisablePayloadEncryption =
+    "disable-payload-encryption";
+constexpr std::string_view kSwitchAdditionalFields = "additional-fields";
+constexpr std::string_view kSwitchAdditionalSharedInfoFields =
     "additional-shared-info-fields";
-constexpr char kSwitchEnableDebugMode[] = "enable-debug-mode";
-constexpr char kSwitchApiVersion[] = "api-version";
-constexpr char kSwitchApi[] = "api";
+constexpr std::string_view kSwitchEnableDebugMode = "enable-debug-mode";
+constexpr std::string_view kSwitchApiVersion = "api-version";
+constexpr std::string_view kSwitchApi = "api";
 
-constexpr char kHelpMsg[] = R"(
+constexpr std::string_view kHelpMsg = R"(
   aggregation_service_tool [--operation=<operation>] --bucket=<bucket>
   --value=<value> --aggregation-mode=<aggregation_mode>
   --reporting-origin=<reporting_origin>
@@ -137,7 +139,7 @@
     return 1;
   }
 
-  const std::vector<std::string> kAllowedSwitches = {
+  const std::vector<std::string_view> kAllowedSwitches = {
       kSwitchHelp,
       kSwitchHelpShort,
       kSwitchOperation,
@@ -171,10 +173,10 @@
     return 1;
   }
 
-  const std::vector<std::string> kRequiredSwitches = {
+  const std::vector<std::string_view> kRequiredSwitches = {
       kSwitchBucket, kSwitchValue, kSwitchReportingOrigin};
-  for (const std::string& required_switch : kRequiredSwitches) {
-    if (!command_line.HasSwitch(required_switch.c_str())) {
+  for (std::string_view required_switch : kRequiredSwitches) {
+    if (!command_line.HasSwitch(required_switch)) {
       LOG(ERROR) << "aggregation_service_tool expects " << required_switch
                  << " to be specified.";
       PrintHelp();
@@ -217,7 +219,7 @@
         base::SplitString(switch_value, /*separators=*/" ",
                           base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
 
-    for (const std::string& url_string : helper_key_url_strings) {
+    for (std::string_view url_string : helper_key_url_strings) {
       GURL helper_key_url(url_string);
       if (!network::IsUrlPotentiallyTrustworthy(helper_key_url)) {
         LOG(ERROR) << "Helper key URL " << url_string