
The changes of this CL are made using the following script. ``` target_directory="content/browser" replace_string_in_files() { old_string="$1" new_string="$2" find "$target_directory" -type f \( -name "*.cc" -o -name "*.h" \) \ -exec sed -i '' "s/$old_string/$new_string/g" {} + } delete_include() { find "$target_directory" \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do grep -v '#include "base/strings/string_piece.h"' "$file" > "$file.tmp" && mv "$file.tmp" "$file" done } add_include() { find "$target_directory" \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do local include_added=false local tempfile=$(mktemp) if grep -qE 'std::(string|u16string)_view' "$file"; then while IFS= read -r line; do echo "$line" >> "$tempfile" if [[ $line =~ ^\s*#include ]]; then if ! $include_added; then echo "#include <string_view>" >> "$tempfile" include_added=true fi fi done < "$file" mv "$tempfile" "$file" if $include_added; then echo "Added #include <string_view> after the first include line in $file" else echo "No include line found in $file" fi else echo "std::string_view not found in $file" fi done } replace_string_in_files "base::StringPiece16" "std::u16string_view" replace_string_in_files "base::StringPiece" "std::string_view" delete_include add_include ``` Replaced base::StringPiece16 with std::u16string_view Replaced base::StringPiece with std::string_view Removed header "base/strings/string_piece.h" Added header "<string_view>" where applicable Bug: 40506050 Change-Id: I2bc22c79dd9a0c839745afe065123f7a53c4a5ca Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5401117 Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Mike West <mkwst@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Reviewed-by: Will Harris <wfh@chromium.org> Cr-Commit-Position: refs/heads/main@{#1281746}
92 lines
3.8 KiB
C++
92 lines
3.8 KiB
C++
// Copyright 2020 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef CONTENT_BROWSER_MOJO_BINDER_POLICY_MAP_IMPL_H_
|
|
#define CONTENT_BROWSER_MOJO_BINDER_POLICY_MAP_IMPL_H_
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "base/containers/flat_map.h"
|
|
#include "content/common/content_export.h"
|
|
#include "content/public/browser/mojo_binder_policy_map.h"
|
|
|
|
namespace content {
|
|
|
|
// Implements MojoBinderPolicyMap and owns a policy map.
|
|
class CONTENT_EXPORT MojoBinderPolicyMapImpl : public MojoBinderPolicyMap {
|
|
public:
|
|
MojoBinderPolicyMapImpl();
|
|
|
|
// This constructor is for testing.
|
|
explicit MojoBinderPolicyMapImpl(
|
|
const base::flat_map<std::string, MojoBinderNonAssociatedPolicy>&
|
|
init_map);
|
|
~MojoBinderPolicyMapImpl() override;
|
|
|
|
// Disallows copy and move operations.
|
|
MojoBinderPolicyMapImpl(const MojoBinderPolicyMapImpl& other) = delete;
|
|
MojoBinderPolicyMapImpl& operator=(const MojoBinderPolicyMapImpl& other) =
|
|
delete;
|
|
MojoBinderPolicyMapImpl(MojoBinderPolicyMapImpl&&) = delete;
|
|
MojoBinderPolicyMapImpl& operator=(MojoBinderPolicyMapImpl&&) = delete;
|
|
|
|
// Returns the instance used by MojoBinderPolicyApplier for prerendering
|
|
// pages.
|
|
// This is used when the prerendered page and the page that triggered the
|
|
// prerendering are same origin. Currently this is the only use of this class.
|
|
static const MojoBinderPolicyMapImpl* GetInstanceForSameOriginPrerendering();
|
|
|
|
// Returns the instance used by MojoBinderPolicyApplier for preview mode. This
|
|
// is used when a page is shown in preview mode.
|
|
static const MojoBinderPolicyMapImpl* GetInstanceForPreview();
|
|
|
|
// Gets the corresponding policy of a given Mojo interface name.
|
|
// If the interface name is not in `non_associated_policy_map_`, the given
|
|
// `default_policy` will be returned.
|
|
// Callers should ensure that the corresponding interface is used as a
|
|
// non-associated interface in the context. If the interface is used as a
|
|
// channel-associated interface, they should call
|
|
// `GetAssociatedMojoBinderPolicy`.
|
|
MojoBinderNonAssociatedPolicy GetNonAssociatedMojoBinderPolicy(
|
|
const std::string& interface_name,
|
|
const MojoBinderNonAssociatedPolicy default_policy) const;
|
|
|
|
// Gets the corresponding policy of a given Mojo interface name.
|
|
// If the interface name is not in `associated_policy_map_`, the given
|
|
// `default_policy` will be returned.
|
|
// Callers should ensure that the corresponding interface is used as a
|
|
// channel-associated interface in the context. If the interface is used as a
|
|
// non-associated interface, they should call
|
|
// `GetNonAssociatedMojoBinderPolicy`.
|
|
MojoBinderAssociatedPolicy GetAssociatedMojoBinderPolicy(
|
|
const std::string& interface_name,
|
|
const MojoBinderAssociatedPolicy default_policy) const;
|
|
|
|
// Fails with DCHECK if the interface is not in `non_associated_policy_map_`.
|
|
MojoBinderNonAssociatedPolicy GetNonAssociatedMojoBinderPolicyOrDieForTesting(
|
|
const std::string& interface_name) const;
|
|
|
|
// Fails with DCHECK if the interface is not in `associated_policy_map_`.
|
|
MojoBinderAssociatedPolicy GetAssociatedMojoBinderPolicyOrDieForTesting(
|
|
const std::string& interface_name) const;
|
|
|
|
private:
|
|
// MojoBinderPolicyMap implementation:
|
|
void SetPolicyByName(const std::string_view& name,
|
|
MojoBinderAssociatedPolicy policy) override;
|
|
|
|
void SetPolicyByName(const std::string_view& name,
|
|
MojoBinderNonAssociatedPolicy policy) override;
|
|
|
|
base::flat_map<std::string, MojoBinderNonAssociatedPolicy>
|
|
non_associated_policy_map_;
|
|
base::flat_map<std::string, MojoBinderAssociatedPolicy>
|
|
associated_policy_map_;
|
|
};
|
|
|
|
} // namespace content
|
|
|
|
#endif // CONTENT_BROWSER_MOJO_BINDER_POLICY_MAP_IMPL_H_
|