Commit 28110cf5 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Add mojom and typemap for Cache Storage API

This is part of converting the follwoing IPC messages to Mojo:
https://cs.chromium.org/chromium/src/content/common/cache_storage/cache_storage_messages.h

This is a continuation of http://crrev.com/c/906046 .

This has been split from http://crrev.com/c/875510 .

In service_worker_types.h removed an include to avoid circular
includes also added include <vector> to fix lint error.

Bug: 612287
Change-Id: Ifdd96596c709abc9f5e91b900bf21ee72f4a2b27
Reviewed-on: https://chromium-review.googlesource.com/906164
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536931}
parent 9f24f067
......@@ -6,5 +6,11 @@ jsbell@chromium.org
per-file *_messages*.h=set noparent
per-file *_messages*.h=file://ipc/SECURITY_OWNERS
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
# TEAM: storage-dev@chromium.org
# COMPONENT: Blink>Storage>CacheStorage
# Copyright 2018 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.
mojom = "//third_party/WebKit/public/platform/modules/cache_storage/cache_storage.mojom"
public_headers = [
"//content/common/cache_storage/cache_storage_types.h",
"//content/common/service_worker/service_worker_types.h",
]
traits_headers =
[ "//content/common/cache_storage/cache_storage_mojom_traits.h" ]
sources = [
"//content/common/cache_storage/cache_storage_mojom_traits.cc",
]
type_mappings = [
"blink.mojom.BatchOperation=content::CacheStorageBatchOperation",
"blink.mojom.OperationType=content::CacheStorageCacheOperationType",
"blink.mojom.QueryParams=content::CacheStorageCacheQueryParams",
]
// Copyright 2018 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 "content/common/cache_storage/cache_storage_mojom_traits.h"
#include "base/logging.h"
#include "content/public/common/referrer_struct_traits.h"
namespace mojo {
using blink::mojom::CacheStorageError;
using blink::mojom::OperationType;
OperationType
EnumTraits<OperationType, content::CacheStorageCacheOperationType>::ToMojom(
content::CacheStorageCacheOperationType input) {
switch (input) {
case content::CACHE_STORAGE_CACHE_OPERATION_TYPE_UNDEFINED:
return OperationType::kUndefined;
case content::CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT:
return OperationType::kPut;
case content::CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE:
return OperationType::kDelete;
}
NOTREACHED();
return OperationType::kUndefined;
}
bool EnumTraits<OperationType, content::CacheStorageCacheOperationType>::
FromMojom(OperationType input,
content::CacheStorageCacheOperationType* out) {
switch (input) {
case OperationType::kUndefined:
*out = content::CACHE_STORAGE_CACHE_OPERATION_TYPE_UNDEFINED;
return true;
case OperationType::kPut:
*out = content::CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
return true;
case OperationType::kDelete:
*out = content::CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE;
return true;
}
return false;
}
bool StructTraits<blink::mojom::QueryParamsDataView,
content::CacheStorageCacheQueryParams>::
Read(blink::mojom::QueryParamsDataView data,
content::CacheStorageCacheQueryParams* out) {
base::Optional<base::string16> cache_name;
if (!data.ReadCacheName(&cache_name))
return false;
out->cache_name = base::NullableString16(std::move(cache_name));
out->ignore_search = data.ignore_search();
out->ignore_method = data.ignore_method();
out->ignore_vary = data.ignore_vary();
return true;
}
bool StructTraits<blink::mojom::BatchOperationDataView,
content::CacheStorageBatchOperation>::
Read(blink::mojom::BatchOperationDataView data,
content::CacheStorageBatchOperation* out) {
if (!data.ReadRequest(&out->request))
return false;
if (!data.ReadResponse(&out->response))
return false;
if (!data.ReadMatchParams(&out->match_params))
return false;
if (!data.ReadOperationType(&out->operation_type))
return false;
return true;
}
} // namespace mojo
// Copyright 2018 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 CONTENT_COMMON_CACHE_STORAGE_CACHE_STORAGE_MOJOM_TRAITS_H_
#define CONTENT_COMMON_CACHE_STORAGE_CACHE_STORAGE_MOJOM_TRAITS_H_
#include <map>
#include <string>
#include <vector>
#include "base/optional.h"
#include "base/strings/string16.h"
#include "content/common/service_worker/service_worker_fetch_request_mojom_traits.h"
#include "content/common/service_worker/service_worker_fetch_response_mojom_traits.h"
#include "content/common/service_worker/service_worker_types.h"
#include "mojo/public/cpp/base/string16_mojom_traits.h"
#include "third_party/WebKit/public/platform/modules/cache_storage/cache_storage.mojom.h"
#include "url/gurl.h"
namespace mojo {
template <>
struct EnumTraits<blink::mojom::OperationType,
content::CacheStorageCacheOperationType> {
static blink::mojom::OperationType ToMojom(
content::CacheStorageCacheOperationType input);
static bool FromMojom(blink::mojom::OperationType input,
content::CacheStorageCacheOperationType* out);
};
template <>
struct StructTraits<blink::mojom::QueryParamsDataView,
content::CacheStorageCacheQueryParams> {
static bool ignore_search(
const content::CacheStorageCacheQueryParams& query_params) {
return query_params.ignore_search;
}
static bool ignore_method(
const content::CacheStorageCacheQueryParams& query_params) {
return query_params.ignore_method;
}
static bool ignore_vary(
const content::CacheStorageCacheQueryParams& query_params) {
return query_params.ignore_vary;
}
static const base::Optional<base::string16>& cache_name(
const content::CacheStorageCacheQueryParams& query_params) {
return query_params.cache_name.as_optional_string16();
}
static bool Read(blink::mojom::QueryParamsDataView,
content::CacheStorageCacheQueryParams* output);
};
template <>
struct StructTraits<blink::mojom::BatchOperationDataView,
content::CacheStorageBatchOperation> {
static content::CacheStorageCacheOperationType operation_type(
const content::CacheStorageBatchOperation& batch_operation) {
return batch_operation.operation_type;
}
static content::ServiceWorkerFetchRequest request(
const content::CacheStorageBatchOperation& batch_operation) {
return batch_operation.request;
}
static content::ServiceWorkerResponse response(
const content::CacheStorageBatchOperation& batch_operation) {
return batch_operation.response;
}
static content::CacheStorageCacheQueryParams match_params(
const content::CacheStorageBatchOperation& batch_operation) {
return batch_operation.match_params;
}
static bool Read(blink::mojom::BatchOperationDataView,
content::CacheStorageBatchOperation* output);
};
} // namespace mojo
#endif // CONTENT_COMMON_CACHE_STORAGE_CACHE_STORAGE_MOJOM_TRAITS_H_
......@@ -10,6 +10,7 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/strings/string_util.h"
#include "base/time/time.h"
......@@ -24,7 +25,6 @@
#include "third_party/WebKit/common/service_worker/service_worker_object.mojom.h"
#include "third_party/WebKit/common/service_worker/service_worker_registration.mojom.h"
#include "third_party/WebKit/common/service_worker/service_worker_state.mojom.h"
#include "third_party/WebKit/public/platform/modules/cache_storage/cache_storage.mojom.h"
#include "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom.h"
#include "url/gurl.h"
......
......@@ -4,6 +4,7 @@
typemaps = [
"//content/common/background_fetch/background_fetch_types.typemap",
"//content/common/cache_storage/cache_storage.typemap",
"//content/common/frame.typemap",
"//content/common/frame_messages.typemap",
"//content/common/media/media_devices.typemap",
......
......@@ -4,6 +4,10 @@
module blink.mojom;
import "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom";
import "third_party/WebKit/public/platform/modules/fetch/fetch_api_response.mojom";
import "mojo/public/mojom/base/string16.mojom";
// This enum is used in histograms, so do not change the ordering and always
// append new types to the end.
// See "CacheStorageErrorType" in enums.xml.
......@@ -20,3 +24,53 @@ enum CacheStorageError {
// Add new values here.
kLast = kErrorNotImplemented
};
// Controls how requests are matched in the Cache API.
struct QueryParams {
bool ignore_search;
bool ignore_method;
bool ignore_vary;
mojo_base.mojom.String16? cache_name;
};
// The type of a single batch operation in the Cache API.
enum OperationType {
kUndefined,
kPut,
kDelete,
};
// A single batch operation for the Cache API.
struct BatchOperation {
OperationType operation_type;
blink.mojom.FetchAPIRequest request;
blink.mojom.FetchAPIResponse response;
QueryParams match_params;
};
// Result of Open method. |status| is only set if there is a failure.
union OpenResult {
CacheStorageError status;
// TODO(lucmult): Enable attribute below when crrev.com/c/875510 is merged.
// associated CacheStorageCache cache;
};
// Result of Match for both interfaces CacheStorage and CacheStorageCache
// method. |status| is only set if there is a failure.
union MatchResult {
CacheStorageError status;
blink.mojom.FetchAPIResponse response;
};
// Result of MatchAll method |status| is only set if there is a failure.
union MatchAllResult {
CacheStorageError status;
array<blink.mojom.FetchAPIResponse> responses;
};
// Result of CacheStorageCache's Keys method. |status| is only set if there is a
// failure.
union CacheKeysResult {
CacheStorageError status;
array<blink.mojom.FetchAPIRequest> keys;
};
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