Implement ClipboardRecentContent for Android |
||||
Issue descriptionhttps://cs.chromium.org/chromium/src/components/open_from_clipboard/clipboard_recent_content.h This only has an implementation on iOS. We'd like to launch it on other platforms, starting with Android.
,
Jan 19 2017
This is likely to have everything you need: https://developer.android.com/reference/android/content/ClipboardManager.html 1.) https://developer.android.com/reference/android/content/ClipboardManager.html#getPrimaryClip() 2.) https://developer.android.com/reference/android/content/ClipboardManager.html#addPrimaryClipChangedListener(android.content.ClipboardManager.OnPrimaryClipChangedListener) -- You won't exactly know that Chrome is the one that entered the text. But if Chrome is in the foreground, I think you could "assume" it was. Same for #3, if Chrome isn't in the foreground then it likely is a non-Chrome app.
,
Jan 19 2017
Also, we have a bit of an abstraction of this already in chrome: https://cs.chromium.org/chromium/src/ui/android/java/src/org/chromium/ui/base/Clipboard.java?q=Clipboard.java So we could potentially extend that.
,
Feb 16 2017
I found the following C++ class https://cs.chromium.org/chromium/src/ui/base/clipboard/clipboard_android.cc which is the C++ layer that accesses the Java Android Clipboard.java that Ted pointed out.
,
Feb 16 2017
I think I have a plan. It involves a lot of piping. tedchoc@, can you read this (or at least section #1 and the Appendix) and comment on whether it seems reasonable?
1.
Make Clipboard.java a subclass of ClipboardManager.OnPrimaryClipChangedListener.
As such, adds a function onPrimaryClipChanged(). When this function gets called
- grab the current clipboard contents to compute a hash
- record the time
Also add the function GetClipboardAge(), which returns the age of the current
clipboard in seconds.
[more details in Appendix]
2.
In clipboard_android.cc, add the function GetClipboardAge() that calls the Java version.
Later we can hoist this function higher (to clipboard.h, the superclass) if we plan to add implementations of the function for other platforms.
3.
Create a clipboard_recent_content_android.{h,cc} that subclasses from ClipboardRecentContent.
This will be a thin class that uses ClipboardAndroid. All it needs to implement are
virtual bool GetRecentURLFromClipboard(GURL* url) = 0;
virtual base::TimeDelta GetClipboardContentAge() const = 0;
virtual void SuppressClipboardContent() = 0;
This should be straightforward.
Appendix:
In my initial version, I suggest Clipboard.java also should do the following (in addition to what I said about onPrimaryClipChanged()):
on cold startup,
- grab the current clipboard contents to compute a hash
- set last_clipboard_change_time_ to an unknown (ancient) time so
this content is never suggested
on background (can it listen for Chrome being put in the background?),
- set last_backgrounded_time_ to the time the app was put into the background
on foreground (can it listen for the app being put in the foreground?),
- grab the current clipboard contents to compute hash
- if the hash has changed from last time, update the last_clipboard_change_time_ to last_backgrounded_time_. This is a pessimistic assumption, assuming that the clipboard changed quickly after the user left Chrome, not changed right before Chrome started.
In a later version, we could consider storing hash and the last_clipboard_change_time_ to prefs. The iOS version does something like this, storing them to NSUserDefaults and thus allowing clipboard information to persist across app closures.
,
Feb 17 2017
Overall this makes sense. Here are my followup thoughts: 1.) Cold start. I think we should at least consider not making clipboard entries on cold start never suggested. I can definitely see Chrome being dead when copying from other apps and into Chrome. On low end phones, this likely would make it never get suggested. 2.) Background/foreground. Take a look at: https://cs.chromium.org/chromium/src/base/android/java/src/org/chromium/base/ApplicationStatus.java In particular: https://cs.chromium.org/chromium/src/base/android/java/src/org/chromium/base/ApplicationStatus.java?l=395 HAS_STOPPED_ACTIVITIES or HAS_DESTROYED_ACTIVITIES means you are in the background. The others are foreground. This is also available in C++ if you want it to be: https://cs.chromium.org/chromium/src/base/android/application_status_listener.h Assuming the Chrome process isn't killed, why do you need to worry about last_backgrounded_time_ though? If you're still receiving updates about clipboard changes, then I think you could just update last_clipboard_change_time_.
,
Feb 17 2017
re: cold start. I think this comes out of mirroring the type of logic in bug 442380 (this feature for iOS) and the decisions made therein. I think the idea is not to suggest things from the clipboard that may be, say, weeks old. re: background/foreground: > Assuming the Chrome process isn't killed, why do you need to worry about > last_backgrounded_time_ though? If you're still receiving updates about > clipboard changes, then I think you could just update last_clipboard_change_time_. Good point. I forgot that Chrome is still running when in the background (duh!) and thus still listens for the clipboard changes. (I assume Android calls PrimaryClipChangedListeners regardless of whether the listening app is in the foreground or background.) Yay, I can drop all that background/foreground listener stuff! Thanks Ted!
,
Feb 28 2017
,
Mar 1 2017
The code is mostly complete. However, it'll take a real push to get this in for M-58, both me finishing it and a lot of pressure on multiple reviewers. This change isn't worth the trouble it'll cause for everyone else to get this in. I'm punting it to M-59.
,
Mar 31 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17 commit 6f6d07f111d9df9bc70ff3dc71612d940d9b2d17 Author: mpearson <mpearson@chromium.org> Date: Fri Mar 31 21:26:57 2017 Make Android Clipboard Keep Track of Last Modified Time And expose it the C++ code. To do in a later changelist: add lightweight code to store the hash and update time in prefs so that Chrome can have a better chance of using the current clipboard content on startup. (If the clipboard content hasn't changed since the last time Chrome ran, the last modified date is likely correct.) BUG= 682446 Review-Url: https://codereview.chromium.org/2766623003 Cr-Commit-Position: refs/heads/master@{#461234} [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/chrome/android/junit/src/org/chromium/chrome/browser/DisableHistogramsRule.java [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/tools/metrics/actions/actions.xml [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/tools/metrics/histograms/histograms.xml [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/android/BUILD.gn [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/android/java/src/org/chromium/ui/base/Clipboard.java [add] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/base/clipboard/clipboard.cc [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/base/clipboard/clipboard.h [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/base/clipboard/clipboard_android.cc [modify] https://crrev.com/6f6d07f111d9df9bc70ff3dc71612d940d9b2d17/ui/base/clipboard/clipboard_android.h
,
Apr 4 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/054a0eadff47f8d158a2314e3858fb050ada6a4f commit 054a0eadff47f8d158a2314e3858fb050ada6a4f Author: mpearson <mpearson@chromium.org> Date: Tue Apr 04 04:43:45 2017 Add Generic Implementation of ClipboardRecentContent i.e., an implementation that works on all platforms for which ui/base/Clipboard has an implementation. This is all of them except iOS. The only platform for which the implementation is sufficient at this time to provide the necessary functionality is Android. (The other platforms always return clipboard modification times of the start of epoch, meaning any URLs in the clipboard will not be suggested.) I have tested this interactively and it works. TBR=sky (for the modifications to ui/base/test/test_clipboard.{h,cc} and the inclusion of ui/base/test in components/open_from_clipboard/DEPS ) BUG= 682446 Review-Url: https://codereview.chromium.org/2790993003 Cr-Commit-Position: refs/heads/master@{#461631} [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/chrome/browser/android/omnibox/autocomplete_controller_android.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/omnibox/browser/autocomplete_controller.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/omnibox/browser/autocomplete_controller.h [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/BUILD.gn [add] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/DEPS [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content.h [add] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content_generic.cc [add] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content_generic.h [add] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/components/open_from_clipboard/clipboard_recent_content_ios.mm [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/ui/base/test/test_clipboard.cc [modify] https://crrev.com/054a0eadff47f8d158a2314e3858fb050ada6a4f/ui/base/test/test_clipboard.h
,
Apr 12 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/03a5e89da19258391f9b0f06bb0d14fae46ce401 commit 03a5e89da19258391f9b0f06bb0d14fae46ce401 Author: mpearson <mpearson@chromium.org> Date: Wed Apr 12 21:21:53 2017 Omnibox - ClipboardRecentContent - Make Proper Singleton This is a follow-up from https://codereview.chromium.org/2790993003 in particular https://codereview.chromium.org/2790993003#msg61 with its concerns about the lifetime of this object. TBR=jif BUG= 682446 Review-Url: https://codereview.chromium.org/2801813003 Cr-Commit-Position: refs/heads/master@{#464154} [modify] https://crrev.com/03a5e89da19258391f9b0f06bb0d14fae46ce401/components/omnibox/browser/autocomplete_controller.cc [modify] https://crrev.com/03a5e89da19258391f9b0f06bb0d14fae46ce401/components/omnibox/browser/autocomplete_controller.h [modify] https://crrev.com/03a5e89da19258391f9b0f06bb0d14fae46ce401/components/open_from_clipboard/clipboard_recent_content.cc [modify] https://crrev.com/03a5e89da19258391f9b0f06bb0d14fae46ce401/components/open_from_clipboard/clipboard_recent_content.h [modify] https://crrev.com/03a5e89da19258391f9b0f06bb0d14fae46ce401/ios/chrome/browser/ios_chrome_main_parts.mm
,
Apr 13 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/71dfbd1f2228ae70efcea0656b3555ab539430fd commit 71dfbd1f2228ae70efcea0656b3555ab539430fd Author: mpearson <mpearson@chromium.org> Date: Thu Apr 13 23:07:43 2017 Refactor Clipboard Last Modified Time Storage This changelist is the first step to solving two problems: * clipboard last modified time isn't remembered from run to run. It should be. * likewise, clipboard suggestion suppression (which happens after clearing browsing data) should also be preserved from run to run. The key to solving both these problems is to store the clipboard last modified time in prefs. (Store a 0 to represent that the clipboard shouldn't be suggested.) To do this, we need a central place to own the last modified time value. Upon consultation with dcheng@, we decided this should be clipboard_android.cc. Because Chrome on Android can be killed almost anytime, the best strategy to have clipboard_android.cc to always have the correct value is to have Clipboard.java "push" notification of the modification to clipboard_android.cc. After this changelist, I will submit a changelist that stores the last_modified_time information to prefs / reads it from prefs. As a consequence of this decision, this change makes * remove storage and retrieval of last modified time from Clipboard.java. clipboard_android.cc is the canonical source now. * clipboard_recent_content_generic.{cc,h} loses |last_modified_time_to_suppress_|, as that suppression logic is unnecessary. Instead, when needing to suppress a suggestion, it tells clipboard_android to set its time to 0, which would cause suppression. Adds a function ClearClipboardLastModifiedTime() to clipboard.h for this. * remove all the logic about hashing clipboard content from Clipboard.java. This is not needed based on our usage of clipboard last modified time. (This usage has been approved by privacy.) This also means marking a related histogram as obsolete. * Because Clipboard.java sends clipboard changed messages now to clipboard_android, add support for sequence numbers to clipboard_android. * Likewise, because clipboard_android is "pushed" messages about the clipboard being updated, it knows when its local data is out of data. It only "pulls" clipboard information from the Java side when someone asks it about the current state of the clipboard and it knows that it is out of date. * Delete ClipboardTest.java. The only thing this tested was updating the last modified time in Clipboard.java, which doesn't exist anymore. TBR=sky,jif (sky@ for the trivial changes to ui/base/test/...) (jif@ for the refactoring / removal of logic from components/open_from_clipboard/...) BUG= 682446 , 707366 Review-Url: https://codereview.chromium.org/2812773002 Cr-Commit-Position: refs/heads/master@{#464594} [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/components/open_from_clipboard/clipboard_recent_content_generic.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/components/open_from_clipboard/clipboard_recent_content_generic.h [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/components/open_from_clipboard/clipboard_recent_content_generic_unittest.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/tools/metrics/histograms/histograms.xml [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/android/BUILD.gn [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/android/java/src/org/chromium/ui/base/Clipboard.java [delete] https://crrev.com/94182b78878d55cb968e15312c66abfe21e3caf4/ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/android/ui_base_jni_registrar.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/clipboard/clipboard.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/clipboard/clipboard.h [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/clipboard/clipboard_android.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/clipboard/clipboard_android.h [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/test/test_clipboard.cc [modify] https://crrev.com/71dfbd1f2228ae70efcea0656b3555ab539430fd/ui/base/test/test_clipboard.h
,
Apr 14 2017
ClipboardRecentContent is implemented for Android and it works. The only thing lacking is storing modification times to prefs. Because that change will need to be merged into M-59, I'm filing it as a separate bug for it: bug 711574 . |
||||
►
Sign in to add a comment |
||||
Comment 1 by mpear...@chromium.org
, Jan 18 2017