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 class ClipboardRecentContentIOSTest; | |
19 | 18 |
20 // IOS implementation of ClipboardRecentContent | 19 // IOS implementation of ClipboardRecentContent |
jif
2017/04/06 15:56:53
Can you add
// IOS implementation of ClipboardRec
lody
2017/04/06 16:34:24
Done.
| |
21 class ClipboardRecentContentIOS : public ClipboardRecentContent { | 20 class ClipboardRecentContentIOS : public ClipboardRecentContent { |
22 public: | 21 public: |
23 // |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 |
24 // 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 |
25 // determine whether or not the clipboard contains a relevant URL. | 24 // determine whether or not the clipboard contains a relevant URL. |
26 // |group_user_defaults| is the NSUserDefaults used to store information on | 25 // |group_user_defaults| is the NSUserDefaults used to store information on |
27 // pasteboard entry expiration. This information will be shared with other | 26 // pasteboard entry expiration. This information will be shared with other |
28 // application in the application group. | 27 // application in the application group. |
29 explicit ClipboardRecentContentIOS(const std::string& application_scheme, | 28 ClipboardRecentContentIOS(const std::string& application_scheme, |
30 NSUserDefaults* group_user_defaults); | 29 NSUserDefaults* group_user_defaults); |
30 | |
31 // Constructor that directly takes an |implementation|. For use in tests. | |
32 ClipboardRecentContentIOS(ClipboardRecentContentImplIOS* implementation); | |
33 | |
31 ~ClipboardRecentContentIOS() override; | 34 ~ClipboardRecentContentIOS() override; |
32 | 35 |
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. | 36 // ClipboardRecentContent implementation. |
45 bool GetRecentURLFromClipboard(GURL* url) override; | 37 bool GetRecentURLFromClipboard(GURL* url) override; |
46 base::TimeDelta GetClipboardContentAge() const override; | 38 base::TimeDelta GetClipboardContentAge() const override; |
47 void SuppressClipboardContent() override; | 39 void SuppressClipboardContent() override; |
48 | 40 |
49 protected: | |
50 // Returns the uptime. Override in tests to return custom value. | |
51 virtual base::TimeDelta Uptime() const; | |
52 | |
53 private: | 41 private: |
54 friend class ClipboardRecentContentIOSTest; | 42 // The implementation instance. |
55 | 43 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 | 44 |
77 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); | 45 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); |
78 }; | 46 }; |
79 | 47 |
80 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ | 48 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ |
OLD | NEW |