Index: chrome_frame/turndown_prompt/reshow_state.cc |
diff --git a/chrome_frame/turndown_prompt/reshow_state.cc b/chrome_frame/turndown_prompt/reshow_state.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..51b59258ef5cb552c3c47dd0476a8c040a3fa85a |
--- /dev/null |
+++ b/chrome_frame/turndown_prompt/reshow_state.cc |
@@ -0,0 +1,50 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome_frame/turndown_prompt/reshow_state.h" |
+ |
+#include "base/win/registry.h" |
+#include "chrome_frame/utils.h" |
+ |
+namespace { |
+ |
+const wchar_t kTurndownPromptLastShown[] = L"TurndownPromptLastShown"; |
+ |
+} |
+ |
+namespace turndown_prompt { |
+ |
+ReshowState::ReshowState(const string16& key_path, |
+ const base::TimeDelta& reshow_delta) |
+ : key_path_(key_path), |
+ reshow_delta_(reshow_delta) { |
+} |
+ |
+ReshowState::~ReshowState() { |
+} |
+ |
+bool ReshowState::HasReshowDeltaExpired(const base::Time& current_time) const { |
+ int64 last_shown = GetConfigInt64(0LL, kTurndownPromptLastShown); |
+ if (!last_shown) |
+ return true; |
+ |
+ FILETIME last_shown_filetime; |
+ last_shown_filetime.dwLowDateTime = |
+ static_cast<DWORD>(last_shown & kuint32max); |
+ last_shown_filetime.dwHighDateTime = |
+ static_cast<DWORD>((static_cast<uint64>(last_shown) >> 32) & kuint32max); |
+ base::Time last_shown_time(base::Time::FromFileTime(last_shown_filetime)); |
+ |
+ return current_time - last_shown_time >= reshow_delta_; |
+} |
+ |
+void ReshowState::MarkShown(const base::Time& last_shown_time) { |
+ FILETIME last_shown_filetime = last_shown_time.ToFileTime(); |
robertshield
2013/06/19 23:36:33
Any reason not to use Time::ToInternalValue() and
grt (UTC plus 2)
2013/06/20 19:55:29
Ah. I used FILETIME since that's common in the Win
|
+ int64 last_shown = |
+ (static_cast<int64>(last_shown_filetime.dwHighDateTime) << 32) | |
+ static_cast<int64>(last_shown_filetime.dwLowDateTime); |
+ SetConfigInt64(kTurndownPromptLastShown, last_shown); |
+} |
+ |
+} // namespace turndown_prompt |