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 ClipboardRecentContentImplIOS; |
17 | 18 |
18 class ClipboardRecentContentIOSTest; | 19 // IOS implementation of ClipboardRecentContent. |
19 | 20 // A large part of the implementation is in clipboard_recent_content_impl_ios, |
20 // IOS implementation of ClipboardRecentContent | 21 // a GURL-free class that is used by some of the iOS extensions. Not using GURL |
| 22 // in extensions is preferable as GURL requires depending on ICU which makes the |
| 23 // extensions much larger. |
21 class ClipboardRecentContentIOS : public ClipboardRecentContent { | 24 class ClipboardRecentContentIOS : public ClipboardRecentContent { |
22 public: | 25 public: |
23 // |application_scheme| is the URL scheme that can be used to open the | 26 // |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 | 27 // current application, may be empty if no such scheme exists. Used to |
25 // determine whether or not the clipboard contains a relevant URL. | 28 // determine whether or not the clipboard contains a relevant URL. |
26 // |group_user_defaults| is the NSUserDefaults used to store information on | 29 // |group_user_defaults| is the NSUserDefaults used to store information on |
27 // pasteboard entry expiration. This information will be shared with other | 30 // pasteboard entry expiration. This information will be shared with other |
28 // application in the application group. | 31 // application in the application group. |
29 explicit ClipboardRecentContentIOS(const std::string& application_scheme, | 32 ClipboardRecentContentIOS(const std::string& application_scheme, |
30 NSUserDefaults* group_user_defaults); | 33 NSUserDefaults* group_user_defaults); |
| 34 |
| 35 // Constructor that directly takes an |implementation|. For use in tests. |
| 36 ClipboardRecentContentIOS(ClipboardRecentContentImplIOS* implementation); |
| 37 |
31 ~ClipboardRecentContentIOS() override; | 38 ~ClipboardRecentContentIOS() override; |
32 | 39 |
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. | 40 // ClipboardRecentContent implementation. |
45 bool GetRecentURLFromClipboard(GURL* url) override; | 41 bool GetRecentURLFromClipboard(GURL* url) override; |
46 base::TimeDelta GetClipboardContentAge() const override; | 42 base::TimeDelta GetClipboardContentAge() const override; |
47 void SuppressClipboardContent() override; | 43 void SuppressClipboardContent() override; |
48 | 44 |
49 protected: | |
50 // Returns the uptime. Override in tests to return custom value. | |
51 virtual base::TimeDelta Uptime() const; | |
52 | |
53 private: | 45 private: |
54 friend class ClipboardRecentContentIOSTest; | 46 // The implementation instance. |
55 | 47 base::scoped_nsobject<ClipboardRecentContentImplIOS> implementation_; |
56 // Saves information to the user defaults about the latest pasteboard entry. | |
57 void SaveToUserDefaults(); | |
58 | |
59 // Returns the URL contained in the clipboard (if any). | |
60 GURL URLFromPasteboard(); | |
61 | |
62 // Contains the URL scheme opening the app. May be empty. | |
63 std::string application_scheme_; | |
64 // The pasteboard's change count. Increases everytime the pasteboard changes. | |
65 NSInteger last_pasteboard_change_count_; | |
66 // Estimation of the date when the pasteboard changed. | |
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 | 48 |
77 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); | 49 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); |
78 }; | 50 }; |
79 | 51 |
80 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ | 52 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ |
OLD | NEW |