OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/android/application_status_listener.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" |
| 13 #include "components/offline_pages/core/background/offliner.h" |
| 14 #include "components/offline_pages/core/offline_page_types.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 |
| 17 namespace content { |
| 18 class BrowserContext; |
| 19 } // namespace content |
| 20 |
| 21 namespace offline_pages { |
| 22 |
| 23 class OfflinerPolicy; |
| 24 class OfflinePageModel; |
| 25 |
| 26 // An Offliner implementation that attempts client-side rendering and saving |
| 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. |
| 29 class BackgroundLoaderOffliner : public Offliner, |
| 30 public content::WebContentsObserver { |
| 31 public: |
| 32 BackgroundLoaderOffliner(content::BrowserContext* browser_context, |
| 33 const OfflinerPolicy* policy, |
| 34 OfflinePageModel* offline_page_model); |
| 35 ~BackgroundLoaderOffliner() override; |
| 36 |
| 37 // Offliner implementation. |
| 38 bool LoadAndSave(const SavePageRequest& request, |
| 39 const CompletionCallback& callback) override; |
| 40 void Cancel() override; |
| 41 |
| 42 // WebContentsObserver implementation. |
| 43 void DidStopLoading() override; |
| 44 |
| 45 protected: |
| 46 // Called to reset internal loader and observer state. |
| 47 virtual void ResetState(); |
| 48 |
| 49 private: |
| 50 friend class TestBackgroundLoaderOffliner; |
| 51 |
| 52 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; |
| 53 |
| 54 // Called when the page has been saved. |
| 55 void OnPageSaved(SavePageResult save_result, int64_t offline_id); |
| 56 |
| 57 // Called when application state has changed. |
| 58 void OnApplicationStateChange( |
| 59 base::android::ApplicationState application_state); |
| 60 |
| 61 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; |
| 62 // Not owned. |
| 63 content::BrowserContext* browser_context_; |
| 64 // Not owned. |
| 65 OfflinePageModel* offline_page_model_; |
| 66 // Tracks pending request, if any. |
| 67 std::unique_ptr<SavePageRequest> pending_request_; |
| 68 // Callback when pending request completes. |
| 69 CompletionCallback completion_callback_; |
| 70 // ApplicationStatusListener to monitor if Chrome moves to the foreground. |
| 71 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 72 // Whether we are on a low-end device. |
| 73 bool is_low_end_device_; |
| 74 // Save state. |
| 75 SaveState save_state_; |
| 76 |
| 77 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| 78 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| 79 }; |
| 80 |
| 81 } // namespace offline_pages |
| 82 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
OLD | NEW |