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

Side by Side Diff: components/open_from_clipboard/clipboard_recent_content_ios.mm

Issue 961673004: Add unittest to Open from Clipboard component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added error to check that the test is ran. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/open_from_clipboard/clipboard_recent_content_ios.h" 5 #include "components/open_from_clipboard/clipboard_recent_content_ios.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return false; 93 return false;
94 } 94 }
95 if (urlFromPasteboardCache_.is_valid()) { 95 if (urlFromPasteboardCache_.is_valid()) {
96 *url = urlFromPasteboardCache_; 96 *url = urlFromPasteboardCache_;
97 return true; 97 return true;
98 } 98 }
99 return false; 99 return false;
100 } 100 }
101 101
102 void ClipboardRecentContentIOS::PasteboardChanged() { 102 void ClipboardRecentContentIOS::PasteboardChanged() {
103 if ([UIPasteboard generalPasteboard].changeCount != 103 urlFromPasteboardCache_ = URLFromPasteboard();
104 lastPasteboardChangeCount_) { 104 if (!urlFromPasteboardCache_.is_empty()) {
105 urlFromPasteboardCache_ = URLFromPasteboard(); 105 base::RecordAction(
106 if (!urlFromPasteboardCache_.is_empty()) { 106 base::UserMetricsAction("MobileOmniboxClipboardChanged"));
107 base::RecordAction(
108 base::UserMetricsAction("MobileOmniboxClipboardChanged"));
109 }
110 lastPasteboardChangeDate_.reset([[NSDate date] retain]);
111 lastPasteboardChangeCount_ = [UIPasteboard generalPasteboard].changeCount;
112 SaveToUserDefaults();
113 } 107 }
108 lastPasteboardChangeDate_.reset([[NSDate date] retain]);
109 lastPasteboardChangeCount_ = [UIPasteboard generalPasteboard].changeCount;
110 SaveToUserDefaults();
114 } 111 }
115 112
116 ClipboardRecentContentIOS::ClipboardRecentContentIOS() 113 ClipboardRecentContentIOS::ClipboardRecentContentIOS()
117 : ClipboardRecentContent() { 114 : ClipboardRecentContent() {
118 urlFromPasteboardCache_ = URLFromPasteboard(); 115 urlFromPasteboardCache_ = URLFromPasteboard();
119 LoadFromUserDefaults(); 116 LoadFromUserDefaults();
120 // The pasteboard's changeCount is reset to zero when the device is restarted. 117 // The pasteboard's changeCount is reset to zero when the device is restarted.
121 // This means that even if |changeCount| hasn't changed, the pasteboard 118 // This means that even if |changeCount| hasn't changed, the pasteboard
122 // content could have changed. In order to avoid missing pasteboard changes, 119 // content could have changed. In order to avoid missing pasteboard changes,
123 // the changeCount is reset if the device has restarted. 120 // the changeCount is reset if the device has restarted.
124 NSInteger changeCount = [UIPasteboard generalPasteboard].changeCount; 121 NSInteger changeCount = [UIPasteboard generalPasteboard].changeCount;
125 if (changeCount != lastPasteboardChangeCount_ || 122 if (changeCount != lastPasteboardChangeCount_ ||
126 DeviceRestartedSincePasteboardChanged()) { 123 DeviceRestartedSincePasteboardChanged()) {
127 PasteboardChanged(); 124 PasteboardChanged();
128 } 125 }
129 notificationBridge_.reset( 126 notificationBridge_.reset(
130 [[PasteboardNotificationListenerBridge alloc] initWithDelegate:this]); 127 [[PasteboardNotificationListenerBridge alloc] initWithDelegate:this]);
131 } 128 }
132 129
133 ClipboardRecentContentIOS::~ClipboardRecentContentIOS() { 130 ClipboardRecentContentIOS::~ClipboardRecentContentIOS() {
134 } 131 }
135 132
136 GURL ClipboardRecentContentIOS::URLFromPasteboard() { 133 GURL ClipboardRecentContentIOS::URLFromPasteboard() {
137 const std::string clipboard = 134 const std::string clipboard =
(...skipping 28 matching lines...) Expand all
166 [[NSUserDefaults standardUserDefaults] setObject:lastPasteboardChangeDate_ 163 [[NSUserDefaults standardUserDefaults] setObject:lastPasteboardChangeDate_
167 forKey:kPasteboardChangeDateKey]; 164 forKey:kPasteboardChangeDateKey];
168 } 165 }
169 166
170 bool ClipboardRecentContentIOS::DeviceRestartedSincePasteboardChanged() { 167 bool ClipboardRecentContentIOS::DeviceRestartedSincePasteboardChanged() {
171 int64 secondsSincePasteboardChange = 168 int64 secondsSincePasteboardChange =
172 -static_cast<int64>([lastPasteboardChangeDate_ timeIntervalSinceNow]); 169 -static_cast<int64>([lastPasteboardChangeDate_ timeIntervalSinceNow]);
173 int64 secondsSinceLastDeviceRestart = base::SysInfo::Uptime() / 1000; 170 int64 secondsSinceLastDeviceRestart = base::SysInfo::Uptime() / 1000;
174 return secondsSincePasteboardChange > secondsSinceLastDeviceRestart; 171 return secondsSincePasteboardChange > secondsSinceLastDeviceRestart;
175 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698