test_device_id_provider.cc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2019 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. #include "remoting/test/test_device_id_provider.h"
  5. #include <utility>
  6. #include "base/guid.h"
  7. #include "base/logging.h"
  8. #include "build/build_config.h"
  9. namespace remoting {
  10. namespace test {
  11. TestDeviceIdProvider::TestDeviceIdProvider(TokenStorage* token_storage)
  12. : token_storage_(token_storage) {
  13. DCHECK(token_storage_);
  14. }
  15. TestDeviceIdProvider::~TestDeviceIdProvider() = default;
  16. ftl::DeviceId TestDeviceIdProvider::GetDeviceId() {
  17. std::string id = token_storage_->FetchDeviceId();
  18. if (id.empty()) {
  19. id = "crd-test-" + base::GenerateGUID();
  20. VLOG(0) << "Generated new device_id: " << id;
  21. token_storage_->StoreDeviceId(id);
  22. } else {
  23. VLOG(0) << "Using stored device_id: " << id;
  24. }
  25. ftl::DeviceId device_id;
  26. device_id.set_type(ftl::DeviceIdType_Type_WEB_UUID);
  27. device_id.set_id(id);
  28. return device_id;
  29. }
  30. } // namespace test
  31. } // namespace remoting