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

Side by Side Diff: chrome/browser/dom_distiller/tab_utils.cc

Issue 2659953002: Convert SelfDeletingRequestDelegate to use the new navigation callbacks. (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/dom_distiller/tab_utils.h" 5 #include "chrome/browser/dom_distiller/tab_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 12 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
13 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 13 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
14 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 14 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
15 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h " 15 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h "
16 #include "components/dom_distiller/core/distiller_page.h" 16 #include "components/dom_distiller/core/distiller_page.h"
17 #include "components/dom_distiller/core/dom_distiller_service.h" 17 #include "components/dom_distiller/core/dom_distiller_service.h"
18 #include "components/dom_distiller/core/task_tracker.h" 18 #include "components/dom_distiller/core/task_tracker.h"
19 #include "components/dom_distiller/core/url_constants.h" 19 #include "components/dom_distiller/core/url_constants.h"
20 #include "components/dom_distiller/core/url_utils.h" 20 #include "components/dom_distiller/core/url_utils.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/navigation_controller.h" 22 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/navigation_handle.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
25 26
26 namespace { 27 namespace {
27 28
28 using dom_distiller::ViewRequestDelegate; 29 using dom_distiller::ViewRequestDelegate;
29 using dom_distiller::DistilledArticleProto; 30 using dom_distiller::DistilledArticleProto;
30 using dom_distiller::ArticleDistillationUpdate; 31 using dom_distiller::ArticleDistillationUpdate;
31 using dom_distiller::ViewerHandle; 32 using dom_distiller::ViewerHandle;
32 using dom_distiller::SourcePageHandleWebContents; 33 using dom_distiller::SourcePageHandleWebContents;
33 using dom_distiller::DomDistillerService; 34 using dom_distiller::DomDistillerService;
34 using dom_distiller::DomDistillerServiceFactory; 35 using dom_distiller::DomDistillerServiceFactory;
35 using dom_distiller::DistillerPage; 36 using dom_distiller::DistillerPage;
36 using dom_distiller::SourcePageHandle; 37 using dom_distiller::SourcePageHandle;
37 38
38 // An no-op ViewRequestDelegate which holds a ViewerHandle and deletes itself 39 // An no-op ViewRequestDelegate which holds a ViewerHandle and deletes itself
39 // after the WebContents navigates or goes away. This class is a band-aid to 40 // after the WebContents navigates or goes away. This class is a band-aid to
40 // keep a TaskTracker around until the distillation starts from the viewer. 41 // keep a TaskTracker around until the distillation starts from the viewer.
41 class SelfDeletingRequestDelegate : public ViewRequestDelegate, 42 class SelfDeletingRequestDelegate : public ViewRequestDelegate,
42 public content::WebContentsObserver { 43 public content::WebContentsObserver {
43 public: 44 public:
44 explicit SelfDeletingRequestDelegate(content::WebContents* web_contents); 45 explicit SelfDeletingRequestDelegate(content::WebContents* web_contents);
45 ~SelfDeletingRequestDelegate() override; 46 ~SelfDeletingRequestDelegate() override;
46 47
47 // ViewRequestDelegate implementation. 48 // ViewRequestDelegate implementation.
48 void OnArticleReady(const DistilledArticleProto* article_proto) override; 49 void OnArticleReady(const DistilledArticleProto* article_proto) override;
49 void OnArticleUpdated(ArticleDistillationUpdate article_update) override; 50 void OnArticleUpdated(ArticleDistillationUpdate article_update) override;
50 51
51 // content::WebContentsObserver implementation. 52 // content::WebContentsObserver implementation.
52 void DidNavigateMainFrame( 53 void DidFinishNavigation(
53 const content::LoadCommittedDetails& details, 54 content::NavigationHandle* navigation_handle) override;
54 const content::FrameNavigateParams& params) override;
55 void RenderProcessGone(base::TerminationStatus status) override; 55 void RenderProcessGone(base::TerminationStatus status) override;
56 void WebContentsDestroyed() override; 56 void WebContentsDestroyed() override;
57 57
58 // Takes ownership of the ViewerHandle to keep distillation alive until |this| 58 // Takes ownership of the ViewerHandle to keep distillation alive until |this|
59 // is deleted. 59 // is deleted.
60 void TakeViewerHandle(std::unique_ptr<ViewerHandle> viewer_handle); 60 void TakeViewerHandle(std::unique_ptr<ViewerHandle> viewer_handle);
61 61
62 private: 62 private:
63 // The handle to the view request towards the DomDistillerService. It 63 // The handle to the view request towards the DomDistillerService. It
64 // needs to be kept around to ensure the distillation request finishes. 64 // needs to be kept around to ensure the distillation request finishes.
65 std::unique_ptr<ViewerHandle> viewer_handle_; 65 std::unique_ptr<ViewerHandle> viewer_handle_;
66 }; 66 };
67 67
68 void SelfDeletingRequestDelegate::DidNavigateMainFrame( 68 void SelfDeletingRequestDelegate::DidFinishNavigation(
69 const content::LoadCommittedDetails& details, 69 content::NavigationHandle* navigation_handle) {
70 const content::FrameNavigateParams& params) { 70 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
71 return;
72
71 Observe(NULL); 73 Observe(NULL);
72 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 74 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
73 } 75 }
74 76
75 void SelfDeletingRequestDelegate::RenderProcessGone( 77 void SelfDeletingRequestDelegate::RenderProcessGone(
76 base::TerminationStatus status) { 78 base::TerminationStatus status) {
77 Observe(NULL); 79 Observe(NULL);
78 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 80 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
79 } 81 }
80 82
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 DCHECK(source_web_contents); 176 DCHECK(source_web_contents);
175 DCHECK(destination_web_contents); 177 DCHECK(destination_web_contents);
176 178
177 std::unique_ptr<SourcePageHandleWebContents> source_page_handle( 179 std::unique_ptr<SourcePageHandleWebContents> source_page_handle(
178 new SourcePageHandleWebContents(source_web_contents, false)); 180 new SourcePageHandleWebContents(source_web_contents, false));
179 181
180 MaybeStartDistillation(std::move(source_page_handle)); 182 MaybeStartDistillation(std::move(source_page_handle));
181 StartNavigationToDistillerViewer(destination_web_contents, 183 StartNavigationToDistillerViewer(destination_web_contents,
182 source_web_contents->GetLastCommittedURL()); 184 source_web_contents->GetLastCommittedURL());
183 } 185 }
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