Commit 346ef5e4 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Make DirectoryKey a class

The previous implementation of DirectoryKey used a const string making
it largely incompatible with <algorithm> which I intend to make use of
in a few places. To fix this it should be made into a class that can
be copied and swapped, but with only a constant accessor.

Bug: 1058093
Change-Id: Ib3aff42e248910bd78b9a00c98777fd670999d37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084724Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746501}
parent 668d7b0e
...@@ -10,6 +10,8 @@ source_set("browser") { ...@@ -10,6 +10,8 @@ source_set("browser") {
sources = [ sources = [
"compositor_utils.cc", "compositor_utils.cc",
"compositor_utils.h", "compositor_utils.h",
"directory_key.cc",
"directory_key.h",
"file_manager.cc", "file_manager.cc",
"file_manager.h", "file_manager.h",
"hit_tester.cc", "hit_tester.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/paint_preview/browser/directory_key.h"
namespace paint_preview {
bool operator<(const DirectoryKey& a, const DirectoryKey& b) {
return a.AsciiDirname() < b.AsciiDirname();
}
} // namespace paint_preview
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAINT_PREVIEW_BROWSER_DIRECTORY_KEY_H_
#define COMPONENTS_PAINT_PREVIEW_BROWSER_DIRECTORY_KEY_H_
#include <string>
#include "base/strings/string_piece.h"
namespace paint_preview {
// A key for a specific subdirectory (== captured paint preview).
class DirectoryKey {
public:
DirectoryKey() = default;
explicit DirectoryKey(base::StringPiece ascii_dirname)
: ascii_dirname_(ascii_dirname) {}
~DirectoryKey() = default;
const std::string& AsciiDirname() const { return ascii_dirname_; }
private:
std::string ascii_dirname_;
};
bool operator<(const DirectoryKey& a, const DirectoryKey& b);
} // namespace paint_preview
#endif // COMPONENTS_PAINT_PREVIEW_BROWSER_DIRECTORY_KEY_H_
...@@ -40,7 +40,7 @@ size_t FileManager::GetSizeOfArtifacts(const DirectoryKey& key) { ...@@ -40,7 +40,7 @@ size_t FileManager::GetSizeOfArtifacts(const DirectoryKey& key) {
switch (storage_type) { switch (storage_type) {
case kDirectory: { case kDirectory: {
return base::ComputeDirectorySize( return base::ComputeDirectorySize(
root_directory_.AppendASCII(key.ascii_dirname)); root_directory_.AppendASCII(key.AsciiDirname()));
} }
case kZip: { case kZip: {
int64_t file_size = 0; int64_t file_size = 0;
...@@ -91,7 +91,7 @@ bool FileManager::CreateOrGetDirectory(const DirectoryKey& key, ...@@ -91,7 +91,7 @@ bool FileManager::CreateOrGetDirectory(const DirectoryKey& key,
StorageType storage_type = GetPathForKey(key, &path); StorageType storage_type = GetPathForKey(key, &path);
switch (storage_type) { switch (storage_type) {
case kNone: { case kNone: {
base::FilePath new_path = root_directory_.AppendASCII(key.ascii_dirname); base::FilePath new_path = root_directory_.AppendASCII(key.AsciiDirname());
base::File::Error error = base::File::FILE_OK; base::File::Error error = base::File::FILE_OK;
if (base::CreateDirectoryAndGetError(new_path, &error)) { if (base::CreateDirectoryAndGetError(new_path, &error)) {
*directory = new_path; *directory = new_path;
...@@ -106,7 +106,7 @@ bool FileManager::CreateOrGetDirectory(const DirectoryKey& key, ...@@ -106,7 +106,7 @@ bool FileManager::CreateOrGetDirectory(const DirectoryKey& key,
return true; return true;
} }
case kZip: { case kZip: {
base::FilePath dst_path = root_directory_.AppendASCII(key.ascii_dirname); base::FilePath dst_path = root_directory_.AppendASCII(key.AsciiDirname());
base::File::Error error = base::File::FILE_OK; base::File::Error error = base::File::FILE_OK;
if (!base::CreateDirectoryAndGetError(dst_path, &error)) { if (!base::CreateDirectoryAndGetError(dst_path, &error)) {
DVLOG(1) << "ERROR: failed to create directory: " << path DVLOG(1) << "ERROR: failed to create directory: " << path
...@@ -185,7 +185,7 @@ std::unique_ptr<PaintPreviewProto> FileManager::DeserializePaintPreviewProto( ...@@ -185,7 +185,7 @@ std::unique_ptr<PaintPreviewProto> FileManager::DeserializePaintPreviewProto(
FileManager::StorageType FileManager::GetPathForKey(const DirectoryKey& key, FileManager::StorageType FileManager::GetPathForKey(const DirectoryKey& key,
base::FilePath* path) { base::FilePath* path) {
base::FilePath directory_path = base::FilePath directory_path =
root_directory_.AppendASCII(key.ascii_dirname); root_directory_.AppendASCII(key.AsciiDirname());
if (base::PathExists(directory_path)) { if (base::PathExists(directory_path)) {
*path = directory_path; *path = directory_path;
return kDirectory; return kDirectory;
......
...@@ -5,19 +5,14 @@ ...@@ -5,19 +5,14 @@
#ifndef COMPONENTS_PAINT_PREVIEW_BROWSER_FILE_MANAGER_H_ #ifndef COMPONENTS_PAINT_PREVIEW_BROWSER_FILE_MANAGER_H_
#define COMPONENTS_PAINT_PREVIEW_BROWSER_FILE_MANAGER_H_ #define COMPONENTS_PAINT_PREVIEW_BROWSER_FILE_MANAGER_H_
#include <string>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/paint_preview/browser/directory_key.h"
#include "components/paint_preview/common/proto/paint_preview.pb.h" #include "components/paint_preview/common/proto/paint_preview.pb.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace paint_preview { namespace paint_preview {
struct DirectoryKey {
const std::string ascii_dirname;
};
// Manages paint preview files associated with a root directory typically the // Manages paint preview files associated with a root directory typically the
// root directory is <profile_dir>/paint_previews/<feature>. // root directory is <profile_dir>/paint_previews/<feature>.
class FileManager { class FileManager {
......
...@@ -24,7 +24,7 @@ class SkBitmap; ...@@ -24,7 +24,7 @@ class SkBitmap;
namespace paint_preview { namespace paint_preview {
struct DirectoryKey; class DirectoryKey;
class PlayerCompositorDelegate { class PlayerCompositorDelegate {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment