Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: components/open_from_clipboard/clipboard_recent_content_ios.mm

Issue 954143004: Fix detection of clipboard change after device restart. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_ios.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/open_from_clipboard/clipboard_recent_content_ios.mm
diff --git a/components/open_from_clipboard/clipboard_recent_content_ios.mm b/components/open_from_clipboard/clipboard_recent_content_ios.mm
index 9ec6f0794d838ba970caeee98e846539f679b7b3..4cc2ed579532fd5626e2292c81bfee84a26f6151 100644
--- a/components/open_from_clipboard/clipboard_recent_content_ios.mm
+++ b/components/open_from_clipboard/clipboard_recent_content_ios.mm
@@ -11,6 +11,7 @@
#include "base/memory/singleton.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/sys_info.h"
#include "url/gurl.h"
#include "url/url_constants.h"
@@ -116,9 +117,14 @@ ClipboardRecentContentIOS::ClipboardRecentContentIOS()
: ClipboardRecentContent() {
urlFromPasteboardCache_ = URLFromPasteboard();
LoadFromUserDefaults();
- if ([UIPasteboard generalPasteboard].changeCount !=
- lastPasteboardChangeCount_) {
- PasteboardChanged();
+ // The pasteboard's changeCount is reset to zero when the device is restarted.
+ // This means that even if |changeCount| hasn't changed, the pasteboard
+ // content could have changed. In order to avoid missing pasteboard changes,
+ // the changeCount is reset if the device has restarted.
+ NSInteger changeCount = [UIPasteboard generalPasteboard].changeCount;
+ if (changeCount != lastPasteboardChangeCount_ ||
+ DeviceRestartedSincePasteboardChanged()) {
+ PasteboardChanged();
}
notificationBridge_.reset(
[[PasteboardNotificationListenerBridge alloc] initWithDelegate:this]);
@@ -160,3 +166,10 @@ void ClipboardRecentContentIOS::SaveToUserDefaults() {
[[NSUserDefaults standardUserDefaults] setObject:lastPasteboardChangeDate_
forKey:kPasteboardChangeDateKey];
}
+
+bool ClipboardRecentContentIOS::DeviceRestartedSincePasteboardChanged() {
+ int64 secondsSincePasteboardChange =
+ -static_cast<int64>([lastPasteboardChangeDate_ timeIntervalSinceNow]);
+ int64 secondsSinceLastDeviceRestart = base::SysInfo::Uptime() / 1000;
+ return secondsSincePasteboardChange > secondsSinceLastDeviceRestart;
+}
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_ios.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698