Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: components/open_from_clipboard/clipboard_recent_content_ios.h

Issue 1274713003: Refactor ClipboardRecentContent singleton creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comment by jif Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/open_from_clipboard/clipboard_recent_content.h" 9 #include "components/open_from_clipboard/clipboard_recent_content.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 @class NSDate; 12 @class NSDate;
13 @class PasteboardNotificationListenerBridge; 13 @class PasteboardNotificationListenerBridge;
14 14
15 namespace test { 15 class ClipboardRecentContentIOSTest;
16 class ClipboardRecentContentIOSTestHelper;
17 } // namespace test
18
19 template <typename T>
20 struct DefaultSingletonTraits;
21 16
22 // IOS implementation of ClipboardRecentContent 17 // IOS implementation of ClipboardRecentContent
23 class ClipboardRecentContentIOS : public ClipboardRecentContent { 18 class ClipboardRecentContentIOS : public ClipboardRecentContent {
24 public: 19 public:
25 static ClipboardRecentContentIOS* GetInstance(); 20 // |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
22 // determine whether or not the clipboard contains a relevant URL.
23 explicit ClipboardRecentContentIOS(const std::string& application_scheme);
24 ~ClipboardRecentContentIOS() override;
25
26 // Notifies that the content of the pasteboard may have changed. 26 // Notifies that the content of the pasteboard may have changed.
27 void PasteboardChanged(); 27 void PasteboardChanged();
28 28
29 // ClipboardRecentContent implementation.
29 bool GetRecentURLFromClipboard(GURL* url) const override; 30 bool GetRecentURLFromClipboard(GURL* url) const override;
30
31 base::TimeDelta GetClipboardContentAge() const override; 31 base::TimeDelta GetClipboardContentAge() const override;
32
33 void SuppressClipboardContent() override; 32 void SuppressClipboardContent() override;
34 33
35 protected: 34 private:
36 // Protected for testing. 35 friend class ClipboardRecentContentIOSTest;
37 ClipboardRecentContentIOS();
38 ~ClipboardRecentContentIOS() override;
39 // |uptime| is how long ago the device has started.
40 ClipboardRecentContentIOS(base::TimeDelta uptime);
41 36
42 private: 37 // Helper constructor for testing. |uptime| is how long ago the device has
43 friend struct DefaultSingletonTraits<ClipboardRecentContentIOS>; 38 // started, while |application_scheme| has the same meaning as the public
44 friend class test::ClipboardRecentContentIOSTestHelper; 39 // constructor.
40 ClipboardRecentContentIOS(const std::string& application_scheme,
41 base::TimeDelta uptime);
42
45 // Initializes the object. |uptime| is how long ago the device has started. 43 // Initializes the object. |uptime| is how long ago the device has started.
46 void Init(base::TimeDelta uptime); 44 void Init(base::TimeDelta uptime);
45
47 // Loads information from the user defaults about the latest pasteboard entry. 46 // Loads information from the user defaults about the latest pasteboard entry.
48 void LoadFromUserDefaults(); 47 void LoadFromUserDefaults();
48
49 // Saves information to the user defaults about the latest pasteboard entry. 49 // Saves information to the user defaults about the latest pasteboard entry.
50 void SaveToUserDefaults(); 50 void SaveToUserDefaults();
51
51 // Returns the URL contained in the clipboard (if any). 52 // Returns the URL contained in the clipboard (if any).
52 GURL URLFromPasteboard(); 53 GURL URLFromPasteboard();
53 54
55 // Contains the URL scheme opening the app. May be empty.
56 std::string application_scheme_;
54 // The pasteboard's change count. Increases everytime the pasteboard changes. 57 // The pasteboard's change count. Increases everytime the pasteboard changes.
55 NSInteger lastPasteboardChangeCount_; 58 NSInteger lastPasteboardChangeCount_;
56 // Estimation of the date when the pasteboard changed. 59 // Estimation of the date when the pasteboard changed.
57 base::scoped_nsobject<NSDate> lastPasteboardChangeDate_; 60 base::scoped_nsobject<NSDate> lastPasteboardChangeDate_;
58 // Cache of the GURL contained in the pasteboard (if any). 61 // Cache of the GURL contained in the pasteboard (if any).
59 GURL urlFromPasteboardCache_; 62 GURL urlFromPasteboardCache_;
60 // A count identifying the suppressed pasteboard entry. Contains 63 // A count identifying the suppressed pasteboard entry. Contains
61 // |NSIntegerMax| if there's no relevant entry to suppress. 64 // |NSIntegerMax| if there's no relevant entry to suppress.
62 NSInteger suppressedPasteboardEntryCount_; 65 NSInteger suppressedPasteboardEntryCount_;
63 // Bridge to receive notification when the pasteboard changes. 66 // Bridge to receive notification when the pasteboard changes.
64 base::scoped_nsobject<PasteboardNotificationListenerBridge> 67 base::scoped_nsobject<PasteboardNotificationListenerBridge>
65 notificationBridge_; 68 notificationBridge_;
66 69
67 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS); 70 DISALLOW_COPY_AND_ASSIGN(ClipboardRecentContentIOS);
68 }; 71 };
69 72
70 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_ 73 #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698