Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: components/precache/core/precache_manifest_util.cc

Issue 2802053002: precache: Extract common methods for PrecacheManifest into util. (Closed)
Patch Set: Copyright. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/precache/core/precache_manifest_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/precache/core/precache_manifest_util.cc
diff --git a/components/precache/core/precache_manifest_util.cc b/components/precache/core/precache_manifest_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..668a77fecb2c3e1f8e8dccd189c3ae428902d25e
--- /dev/null
+++ b/components/precache/core/precache_manifest_util.cc
@@ -0,0 +1,60 @@
+// Copyright 2017 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/precache/core/precache_manifest_util.h"
+
+#include <string>
+
+#include "components/precache/core/proto/precache.pb.h"
+
+namespace precache {
+
+void RemoveUnknownFields(PrecacheManifest* manifest) {
+ manifest->mutable_unknown_fields()->clear();
+ for (auto& resource : *manifest->mutable_resource())
+ resource.mutable_unknown_fields()->clear();
+ if (manifest->has_experiments()) {
+ manifest->mutable_experiments()->mutable_unknown_fields()->clear();
+ for (auto& kv : *manifest->mutable_experiments()
+ ->mutable_resources_by_experiment_group()) {
+ kv.second.mutable_unknown_fields()->clear();
+ }
+ }
+ if (manifest->has_id())
+ manifest->mutable_id()->mutable_unknown_fields()->clear();
+}
+
+base::Optional<std::vector<bool>> GetResourceBitset(
+ const PrecacheManifest& manifest,
+ uint32_t experiment_id) {
+ base::Optional<std::vector<bool>> ret;
+ if (manifest.has_experiments()) {
+ const auto& resource_bitset_map =
+ manifest.experiments().resources_by_experiment_group();
+ const auto& it = resource_bitset_map.find(experiment_id);
+ if (it != resource_bitset_map.end()) {
+ if (it->second.has_bitset()) {
+ const std::string& bitset = it->second.bitset();
+ ret.emplace(bitset.size() * 8);
+ for (size_t i = 0; i < bitset.size(); ++i) {
+ for (size_t j = 0; j < 8; ++j) {
+ if ((1 << j) & bitset[i])
+ ret.value()[i * 8 + j] = true;
+ }
+ }
+ } else if (it->second.has_deprecated_bitset()) {
+ uint64_t bitset = it->second.deprecated_bitset();
+ ret.emplace(64);
+ for (int i = 0; i < 64; ++i) {
+ if ((0x1ULL << i) & bitset)
+ ret.value()[i] = true;
+ }
+ }
+ }
+ }
+ // Only return one variable to ensure RVO triggers.
+ return ret;
+}
+
+} // namespace precache
« no previous file with comments | « components/precache/core/precache_manifest_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698