Chromium Code Reviews| Index: chrome/browser/android/offline_pages/background_loader_offliner.h |
| diff --git a/chrome/browser/android/offline_pages/background_loader_offliner.h b/chrome/browser/android/offline_pages/background_loader_offliner.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..42cbd07e6ff88d475a94ec249fee7e90d4dc4ffb |
| --- /dev/null |
| +++ b/chrome/browser/android/offline_pages/background_loader_offliner.h |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| +#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/android/application_status_listener.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/offline_pages/background/offliner.h" |
| +#include "components/offline_pages/content/background_loader/background_loader_contents.h" |
| +#include "components/offline_pages/offline_page_model.h" |
| +#include "components/offline_pages/offline_page_types.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} // namespace content |
| + |
| +namespace offline_pages { |
| + |
| +class OfflinerPolicy; |
| + |
| +// An Offliner implementation that attempts client-side rendering and saving |
| +// of an offline page. It uses the BackgroundLoader to load the page and the |
| +// OfflinePageModel to save it. Only one request may be active at a time. |
| +class BackgroundLoaderOffliner : public Offliner, |
| + public content::WebContentsObserver { |
| + public: |
| + explicit BackgroundLoaderOffliner(content::BrowserContext* browser_context, |
| + const OfflinerPolicy* policy, |
| + OfflinePageModel* offline_page_model); |
| + ~BackgroundLoaderOffliner() override; |
| + |
| + // Offliner implementation |
| + bool LoadAndSave(const SavePageRequest& request, |
| + const CompletionCallback& callback) override; |
| + void Cancel() override; |
| + |
| + // WebContentsObserver implementation |
| + void DidStopLoading() override; |
| + |
| + private: |
| + friend class TestBackgroundContentsOffliner; |
| + // Called when the page has been saved. |
| + void OnPageSaved(SavePageResult save_result, int64_t offline_id); |
| + |
| + // Called to reset internal loader and observer state. |
| + // TODO(chili): Remove after RequestCoordinator can handle multiple offliners. |
| + void ResetState(); |
| + |
| + // Called when application state has changed. |
| + void OnApplicationStateChange( |
| + base::android::ApplicationState application_state); |
| + |
| + // Not owned. |
| + content::BrowserContext* browser_context_; |
| + // Not owned. |
| + OfflinePageModel* offline_page_model_; |
| + // Tracks pending request, if any. |
| + std::unique_ptr<SavePageRequest> pending_request_; |
| + // Callback when pending request completes. |
| + CompletionCallback completion_callback_; |
| + std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; |
| + // ApplicationStatusListener to monitor if Chrome moves to the foreground. |
| + std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| + // Whether we are on a low-end device. |
|
Pete Williamson
2016/12/01 02:03:38
We needed to track this for the prerenderer, becau
chili
2016/12/09 22:45:57
I'm allowing for possibility. We can remove later
|
| + bool is_low_end_device_; |
| + |
| + base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| +}; |
| + |
| +} // namespace offline_pages |
| +#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |