offline_store_utils.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "components/offline_pages/core/offline_store_utils.h"
  5. #include <limits>
  6. #include <string>
  7. #include "base/files/file_util.h"
  8. #include "base/rand_util.h"
  9. #include "base/time/time.h"
  10. namespace offline_pages {
  11. namespace store_utils {
  12. int64_t ToDatabaseTime(base::Time time) {
  13. return time.ToDeltaSinceWindowsEpoch().InMicroseconds();
  14. }
  15. base::Time FromDatabaseTime(int64_t serialized_time) {
  16. return base::Time::FromDeltaSinceWindowsEpoch(
  17. base::Microseconds(serialized_time));
  18. }
  19. std::string ToDatabaseFilePath(const base::FilePath& file_path) {
  20. return file_path.AsUTF8Unsafe();
  21. }
  22. base::FilePath FromDatabaseFilePath(const std::string& file_path_string) {
  23. return base::FilePath::FromUTF8Unsafe(file_path_string);
  24. }
  25. int64_t GenerateOfflineId() {
  26. // This is guaranteed to return positive since RandGenerator returns uint64_t.
  27. return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
  28. }
  29. } // namespace store_utils
  30. } // namespace offline_pages