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

Unified Diff: content/browser/find_request_manager.cc

Issue 2249133002: Changes to how FindRequestManager reports find results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/find_request_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/find_request_manager.cc
diff --git a/content/browser/find_request_manager.cc b/content/browser/find_request_manager.cc
index ba97753698a77a8e8f00fe80181909fb083d17a5..09415ec800a4785b62fea855aad2bb9c5ddcc7a3 100644
--- a/content/browser/find_request_manager.cc
+++ b/content/browser/find_request_manager.cc
@@ -91,6 +91,7 @@ FindRequestManager::FindRequestManager(WebContentsImpl* web_contents)
: WebContentsObserver(web_contents),
contents_(web_contents),
current_session_id_(kInvalidId),
+ pending_find_next_reply_(nullptr),
pending_active_match_ordinal_(false),
number_of_matches_(0),
active_frame_(nullptr),
@@ -190,16 +191,27 @@ void FindRequestManager::OnFindReply(RenderFrameHost* rfh,
// This is the final update for this frame for the current find operation.
- pending_replies_.erase(rfh);
- if (request_id == current_session_id_ && !pending_replies_.empty()) {
- NotifyFindReply(request_id, false /* final_update */);
+ pending_initial_replies_.erase(rfh);
+ if (request_id == current_session_id_ && !pending_initial_replies_.empty())
lfg 2016/08/18 18:50:42 Why did you remove the NotifyFindReply() from this
paulmeyer 2016/08/29 22:27:41 I can't remember why I did that. It may have been
return;
- }
- DCHECK(request_id == current_session_id_ ||
- current_request_.options.findNext);
// This is the final update for the current find operation.
- FinalUpdate(request_id, rfh);
+
+ if (request_id == current_request_.id && request_id != current_session_id_) {
+ DCHECK(current_request_.options.findNext);
+ DCHECK(pending_find_next_reply_ == rfh);
lfg 2016/08/18 18:50:42 nit: DCHECK_EQ.
paulmeyer 2016/08/29 22:27:41 Done.
+ pending_find_next_reply_ = nullptr;
+ }
+
+ // The find results are normally reported under the ID of the find reply they
+ // came from (|request_id|), but if this really is the last update, then they
+ // need to be reported with the latest find request ID
+ // (|current_request_.id|), so that the receiver can know for sure that all
+ // issued find requests have completed.
lfg 2016/08/18 18:50:42 See my comment above, I don't think we should ever
paulmeyer 2016/08/29 22:27:41 Done.
+ int report_id = request_id;
+ if (pending_initial_replies_.empty() && !pending_find_next_reply_)
+ report_id = current_request_.id;
+ FinalUpdate(report_id, rfh);
}
void FindRequestManager::RemoveFrame(RenderFrameHost* rfh) {
@@ -218,6 +230,7 @@ void FindRequestManager::RemoveFrame(RenderFrameHost* rfh) {
if (active_frame_ == rfh) {
active_frame_ = nullptr;
relative_active_match_ordinal_ = 0;
+ selection_rect_ = gfx::Rect();
}
UpdateActiveMatchOrdinal();
@@ -239,17 +252,28 @@ void FindRequestManager::RemoveFrame(RenderFrameHost* rfh) {
RemoveFindMatchRectsPendingReply(rfh);
#endif
- if (pending_replies_.count(rfh)) {
+ // If no pending find replies are expected for the removed frame, then just
+ // report the updated results.
+ if (!pending_initial_replies_.count(rfh) && pending_find_next_reply_ != rfh) {
+ bool final_update =
+ pending_initial_replies_.empty() && !pending_find_next_reply_;
+ NotifyFindReply(current_session_id_, final_update);
lfg 2016/08/18 18:50:42 I don't understand why we avoid calling FinalUpdat
paulmeyer 2016/08/29 22:27:41 See comment on FinalUpdate(). In this case, a fram
lfg 2016/08/30 14:57:38 Is it possible that the final update will be sent
paulmeyer 2016/08/30 15:40:12 Yes, that is possible, and intended. Once all fram
+ return;
+ }
+
+ if (pending_initial_replies_.count(rfh)) {
// A reply should not be expected from the removed frame.
- pending_replies_.erase(rfh);
- if (pending_replies_.empty()) {
- FinalUpdate(current_request_.id, rfh);
- return;
+ pending_initial_replies_.erase(rfh);
+ if (pending_initial_replies_.empty()) {
+ FinalUpdate(current_session_id_, rfh);
lfg 2016/08/18 18:50:42 Do we want to send a FinalUpdate if pending_find_n
paulmeyer 2016/08/29 22:27:41 See comment on FinalUpdate().
}
}
- NotifyFindReply(current_session_id_,
- pending_replies_.empty() /* final_update */);
+ if (pending_find_next_reply_ == rfh) {
+ // A reply should not be expected from the removed frame.
+ pending_find_next_reply_ = nullptr;
+ FinalUpdate(current_request_.id, rfh);
lfg 2016/08/18 18:50:42 Same as above, do we want to send a FinalUpdate if
paulmeyer 2016/08/29 22:27:41 See comment on FinalUpdate().
+ }
}
#if defined(OS_ANDROID)
@@ -264,7 +288,7 @@ void FindRequestManager::ActivateNearestFindResult(float x, float y) {
for (FrameTreeNode* node : contents_->GetFrameTree()->Nodes()) {
RenderFrameHost* rfh = node->current_frame_host();
- if (!CheckFrame(rfh))
+ if (!CheckFrame(rfh) || !rfh->IsRenderFrameLive())
continue;
activate_.pending_replies.insert(rfh);
@@ -299,7 +323,7 @@ void FindRequestManager::RequestFindMatchRects(int current_version) {
for (FrameTreeNode* node : contents_->GetFrameTree()->Nodes()) {
RenderFrameHost* rfh = node->current_frame_host();
- if (!CheckFrame(rfh))
+ if (!CheckFrame(rfh) || !rfh->IsRenderFrameLive())
continue;
match_rects_.pending_replies.insert(rfh);
@@ -343,7 +367,8 @@ void FindRequestManager::FrameDeleted(RenderFrameHost* rfh) {
void FindRequestManager::Reset(const FindRequest& initial_request) {
current_session_id_ = initial_request.id;
current_request_ = initial_request;
- pending_replies_.clear();
+ pending_initial_replies_.clear();
+ pending_find_next_reply_ = nullptr;
pending_active_match_ordinal_ = true;
matches_per_frame_.clear();
number_of_matches_ = 0;
@@ -400,7 +425,14 @@ void FindRequestManager::AdvanceQueue(int request_id) {
void FindRequestManager::SendFindIPC(const FindRequest& request,
RenderFrameHost* rfh) {
- pending_replies_.insert(rfh);
+ DCHECK(CheckFrame(rfh));
+ DCHECK(rfh->IsRenderFrameLive());
+
+ if (request.options.findNext)
+ pending_find_next_reply_ = rfh;
+ else
+ pending_initial_replies_.insert(rfh);
+
rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id,
request.search_text, request.options));
}
@@ -437,7 +469,7 @@ RenderFrameHost* FindRequestManager::Traverse(RenderFrameHost* from_rfh,
continue;
RenderFrameHost* current_rfh = node->current_frame_host();
if (!matches_only || matches_per_frame_.find(current_rfh)->second ||
- pending_replies_.count(current_rfh)) {
+ pending_initial_replies_.count(current_rfh)) {
// Note that if there is still a pending reply expected for this frame,
// then it may have unaccounted matches and will not be skipped via
// |matches_only|.
@@ -466,7 +498,7 @@ void FindRequestManager::AddFrame(RenderFrameHost* rfh) {
}
bool FindRequestManager::CheckFrame(RenderFrameHost* rfh) const {
- return rfh && rfh->IsRenderFrameLive() && matches_per_frame_.count(rfh);
+ return rfh && matches_per_frame_.count(rfh);
lfg 2016/08/18 18:50:42 I don't understand the reason for this change.
paulmeyer 2016/08/29 22:27:41 I discovered that I don't actually want to check I
lfg 2016/08/30 14:57:38 Can you add add a comment in the places that this
paulmeyer 2016/08/30 15:40:12 I don't think that is necessary. If you look at th
lfg 2016/08/30 15:43:23 Acknowledged.
}
void FindRequestManager::UpdateActiveMatchOrdinal() {
@@ -492,9 +524,13 @@ void FindRequestManager::UpdateActiveMatchOrdinal() {
void FindRequestManager::FinalUpdate(int request_id, RenderFrameHost* rfh) {
if (!number_of_matches_ ||
- !pending_active_match_ordinal_ ||
+ (active_match_ordinal_ && !pending_active_match_ordinal_) ||
request_id != current_request_.id) {
- NotifyFindReply(request_id, true /* final_update */);
+ // All the find results for |request_id| are in and ready to report. Note
+ // that |final_update| will be set to false if there are still pending
+ // replies expected from the initial find request.
+ NotifyFindReply(request_id,
+ pending_initial_replies_.empty() /* final_update */);
lfg 2016/08/18 18:50:42 The fact that FinalUpdate() doesn't always send a
paulmeyer 2016/08/29 22:27:41 FinalUpdate() is called once all the replies have
lfg 2016/08/30 14:57:38 Can you update the comment on the header to reflec
paulmeyer 2016/08/30 15:40:12 Done. I also renamed FinalUpdate() to FinalUpdateR
AdvanceQueue(request_id);
return;
}
« no previous file with comments | « content/browser/find_request_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698