1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_STRUCTURED_TEST_TEST_KEY_DATA_PROVIDER_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_TEST_TEST_KEY_DATA_PROVIDER_H_ 7 8 #include <memory> 9 #include <optional> 10 #include <string> 11 12 #include "base/functional/callback_forward.h" 13 #include "components/metrics/structured/lib/key_data_provider.h" 14 15 namespace base { 16 class FilePath; 17 } 18 19 namespace metrics::structured { 20 21 // Test implementation for KeyDataProvider. 22 // 23 // If only the |device_key_path| is provided in the ctor, then 24 // |profile_key_data_| will be empty until InitializeProfileKey is called and 25 // created in specified path |profile_path|. If |profile_key_path| is provided 26 // in the ctor, then |profile_path| provided in InitializeProfileKey will be 27 // ignored. 28 class TestKeyDataProvider : public KeyDataProvider, KeyDataProvider::Observer { 29 public: 30 explicit TestKeyDataProvider(const base::FilePath& device_key_path); 31 TestKeyDataProvider(const base::FilePath& device_key_path, 32 const base::FilePath& profile_key_path); 33 ~TestKeyDataProvider() override; 34 35 // KeyDataProvider: 36 bool IsReady() override; 37 std::optional<uint64_t> GetId(const std::string& project_name) override; 38 std::optional<uint64_t> GetSecondaryId( 39 const std::string& project_name) override; 40 KeyData* GetKeyData(const std::string& project_name) override; 41 void Purge() override; 42 43 // KeyDataProvider::Observer 44 void OnKeyReady() override; 45 46 void OnProfileAdded(const base::FilePath& profile_path); 47 48 private: 49 base::FilePath device_key_path_; 50 base::FilePath profile_key_path_; 51 52 std::unique_ptr<KeyDataProvider> device_key_data_; 53 std::unique_ptr<KeyDataProvider> profile_key_data_; 54 }; 55 56 } // namespace metrics::structured 57 58 #endif // COMPONENTS_METRICS_STRUCTURED_TEST_TEST_KEY_DATA_PROVIDER_H_ 59