content_record_password_state.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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
  3. // found in the LICENSE file.
  4. #include "components/sessions/content/content_record_password_state.h"
  5. #include "content/public/browser/navigation_entry.h"
  6. namespace sessions {
  7. namespace {
  8. // The key used to store PasswordState in the NavigationEntry;
  9. // We stash an enum value in the first character of the string16 that is
  10. // associated with this key.
  11. const char kPasswordStateKey[] = "sessions_password_state";
  12. class PasswordStateData : public base::SupportsUserData::Data {
  13. public:
  14. explicit PasswordStateData(
  15. SerializedNavigationEntry::PasswordState password_state)
  16. : password_state_(password_state) {}
  17. PasswordStateData(const PasswordStateData&) = delete;
  18. PasswordStateData& operator=(const PasswordStateData&) = delete;
  19. ~PasswordStateData() override = default;
  20. SerializedNavigationEntry::PasswordState password_state() const {
  21. return password_state_;
  22. }
  23. // base::SupportsUserData::Data:
  24. std::unique_ptr<Data> Clone() override {
  25. return std::make_unique<PasswordStateData>(password_state_);
  26. }
  27. private:
  28. const SerializedNavigationEntry::PasswordState password_state_;
  29. };
  30. } // namespace
  31. SerializedNavigationEntry::PasswordState GetPasswordStateFromNavigation(
  32. content::NavigationEntry* entry) {
  33. PasswordStateData* data =
  34. static_cast<PasswordStateData*>(entry->GetUserData(kPasswordStateKey));
  35. return data ? data->password_state()
  36. : SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN;
  37. }
  38. void SetPasswordStateInNavigation(
  39. SerializedNavigationEntry::PasswordState state,
  40. content::NavigationEntry* entry) {
  41. entry->SetUserData(kPasswordStateKey,
  42. std::make_unique<PasswordStateData>(state));
  43. }
  44. } // namespace sessions