Chromium Code Reviews| 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; |
| 44 | |
|
droger
2015/08/13 11:42:21
Remove blank line.
Olivier
2015/08/13 12:01:58
Done.
| |
| 31 base::TimeDelta GetClipboardContentAge() const override; | 45 base::TimeDelta GetClipboardContentAge() const override; |
| 32 void SuppressClipboardContent() override; | 46 void SuppressClipboardContent() override; |
| 47 void RecentURLDisplayed() override; | |
| 33 | 48 |
| 34 private: | 49 private: |
| 35 friend class ClipboardRecentContentIOSTest; | 50 friend class ClipboardRecentContentIOSTest; |
| 36 | 51 |
| 37 // Helper constructor for testing. |uptime| is how long ago the device has | 52 // Helper constructor for testing. |uptime| is how long ago the device has |
| 38 // started, while |application_scheme| has the same meaning as the public | 53 // started, while |application_scheme| has the same meaning as the public |
| 39 // constructor. | 54 // constructor. |
| 40 ClipboardRecentContentIOS(const std::string& application_scheme, | 55 ClipboardRecentContentIOS(const std::string& application_scheme, |
| 41 base::TimeDelta uptime); | 56 base::TimeDelta uptime); |
| 42 | 57 |
| 43 // Initializes the object. |uptime| is how long ago the device has started. | 58 // Initializes the object. |uptime| is how long ago the device has started. |
| 44 void Init(base::TimeDelta uptime); | 59 void Init(base::TimeDelta uptime); |
| 45 | 60 |
| 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. | 61 // Saves information to the user defaults about the latest pasteboard entry. |
| 50 void SaveToUserDefaults(); | 62 void SaveToUserDefaults(); |
| 51 | 63 |
| 52 // Returns the URL contained in the clipboard (if any). | 64 // Returns the URL contained in the clipboard (if any). |
| 53 GURL URLFromPasteboard(); | 65 GURL URLFromPasteboard(); |
| 54 | 66 |
| 55 // Contains the URL scheme opening the app. May be empty. | 67 // Contains the URL scheme opening the app. May be empty. |
| 56 std::string application_scheme_; | 68 std::string application_scheme_; |
| 57 // The pasteboard's change count. Increases everytime the pasteboard changes. | 69 // The pasteboard's change count. Increases everytime the pasteboard changes. |
| 58 NSInteger lastPasteboardChangeCount_; | 70 NSInteger last_pasteboard_change_count_; |
| 59 // Estimation of the date when the pasteboard changed. | 71 // Estimation of the date when the pasteboard changed. |
| 60 base::scoped_nsobject<NSDate> lastPasteboardChangeDate_; | 72 base::scoped_nsobject<NSDate> last_pasteboard_change_date_; |
| 73 // Estimation of the copy date of the last displayed URL. | |
| 74 base::scoped_nsobject<NSDate> last_displayed_pasteboard_entry_; | |
| 75 // MD5 hash of the last registered pasteboard entry. | |
| 76 base::scoped_nsobject<NSData> last_pasteboard_entry_md5_; | |
| 61 // Cache of the GURL contained in the pasteboard (if any). | 77 // Cache of the GURL contained in the pasteboard (if any). |
| 62 GURL urlFromPasteboardCache_; | 78 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. | 79 // Bridge to receive notification when the pasteboard changes. |
| 67 base::scoped_nsobject<PasteboardNotificationListenerBridge> | 80 base::scoped_nsobject<PasteboardNotificationListenerBridge> |
| 68 notificationBridge_; | 81 notification_bridge_; |
| 82 // The user defaults from the app group used to optimize the pasteboard change | |
| 83 // detection. | |
| 84 base::scoped_nsobject<NSUserDefaults> shared_user_defaults_; | |
| 69 | 85 |
| 70 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); | 86 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); |
| 71 }; | 87 }; |
| 72 | 88 |
| 73 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ | 89 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ |
| OLD | NEW |