Rename GetIconID to GetIconId
[chromium-blink-merge.git] / components / open_from_clipboard / clipboard_recent_content_ios.h
blobb0b893f6903850511897a60184f78cea71e25fd7
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
6 #define COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/time/time.h"
10 #include "components/open_from_clipboard/clipboard_recent_content.h"
11 #include "url/gurl.h"
13 @class NSDate;
14 @class NSUserDefaults;
15 @class PasteboardNotificationListenerBridge;
17 class ClipboardRecentContentIOSTest;
19 // IOS implementation of ClipboardRecentContent
20 class ClipboardRecentContentIOS : public ClipboardRecentContent {
21 public:
22 // |application_scheme| is the URL scheme that can be used to open the
23 // current application, may be empty if no such scheme exists. Used to
24 // determine whether or not the clipboard contains a relevant URL.
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);
30 ~ClipboardRecentContentIOS() override;
32 // Notifies that the content of the pasteboard may have changed.
33 void PasteboardChanged();
35 // Checks if pasteboard changed since last time a pasteboard change was
36 // registered.
37 bool HasPasteboardChanged(base::TimeDelta uptime);
39 // Loads information from the user defaults about the latest pasteboard entry.
40 void LoadFromUserDefaults();
42 // ClipboardRecentContent implementation.
43 bool GetRecentURLFromClipboard(GURL* url) const override;
44 base::TimeDelta GetClipboardContentAge() const override;
45 void SuppressClipboardContent() override;
46 void RecentURLDisplayed() override;
48 private:
49 friend class ClipboardRecentContentIOSTest;
51 // Helper constructor for testing. |uptime| is how long ago the device has
52 // started, while |application_scheme| has the same meaning as the public
53 // constructor.
54 ClipboardRecentContentIOS(const std::string& application_scheme,
55 base::TimeDelta uptime);
57 // Initializes the object. |uptime| is how long ago the device has started.
58 void Init(base::TimeDelta uptime);
60 // Saves information to the user defaults about the latest pasteboard entry.
61 void SaveToUserDefaults();
63 // Returns the URL contained in the clipboard (if any).
64 GURL URLFromPasteboard();
66 // Contains the URL scheme opening the app. May be empty.
67 std::string application_scheme_;
68 // The pasteboard's change count. Increases everytime the pasteboard changes.
69 NSInteger last_pasteboard_change_count_;
70 // Estimation of the date when the pasteboard changed.
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_;
76 // Cache of the GURL contained in the pasteboard (if any).
77 GURL url_from_pasteboard_cache_;
78 // Bridge to receive notification when the pasteboard changes.
79 base::scoped_nsobject<PasteboardNotificationListenerBridge>
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_;
85 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS);
88 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_