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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader.h

Issue 2711693002: [Offline Pages] Make prerenderer notify us of network progress. (Closed)
Patch Set: last minute fixes 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 14 matching lines...) Expand all
25 // the page loading in the background. It operates on a single thread and 25 // the page loading in the background. It operates on a single thread and
26 // needs to run on BrowserThread::UI to work with the PrerenderManager. 26 // needs to run on BrowserThread::UI to work with the PrerenderManager.
27 // It supports a single load request at a time. 27 // It supports a single load request at a time.
28 class PrerenderingLoader : public PrerenderAdapter::Observer, 28 class PrerenderingLoader : public PrerenderAdapter::Observer,
29 public SnapshotController::Client { 29 public SnapshotController::Client {
30 public: 30 public:
31 // Reports status of a load page request with loaded contents if available. 31 // Reports status of a load page request with loaded contents if available.
32 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)> 32 typedef base::Callback<void(Offliner::RequestStatus, content::WebContents*)>
33 LoadPageCallback; 33 LoadPageCallback;
34 34
35 typedef base::Callback<void(int64_t)> ProgressCallback;
36
35 explicit PrerenderingLoader(content::BrowserContext* browser_context); 37 explicit PrerenderingLoader(content::BrowserContext* browser_context);
36 ~PrerenderingLoader() override; 38 ~PrerenderingLoader() override;
37 39
38 // Loads a page in the background if possible and returns whether the 40 // Loads a page in the background if possible and returns whether the
39 // request was accepted. If so, the LoadPageCallback will be informed 41 // request was accepted. If so, the LoadPageCallback will be informed
40 // of status. Only one load request may exist as a time. If a previous 42 // of status. Only one load request may exist as a time. If a previous
41 // request is still in progress it must be stopped before a new 43 // request is still in progress it must be stopped before a new
42 // request will be accepted. The callback may be called more than 44 // request will be accepted. The callback may be called more than
43 // once - first for a successful load and then if canceled after the 45 // once - first for a successful load and then if canceled after the
44 // load (which may be from resources being reclaimed) at which point 46 // load (which may be from resources being reclaimed) at which point
45 // the retrieved WebContents should no longer be used. 47 // the retrieved WebContents should no longer be used.
46 virtual bool LoadPage(const GURL& url, const LoadPageCallback& callback); 48 virtual bool LoadPage(const GURL& url,
49 const LoadPageCallback& load_done_callback,
50 const ProgressCallback& progress_callback);
47 51
48 // Stops (completes or cancels) the load request. Must be called when 52 // Stops (completes or cancels) the load request. Must be called when
49 // LoadPageCallback is done with consuming the contents. May be called 53 // LoadPageCallback is done with consuming the contents. May be called
50 // prior to LoadPageCallback in order to cancel the current request (in 54 // prior to LoadPageCallback in order to cancel the current request (in
51 // which case the callback will not be run). 55 // which case the callback will not be run).
52 // This loader should also be responsible for stopping offline 56 // This loader should also be responsible for stopping offline
53 // prerenders when Chrome is transitioned to foreground. 57 // prerenders when Chrome is transitioned to foreground.
54 virtual void StopLoading(); 58 virtual void StopLoading();
55 59
56 // Returns whether the loader is idle and able to accept new LoadPage 60 // Returns whether the loader is idle and able to accept new LoadPage
57 // request. 61 // request.
58 virtual bool IsIdle(); 62 virtual bool IsIdle();
59 63
60 // Returns whether the loader has successfully loaded web contents. 64 // Returns whether the loader has successfully loaded web contents.
61 // Note that |StopLoading()| should be used to clear this state once 65 // Note that |StopLoading()| should be used to clear this state once
62 // the loaded web contents are no longer needed. 66 // the loaded web contents are no longer needed.
63 virtual bool IsLoaded(); 67 virtual bool IsLoaded();
64 68
65 // Overrides the prerender stack adapter for unit testing. 69 // Overrides the prerender stack adapter for unit testing.
66 void SetAdapterForTesting( 70 void SetAdapterForTesting(
67 std::unique_ptr<PrerenderAdapter> prerender_adapter); 71 std::unique_ptr<PrerenderAdapter> prerender_adapter);
68 72
69 // PrerenderAdapter::Observer implementation: 73 // PrerenderAdapter::Observer implementation:
70 void OnPrerenderStopLoading() override; 74 void OnPrerenderStopLoading() override;
71 void OnPrerenderDomContentLoaded() override; 75 void OnPrerenderDomContentLoaded() override;
72 void OnPrerenderStop() override; 76 void OnPrerenderStop() override;
77 void OnPrerenderNetworkBytesChanged(int64_t bytes) override;
73 78
74 // SnapshotController::Client implementation: 79 // SnapshotController::Client implementation:
75 void StartSnapshot() override; 80 void StartSnapshot() override;
76 81
77 private: 82 private:
78 // State of the loader (only one request may be active at a time). 83 // State of the loader (only one request may be active at a time).
79 enum class State { 84 enum class State {
80 IDLE, // No active load request. 85 IDLE, // No active load request.
81 PENDING, // Load request is pending the start of prerendering. 86 PENDING, // Load request is pending the start of prerendering.
82 LOADING, // Loading in progress. 87 LOADING, // Loading in progress.
(...skipping 24 matching lines...) Expand all
107 112
108 // Adapter for handling calls to the prerender stack. 113 // Adapter for handling calls to the prerender stack.
109 std::unique_ptr<PrerenderAdapter> adapter_; 114 std::unique_ptr<PrerenderAdapter> adapter_;
110 115
111 // A WebContents for the active load request that is used to hold the session 116 // A WebContents for the active load request that is used to hold the session
112 // storage namespace for rendering. This will NOT have the loaded page. 117 // storage namespace for rendering. This will NOT have the loaded page.
113 std::unique_ptr<content::WebContents> session_contents_; 118 std::unique_ptr<content::WebContents> session_contents_;
114 119
115 // Callback to call when the active load request completes, fails, or is 120 // Callback to call when the active load request completes, fails, or is
116 // canceled. 121 // canceled.
117 LoadPageCallback callback_; 122 LoadPageCallback load_done_callback_;
123
124 // Callback to call when we know more bytes have loaded from the network.
125 ProgressCallback progress_callback_;
118 126
119 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader); 127 DISALLOW_COPY_AND_ASSIGN(PrerenderingLoader);
120 }; 128 };
121 129
122 } // namespace offline_pages 130 } // namespace offline_pages
123 131
124 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_ 132 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698