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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/precache/core/precache_manifest_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/precache/core/precache_manifest_util.h"
6
7 #include <string>
8
9 #include "components/precache/core/proto/precache.pb.h"
10
11 namespace precache {
12
13 void RemoveUnknownFields(PrecacheManifest* manifest) {
14 manifest->mutable_unknown_fields()->clear();
15 for (auto& resource : *manifest->mutable_resource())
16 resource.mutable_unknown_fields()->clear();
17 if (manifest->has_experiments()) {
18 manifest->mutable_experiments()->mutable_unknown_fields()->clear();
19 for (auto& kv : *manifest->mutable_experiments()
20 ->mutable_resources_by_experiment_group()) {
21 kv.second.mutable_unknown_fields()->clear();
22 }
23 }
24 if (manifest->has_id())
25 manifest->mutable_id()->mutable_unknown_fields()->clear();
26 }
27
28 base::Optional<std::vector<bool>> GetResourceBitset(
29 const PrecacheManifest& manifest,
30 uint32_t experiment_id) {
31 base::Optional<std::vector<bool>> ret;
32 if (manifest.has_experiments()) {
33 const auto& resource_bitset_map =
34 manifest.experiments().resources_by_experiment_group();
35 const auto& it = resource_bitset_map.find(experiment_id);
36 if (it != resource_bitset_map.end()) {
37 if (it->second.has_bitset()) {
38 const std::string& bitset = it->second.bitset();
39 ret.emplace(bitset.size() * 8);
40 for (size_t i = 0; i < bitset.size(); ++i) {
41 for (size_t j = 0; j < 8; ++j) {
42 if ((1 << j) & bitset[i])
43 ret.value()[i * 8 + j] = true;
44 }
45 }
46 } else if (it->second.has_deprecated_bitset()) {
47 uint64_t bitset = it->second.deprecated_bitset();
48 ret.emplace(64);
49 for (int i = 0; i < 64; ++i) {
50 if ((0x1ULL << i) & bitset)
51 ret.value()[i] = true;
52 }
53 }
54 }
55 }
56 // Only return one variable to ensure RVO triggers.
57 return ret;
58 }
59
60 } // namespace precache
OLDNEW
« 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