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

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

Issue 2748053004: [Offline Pages] Allow BackgroundLoader to track network bytes using prerenderer hook-in. (Closed)
Patch Set: Created 3 years, 9 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 | chrome/browser/android/offline_pages/background_loader_offliner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BACKGROUND_LOADER_OFFLINER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/android/application_status_listener.h" 10 #include "base/android/application_status_listener.h"
(...skipping 16 matching lines...) Expand all
27 // of an offline page. It uses the BackgroundLoader to load the page and the 27 // of an offline page. It uses the BackgroundLoader to load the page and the
28 // OfflinePageModel to save it. Only one request may be active at a time. 28 // OfflinePageModel to save it. Only one request may be active at a time.
29 class BackgroundLoaderOffliner : public Offliner, 29 class BackgroundLoaderOffliner : public Offliner,
30 public content::WebContentsObserver { 30 public content::WebContentsObserver {
31 public: 31 public:
32 BackgroundLoaderOffliner(content::BrowserContext* browser_context, 32 BackgroundLoaderOffliner(content::BrowserContext* browser_context,
33 const OfflinerPolicy* policy, 33 const OfflinerPolicy* policy,
34 OfflinePageModel* offline_page_model); 34 OfflinePageModel* offline_page_model);
35 ~BackgroundLoaderOffliner() override; 35 ~BackgroundLoaderOffliner() override;
36 36
37 static BackgroundLoaderOffliner* FromWebContents(
38 content::WebContents* contents);
39
37 // Offliner implementation. 40 // Offliner implementation.
38 bool LoadAndSave(const SavePageRequest& request, 41 bool LoadAndSave(const SavePageRequest& request,
39 const CompletionCallback& completion_callback, 42 const CompletionCallback& completion_callback,
40 const ProgressCallback& progress_callback) override; 43 const ProgressCallback& progress_callback) override;
41 void Cancel(const CancelCallback& callback) override; 44 void Cancel(const CancelCallback& callback) override;
42 bool HandleTimeout(const SavePageRequest& request) override; 45 bool HandleTimeout(const SavePageRequest& request) override;
43 46
44 // WebContentsObserver implementation. 47 // WebContentsObserver implementation.
45 void DidStopLoading() override; 48 void DidStopLoading() override;
46 void RenderProcessGone(base::TerminationStatus status) override; 49 void RenderProcessGone(base::TerminationStatus status) override;
47 void WebContentsDestroyed() override; 50 void WebContentsDestroyed() override;
48 void DidFinishNavigation( 51 void DidFinishNavigation(
49 content::NavigationHandle* navigation_handle) override; 52 content::NavigationHandle* navigation_handle) override;
50 53
51 void SetPageDelayForTest(long delay_ms); 54 void SetPageDelayForTest(long delay_ms);
55 void OnNetworkBytesChanged(int64_t bytes);
52 56
53 protected: 57 protected:
54 // Called to reset internal loader and observer state. 58 // Called to reset internal loader and observer state.
55 virtual void ResetState(); 59 virtual void ResetState();
56 60
57 private: 61 private:
58 friend class TestBackgroundLoaderOffliner; 62 friend class TestBackgroundLoaderOffliner;
59 63
60 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; 64 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE };
61 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE }; 65 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE };
(...skipping 12 matching lines...) Expand all
74 78
75 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; 79 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_;
76 // Not owned. 80 // Not owned.
77 content::BrowserContext* browser_context_; 81 content::BrowserContext* browser_context_;
78 // Not owned. 82 // Not owned.
79 OfflinePageModel* offline_page_model_; 83 OfflinePageModel* offline_page_model_;
80 // Tracks pending request, if any. 84 // Tracks pending request, if any.
81 std::unique_ptr<SavePageRequest> pending_request_; 85 std::unique_ptr<SavePageRequest> pending_request_;
82 // Callback when pending request completes. 86 // Callback when pending request completes.
83 CompletionCallback completion_callback_; 87 CompletionCallback completion_callback_;
88 // Callback to report progress.
89 ProgressCallback progress_callback_;
84 // ApplicationStatusListener to monitor if Chrome moves to the foreground. 90 // ApplicationStatusListener to monitor if Chrome moves to the foreground.
85 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; 91 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
86 // Whether we are on a low-end device. 92 // Whether we are on a low-end device.
87 bool is_low_end_device_; 93 bool is_low_end_device_;
88 94
89 // Save state. 95 // Save state.
90 SaveState save_state_; 96 SaveState save_state_;
91 // Page load state. 97 // Page load state.
92 PageLoadState page_load_state_; 98 PageLoadState page_load_state_;
93 // Seconds to delay before taking snapshot. 99 // Seconds to delay before taking snapshot.
94 long page_delay_ms_; 100 long page_delay_ms_;
101 // Network bytes loaded.
102 int64_t network_bytes_;
95 103
96 // Callback for cancel. 104 // Callback for cancel.
97 CancelCallback cancel_callback_; 105 CancelCallback cancel_callback_;
98 106
99 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; 107 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_;
100 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); 108 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner);
101 }; 109 };
102 110
103 } // namespace offline_pages 111 } // namespace offline_pages
104 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ 112 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/background_loader_offliner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698