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

Side by Side Diff: components/cryptauth/background_eid_generator.cc

Issue 2847233003: [EasyUnlock] Move DataWithTimestamp out of ForegroundEidGenerator so it can be shared. (Closed)
Patch Set: fixes Created 3 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cryptauth/background_eid_generator.h" 5 #include "components/cryptauth/background_eid_generator.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 base::MakeUnique<base::DefaultClock>()) {} 47 base::MakeUnique<base::DefaultClock>()) {}
48 48
49 BackgroundEidGenerator::~BackgroundEidGenerator() {} 49 BackgroundEidGenerator::~BackgroundEidGenerator() {}
50 50
51 BackgroundEidGenerator::BackgroundEidGenerator( 51 BackgroundEidGenerator::BackgroundEidGenerator(
52 std::unique_ptr<RawEidGenerator> raw_eid_generator, 52 std::unique_ptr<RawEidGenerator> raw_eid_generator,
53 std::unique_ptr<base::Clock> clock) 53 std::unique_ptr<base::Clock> clock)
54 : raw_eid_generator_(std::move(raw_eid_generator)), 54 : raw_eid_generator_(std::move(raw_eid_generator)),
55 clock_(std::move(clock)) {} 55 clock_(std::move(clock)) {}
56 56
57 std::vector<std::string> BackgroundEidGenerator::GenerateNearestEids( 57 std::vector<DataWithTimestamp> BackgroundEidGenerator::GenerateNearestEids(
58 const std::vector<BeaconSeed>& beacon_seeds) const { 58 const std::vector<BeaconSeed>& beacon_seeds) const {
59 int64_t now_timestamp_ms = clock_->Now().ToJavaTime(); 59 int64_t now_timestamp_ms = clock_->Now().ToJavaTime();
60 std::vector<std::string> eids; 60 std::vector<DataWithTimestamp> eids;
61 61
62 PA_LOG(INFO) << "Generating EIDs:";
63 for (int i = -kEidLookAhead; i <= kEidLookAhead; ++i) { 62 for (int i = -kEidLookAhead; i <= kEidLookAhead; ++i) {
64 int64_t timestamp_ms = now_timestamp_ms + i * kEidPeriodMs; 63 int64_t timestamp_ms = now_timestamp_ms + i * kEidPeriodMs;
65 std::unique_ptr<std::string> eid = GenerateEid(timestamp_ms, beacon_seeds); 64 std::unique_ptr<DataWithTimestamp> eid =
65 GenerateEid(timestamp_ms, beacon_seeds);
66 if (eid) 66 if (eid)
67 eids.push_back(*eid); 67 eids.push_back(*eid);
68 } 68 }
69 69
70 PA_LOG(INFO) << "Generated EIDs: " << DataWithTimestamp::ToDebugString(eids);
70 return eids; 71 return eids;
71 } 72 }
72 73
73 std::unique_ptr<std::string> BackgroundEidGenerator::GenerateEid( 74 std::unique_ptr<DataWithTimestamp> BackgroundEidGenerator::GenerateEid(
74 int64_t timestamp_ms, 75 int64_t timestamp_ms,
75 const std::vector<BeaconSeed>& beacon_seeds) const { 76 const std::vector<BeaconSeed>& beacon_seeds) const {
76 const BeaconSeed* beacon_seed = 77 const BeaconSeed* beacon_seed =
77 GetBeaconSeedForTimestamp(timestamp_ms, beacon_seeds); 78 GetBeaconSeedForTimestamp(timestamp_ms, beacon_seeds);
78 if (!beacon_seed) { 79 if (!beacon_seed) {
79 PA_LOG(INFO) << " " << timestamp_ms << ": outside of BeaconSeed range."; 80 PA_LOG(INFO) << " " << timestamp_ms << ": outside of BeaconSeed range.";
80 return nullptr; 81 return nullptr;
81 } 82 }
82 83
83 int64_t seed_start_time_ms = beacon_seed->start_time_millis(); 84 int64_t seed_start_time_ms = beacon_seed->start_time_millis();
84 int64_t offset_time_ms = timestamp_ms - seed_start_time_ms; 85 int64_t offset_time_ms = timestamp_ms - seed_start_time_ms;
85 int64_t start_of_period_ms = 86 int64_t start_of_period_ms =
86 seed_start_time_ms + (offset_time_ms / kEidPeriodMs) * kEidPeriodMs; 87 seed_start_time_ms + (offset_time_ms / kEidPeriodMs) * kEidPeriodMs;
87 88
88 std::string eid = raw_eid_generator_->GenerateEid( 89 std::string eid = raw_eid_generator_->GenerateEid(
89 beacon_seed->data(), start_of_period_ms, nullptr); 90 beacon_seed->data(), start_of_period_ms, nullptr);
90 91
91 PA_LOG(INFO) << " " << start_of_period_ms << ": " << eid; 92 return base::MakeUnique<DataWithTimestamp>(eid, start_of_period_ms,
92 return base::MakeUnique<std::string>(eid); 93 start_of_period_ms + kEidPeriodMs);
93 } 94 }
94 95
95 } // cryptauth 96 } // cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/background_eid_generator.h ('k') | components/cryptauth/background_eid_generator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698