OLD | NEW |
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/time/time.h" |
9 #include "components/open_from_clipboard/clipboard_recent_content.h" | 10 #include "components/open_from_clipboard/clipboard_recent_content.h" |
10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
11 | 12 |
12 @class NSDate; | 13 @class NSDate; |
| 14 @class NSUserDefaults; |
13 @class PasteboardNotificationListenerBridge; | 15 @class PasteboardNotificationListenerBridge; |
14 | 16 |
15 class ClipboardRecentContentIOSTest; | 17 class ClipboardRecentContentIOSTest; |
16 | 18 |
17 // IOS implementation of ClipboardRecentContent | 19 // IOS implementation of ClipboardRecentContent |
18 class ClipboardRecentContentIOS : public ClipboardRecentContent { | 20 class ClipboardRecentContentIOS : public ClipboardRecentContent { |
19 public: | 21 public: |
20 // |application_scheme| is the URL scheme that can be used to open the | 22 // |application_scheme| is the URL scheme that can be used to open the |
21 // current application, may be empty if no such scheme exists. Used to | 23 // current application, may be empty if no such scheme exists. Used to |
22 // determine whether or not the clipboard contains a relevant URL. | 24 // determine whether or not the clipboard contains a relevant URL. |
23 explicit ClipboardRecentContentIOS(const std::string& application_scheme); | 25 // |group_user_defaults| is the NSUserDefaults used to store information on |
| 26 // pasteboard entry expiration. This information will be shared with other |
| 27 // application in the application group. |
| 28 explicit ClipboardRecentContentIOS(const std::string& application_scheme, |
| 29 NSUserDefaults* group_user_defaults); |
24 ~ClipboardRecentContentIOS() override; | 30 ~ClipboardRecentContentIOS() override; |
25 | 31 |
26 // Notifies that the content of the pasteboard may have changed. | 32 // Notifies that the content of the pasteboard may have changed. |
27 void PasteboardChanged(); | 33 void PasteboardChanged(); |
28 | 34 |
| 35 // Checks if pasteboard changed since last time a pasteboard change was |
| 36 // registered. |
| 37 bool HasPasteboardChanged(base::TimeDelta uptime); |
| 38 |
| 39 // Loads information from the user defaults about the latest pasteboard entry. |
| 40 void LoadFromUserDefaults(); |
| 41 |
29 // ClipboardRecentContent implementation. | 42 // ClipboardRecentContent implementation. |
30 bool GetRecentURLFromClipboard(GURL* url) const override; | 43 bool GetRecentURLFromClipboard(GURL* url) const override; |
31 base::TimeDelta GetClipboardContentAge() const override; | 44 base::TimeDelta GetClipboardContentAge() const override; |
32 void SuppressClipboardContent() override; | 45 void SuppressClipboardContent() override; |
| 46 void RecentURLDisplayed() override; |
33 | 47 |
34 private: | 48 private: |
35 friend class ClipboardRecentContentIOSTest; | 49 friend class ClipboardRecentContentIOSTest; |
36 | 50 |
37 // Helper constructor for testing. |uptime| is how long ago the device has | 51 // Helper constructor for testing. |uptime| is how long ago the device has |
38 // started, while |application_scheme| has the same meaning as the public | 52 // started, while |application_scheme| has the same meaning as the public |
39 // constructor. | 53 // constructor. |
40 ClipboardRecentContentIOS(const std::string& application_scheme, | 54 ClipboardRecentContentIOS(const std::string& application_scheme, |
41 base::TimeDelta uptime); | 55 base::TimeDelta uptime); |
42 | 56 |
43 // Initializes the object. |uptime| is how long ago the device has started. | 57 // Initializes the object. |uptime| is how long ago the device has started. |
44 void Init(base::TimeDelta uptime); | 58 void Init(base::TimeDelta uptime); |
45 | 59 |
46 // Loads information from the user defaults about the latest pasteboard entry. | |
47 void LoadFromUserDefaults(); | |
48 | |
49 // Saves information to the user defaults about the latest pasteboard entry. | 60 // Saves information to the user defaults about the latest pasteboard entry. |
50 void SaveToUserDefaults(); | 61 void SaveToUserDefaults(); |
51 | 62 |
52 // Returns the URL contained in the clipboard (if any). | 63 // Returns the URL contained in the clipboard (if any). |
53 GURL URLFromPasteboard(); | 64 GURL URLFromPasteboard(); |
54 | 65 |
55 // Contains the URL scheme opening the app. May be empty. | 66 // Contains the URL scheme opening the app. May be empty. |
56 std::string application_scheme_; | 67 std::string application_scheme_; |
57 // The pasteboard's change count. Increases everytime the pasteboard changes. | 68 // The pasteboard's change count. Increases everytime the pasteboard changes. |
58 NSInteger lastPasteboardChangeCount_; | 69 NSInteger last_pasteboard_change_count_; |
59 // Estimation of the date when the pasteboard changed. | 70 // Estimation of the date when the pasteboard changed. |
60 base::scoped_nsobject<NSDate> lastPasteboardChangeDate_; | 71 base::scoped_nsobject<NSDate> last_pasteboard_change_date_; |
| 72 // Estimation of the copy date of the last displayed URL. |
| 73 base::scoped_nsobject<NSDate> last_displayed_pasteboard_entry_; |
| 74 // MD5 hash of the last registered pasteboard entry. |
| 75 base::scoped_nsobject<NSData> last_pasteboard_entry_md5_; |
61 // Cache of the GURL contained in the pasteboard (if any). | 76 // Cache of the GURL contained in the pasteboard (if any). |
62 GURL urlFromPasteboardCache_; | 77 GURL url_from_pasteboard_cache_; |
63 // A count identifying the suppressed pasteboard entry. Contains | |
64 // |NSIntegerMax| if there's no relevant entry to suppress. | |
65 NSInteger suppressedPasteboardEntryCount_; | |
66 // Bridge to receive notification when the pasteboard changes. | 78 // Bridge to receive notification when the pasteboard changes. |
67 base::scoped_nsobject<PasteboardNotificationListenerBridge> | 79 base::scoped_nsobject<PasteboardNotificationListenerBridge> |
68 notificationBridge_; | 80 notification_bridge_; |
| 81 // The user defaults from the app group used to optimize the pasteboard change |
| 82 // detection. |
| 83 base::scoped_nsobject<NSUserDefaults> shared_user_defaults_; |
69 | 84 |
70 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); | 85 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); |
71 }; | 86 }; |
72 | 87 |
73 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ | 88 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ |
OLD | NEW |