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

Side by Side Diff: chrome/browser/ui/search/search_ipc_router.cc

Issue 2677013004: SearchIPCRouter: Invalidate cached connection ID on renderer crash (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/ui/search/search_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/search.h" 10 #include "chrome/browser/search/search.h"
(...skipping 23 matching lines...) Expand all
34 public: 34 public:
35 // The |web_contents| must outlive this object. 35 // The |web_contents| must outlive this object.
36 explicit SearchBoxClientFactoryImpl(content::WebContents* web_contents) 36 explicit SearchBoxClientFactoryImpl(content::WebContents* web_contents)
37 : web_contents_(web_contents), 37 : web_contents_(web_contents),
38 last_connected_rfh_( 38 last_connected_rfh_(
39 std::make_pair(content::ChildProcessHost::kInvalidUniqueID, 39 std::make_pair(content::ChildProcessHost::kInvalidUniqueID,
40 MSG_ROUTING_NONE)) {} 40 MSG_ROUTING_NONE)) {}
41 chrome::mojom::SearchBox* GetSearchBox() override; 41 chrome::mojom::SearchBox* GetSearchBox() override;
42 42
43 private: 43 private:
44 void OnConnectionError();
45
44 content::WebContents* web_contents_; 46 content::WebContents* web_contents_;
45 chrome::mojom::SearchBoxAssociatedPtr search_box_; 47 chrome::mojom::SearchBoxAssociatedPtr search_box_;
46 48
47 // The proccess ID and routing ID of the last connected main frame. May be 49 // The proccess ID and routing ID of the last connected main frame. May be
48 // (ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE) if we haven't 50 // (ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE) if we haven't
49 // connected yet. 51 // connected yet.
50 std::pair<int, int> last_connected_rfh_; 52 std::pair<int, int> last_connected_rfh_;
51 53
52 DISALLOW_COPY_AND_ASSIGN(SearchBoxClientFactoryImpl); 54 DISALLOW_COPY_AND_ASSIGN(SearchBoxClientFactoryImpl);
53 }; 55 };
54 56
55 chrome::mojom::SearchBox* SearchBoxClientFactoryImpl::GetSearchBox() { 57 chrome::mojom::SearchBox* SearchBoxClientFactoryImpl::GetSearchBox() {
56 content::RenderFrameHost* frame = web_contents_->GetMainFrame(); 58 content::RenderFrameHost* frame = web_contents_->GetMainFrame();
57 auto id = std::make_pair(frame->GetProcess()->GetID(), frame->GetRoutingID()); 59 auto id = std::make_pair(frame->GetProcess()->GetID(), frame->GetRoutingID());
58 // Avoid reconnecting repeatedly to the same RenderFrameHost for performance 60 // Avoid reconnecting repeatedly to the same RenderFrameHost for performance
59 // reasons. 61 // reasons.
60 if (id != last_connected_rfh_) { 62 if (id != last_connected_rfh_) {
61 if (IsRenderedInInstantProcess(web_contents_)) { 63 if (IsRenderedInInstantProcess(web_contents_)) {
62 frame->GetRemoteAssociatedInterfaces()->GetInterface(&search_box_); 64 frame->GetRemoteAssociatedInterfaces()->GetInterface(&search_box_);
65 search_box_.set_connection_error_handler(
66 base::Bind(&SearchBoxClientFactoryImpl::OnConnectionError,
67 base::Unretained(this)));
63 } else { 68 } else {
64 // Renderer is not an instant process. We'll create a connection that 69 // Renderer is not an instant process. We'll create a connection that
65 // drops all messages. 70 // drops all messages.
66 mojo::GetIsolatedProxy(&search_box_); 71 mojo::GetIsolatedProxy(&search_box_);
67 } 72 }
68 last_connected_rfh_ = id; 73 last_connected_rfh_ = id;
69 } 74 }
70 return search_box_.get(); 75 return search_box_.get();
71 } 76 }
72 77
78 void SearchBoxClientFactoryImpl::OnConnectionError() {
79 search_box_.reset();
80 last_connected_rfh_ = std::make_pair(
81 content::ChildProcessHost::kInvalidUniqueID,
82 MSG_ROUTING_NONE);
83 }
84
73 } // namespace 85 } // namespace
74 86
75 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, 87 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents,
76 Delegate* delegate, 88 Delegate* delegate,
77 std::unique_ptr<Policy> policy) 89 std::unique_ptr<Policy> policy)
78 : WebContentsObserver(web_contents), 90 : WebContentsObserver(web_contents),
79 delegate_(delegate), 91 delegate_(delegate),
80 policy_(std::move(policy)), 92 policy_(std::move(policy)),
81 commit_counter_(0), 93 commit_counter_(0),
82 is_active_tab_(false), 94 is_active_tab_(false),
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 337
326 void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) { 338 void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) {
327 DCHECK(delegate); 339 DCHECK(delegate);
328 delegate_ = delegate; 340 delegate_ = delegate;
329 } 341 }
330 342
331 void SearchIPCRouter::set_policy_for_testing(std::unique_ptr<Policy> policy) { 343 void SearchIPCRouter::set_policy_for_testing(std::unique_ptr<Policy> policy) {
332 DCHECK(policy); 344 DCHECK(policy);
333 policy_ = std::move(policy); 345 policy_ = std::move(policy);
334 } 346 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698