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

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

Issue 2230983002: Stop using UIPasteboardChangedNotification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 #ifndef COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ 5 #ifndef COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
6 #define COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ 6 #define COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
7 7
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/open_from_clipboard/clipboard_recent_content.h" 11 #include "components/open_from_clipboard/clipboard_recent_content.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 @class NSDate; 14 @class NSDate;
15 @class NSUserDefaults; 15 @class NSUserDefaults;
16 @class PasteboardNotificationListenerBridge; 16 @class ApplicationDidBecomeActiveNotificationListenerBridge;
17 17
18 class ClipboardRecentContentIOSTest; 18 class ClipboardRecentContentIOSTest;
19 19
20 // IOS implementation of ClipboardRecentContent 20 // IOS implementation of ClipboardRecentContent
21 class ClipboardRecentContentIOS : public ClipboardRecentContent { 21 class ClipboardRecentContentIOS : public ClipboardRecentContent {
22 public: 22 public:
23 // |application_scheme| is the URL scheme that can be used to open the 23 // |application_scheme| is the URL scheme that can be used to open the
24 // current application, may be empty if no such scheme exists. Used to 24 // current application, may be empty if no such scheme exists. Used to
25 // determine whether or not the clipboard contains a relevant URL. 25 // determine whether or not the clipboard contains a relevant URL.
26 // |group_user_defaults| is the NSUserDefaults used to store information on 26 // |group_user_defaults| is the NSUserDefaults used to store information on
27 // pasteboard entry expiration. This information will be shared with other 27 // pasteboard entry expiration. This information will be shared with other
28 // application in the application group. 28 // application in the application group.
29 explicit ClipboardRecentContentIOS(const std::string& application_scheme, 29 explicit ClipboardRecentContentIOS(const std::string& application_scheme,
30 NSUserDefaults* group_user_defaults); 30 NSUserDefaults* group_user_defaults);
31 ~ClipboardRecentContentIOS() override; 31 ~ClipboardRecentContentIOS() override;
32 32
33 // Notifies that the content of the pasteboard may have changed. 33 // Checks if the content of the pasteboard has changed. Updates the change
34 void PasteboardChanged(); 34 // count, change date, and md5 of the latest pasteboard entry if necessary.
35 void CheckIfPasteboardChanged();
Olivier 2016/08/10 13:46:41 Check... is not a name for a method that updates t
jif-google 2016/08/11 13:39:55 Done. UpdatePasteboardIfNeeded sucked, so I simply
35 36
36 // Checks if pasteboard changed since last time a pasteboard change was 37 // Returns whether the pasteboard changed since the last time a pasteboard
37 // registered. 38 // change was detected.
38 bool HasPasteboardChanged(base::TimeDelta uptime); 39 bool HasPasteboardChanged() const;
39
40 // Gets the current URL in the clipboard. If the cache is out of date, updates
41 // it.
42 bool GetCurrentURLFromClipboard(GURL* url);
43 40
44 // Loads information from the user defaults about the latest pasteboard entry. 41 // Loads information from the user defaults about the latest pasteboard entry.
45 void LoadFromUserDefaults(); 42 void LoadFromUserDefaults();
46 43
47 // ClipboardRecentContent implementation. 44 // ClipboardRecentContent implementation.
48 bool GetRecentURLFromClipboard(GURL* url) const override; 45 bool GetRecentURLFromClipboard(GURL* url) override;
49
50 base::TimeDelta GetClipboardContentAge() const override; 46 base::TimeDelta GetClipboardContentAge() const override;
51 void SuppressClipboardContent() override; 47 void SuppressClipboardContent() override;
52 void RecentURLDisplayed() override;
53 48
54 private: 49 private:
55 friend class ClipboardRecentContentIOSTest; 50 friend class ClipboardRecentContentIOSTest;
56 51
57 // Helper constructor for testing. |uptime| is how long ago the device has 52 // Returns the uptime. Override in tests to return custom value.
58 // started, while |application_scheme| has the same meaning as the public 53 virtual base::TimeDelta Uptime() const;
59 // constructor.
60 ClipboardRecentContentIOS(const std::string& application_scheme,
61 base::TimeDelta uptime);
62
63 // Initializes the object. |uptime| is how long ago the device has started.
64 void Init(base::TimeDelta uptime);
65 54
66 // Saves information to the user defaults about the latest pasteboard entry. 55 // Saves information to the user defaults about the latest pasteboard entry.
67 void SaveToUserDefaults(); 56 void SaveToUserDefaults();
68 57
69 // Returns the URL contained in the clipboard (if any). 58 // Returns the URL contained in the clipboard (if any).
70 GURL URLFromPasteboard(); 59 GURL URLFromPasteboard();
71 60
72 // Contains the URL scheme opening the app. May be empty. 61 // Contains the URL scheme opening the app. May be empty.
73 std::string application_scheme_; 62 std::string application_scheme_;
74 // The pasteboard's change count. Increases everytime the pasteboard changes. 63 // The pasteboard's change count. Increases everytime the pasteboard changes.
75 NSInteger last_pasteboard_change_count_; 64 NSInteger last_pasteboard_change_count_;
76 // Estimation of the date when the pasteboard changed. 65 // Estimation of the date when the pasteboard changed.
77 base::scoped_nsobject<NSDate> last_pasteboard_change_date_; 66 base::scoped_nsobject<NSDate> last_pasteboard_change_date_;
78 // Estimation of the copy date of the last displayed URL.
79 base::scoped_nsobject<NSDate> last_displayed_pasteboard_entry_;
80 // MD5 hash of the last registered pasteboard entry. 67 // MD5 hash of the last registered pasteboard entry.
81 base::scoped_nsobject<NSData> last_pasteboard_entry_md5_; 68 base::scoped_nsobject<NSData> last_pasteboard_entry_md5_;
82 // Cache of the GURL contained in the pasteboard (if any). 69 // Bridge to receive notifications when the application becomes active.
83 GURL url_from_pasteboard_cache_; 70 base::scoped_nsobject<ApplicationDidBecomeActiveNotificationListenerBridge>
84 // Bridge to receive notification when the pasteboard changes.
85 base::scoped_nsobject<PasteboardNotificationListenerBridge>
86 notification_bridge_; 71 notification_bridge_;
87 // The user defaults from the app group used to optimize the pasteboard change 72 // The user defaults from the app group used to optimize the pasteboard change
88 // detection. 73 // detection.
89 base::scoped_nsobject<NSUserDefaults> shared_user_defaults_; 74 base::scoped_nsobject<NSUserDefaults> shared_user_defaults_;
90 75
91 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); 76 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS);
92 }; 77 };
93 78
94 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ 79 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698