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/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 NSArray; | |
| 14 @class NSDate; | 15 @class NSDate; |
| 15 @class NSUserDefaults; | 16 @class NSUserDefaults; |
| 16 @class ApplicationDidBecomeActiveNotificationListenerBridge; | 17 @class ClipboardRecentContentIOSImpl; |
| 17 | 18 |
| 18 class ClipboardRecentContentIOSTest; | 19 class ClipboardRecentContentIOSTest; |
| 19 | 20 |
| 20 // IOS implementation of ClipboardRecentContent | 21 // IOS implementation of ClipboardRecentContent |
| 21 class ClipboardRecentContentIOS : public ClipboardRecentContent { | 22 class ClipboardRecentContentIOS : public ClipboardRecentContent { |
| 22 public: | 23 public: |
| 23 // |application_scheme| is the URL scheme that can be used to open the | 24 // |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 | 25 // current application, may be empty if no such scheme exists. Used to |
| 25 // determine whether or not the clipboard contains a relevant URL. | 26 // determine whether or not the clipboard contains a relevant URL. |
| 26 // |group_user_defaults| is the NSUserDefaults used to store information on | 27 // |group_user_defaults| is the NSUserDefaults used to store information on |
| 27 // pasteboard entry expiration. This information will be shared with other | 28 // pasteboard entry expiration. This information will be shared with other |
| 28 // application in the application group. | 29 // application in the application group. |
| 29 explicit ClipboardRecentContentIOS(const std::string& application_scheme, | 30 explicit ClipboardRecentContentIOS(const std::string& application_scheme, |
|
sdefresne
2017/04/03 09:27:16
Remove "explicit", it is only necessary when the c
lody
2017/04/04 13:42:18
Done.
| |
| 30 NSUserDefaults* group_user_defaults); | 31 NSUserDefaults* group_user_defaults); |
| 31 ~ClipboardRecentContentIOS() override; | 32 ~ClipboardRecentContentIOS() override; |
| 32 | 33 |
| 33 // If the content of the pasteboard has changed, updates the change count, | |
| 34 // change date, and md5 of the latest pasteboard entry if necessary. | |
| 35 void UpdateIfNeeded(); | |
| 36 | |
| 37 // Returns whether the pasteboard changed since the last time a pasteboard | |
| 38 // change was detected. | |
| 39 bool HasPasteboardChanged() const; | |
| 40 | |
| 41 // Loads information from the user defaults about the latest pasteboard entry. | |
| 42 void LoadFromUserDefaults(); | |
| 43 | |
| 44 // ClipboardRecentContent implementation. | 34 // ClipboardRecentContent implementation. |
| 45 bool GetRecentURLFromClipboard(GURL* url) override; | 35 bool GetRecentURLFromClipboard(GURL* url) override; |
| 46 base::TimeDelta GetClipboardContentAge() const override; | 36 base::TimeDelta GetClipboardContentAge() const override; |
| 47 void SuppressClipboardContent() override; | 37 void SuppressClipboardContent() override; |
| 48 | 38 |
| 49 protected: | |
| 50 // Returns the uptime. Override in tests to return custom value. | |
| 51 virtual base::TimeDelta Uptime() const; | |
| 52 | |
| 53 private: | 39 private: |
| 54 friend class ClipboardRecentContentIOSTest; | 40 friend class ClipboardRecentContentIOSTest; |
| 55 | 41 |
| 56 // Saves information to the user defaults about the latest pasteboard entry. | 42 // Saves information to the user defaults about the latest pasteboard entry. |
| 57 void SaveToUserDefaults(); | 43 void SaveToUserDefaults(); |
| 58 | 44 |
| 59 // Returns the URL contained in the clipboard (if any). | 45 // Set estimation of the date when the pasteboard changed. |
|
sdefresne
2017/04/03 09:27:16
This is not necessary. Since you inject a subclass
lody
2017/04/04 13:42:18
Done.
| |
| 60 GURL URLFromPasteboard(); | 46 void SetLastPasteboardChangeDate(NSDate* date); |
| 61 | 47 |
| 62 // Contains the URL scheme opening the app. May be empty. | 48 // Get the list of authorized schemes. |
| 63 std::string application_scheme_; | 49 NSArray* GetAuthorizedSchemeList(const std::string& application_scheme); |
|
sdefresne
2017/04/03 09:27:16
This does not have to be part of the class API, ma
lody
2017/04/04 13:42:18
Done.
| |
| 64 // The pasteboard's change count. Increases everytime the pasteboard changes. | 50 |
| 65 NSInteger last_pasteboard_change_count_; | 51 // The implementation instance. |
| 66 // Estimation of the date when the pasteboard changed. | 52 base::scoped_nsobject<ClipboardRecentContentIOSImpl> implementation_; |
|
sdefresne
2017/04/03 09:27:16
I don't like "implementation_" as a field member n
| |
| 67 base::scoped_nsobject<NSDate> last_pasteboard_change_date_; | |
| 68 // MD5 hash of the last registered pasteboard entry. | |
| 69 base::scoped_nsobject<NSData> last_pasteboard_entry_md5_; | |
| 70 // Bridge to receive notifications when the application becomes active. | |
| 71 base::scoped_nsobject<ApplicationDidBecomeActiveNotificationListenerBridge> | |
| 72 notification_bridge_; | |
| 73 // The user defaults from the app group used to optimize the pasteboard change | |
| 74 // detection. | |
| 75 base::scoped_nsobject<NSUserDefaults> shared_user_defaults_; | |
| 76 | 53 |
| 77 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); | 54 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); |
| 78 }; | 55 }; |
| 79 | 56 |
| 80 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ | 57 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ |
| OLD | NEW |