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_model.h" | |
fgorski
2016/12/12 17:59:16
nit: this likely can be forward declared.
chili
2016/12/15 10:34:39
Done.
| |
15 #include "components/offline_pages/core/offline_page_types.h" | |
16 #include "content/public/browser/web_contents_observer.h" | |
17 | |
18 namespace content { | |
19 class BrowserContext; | |
20 } // namespace content | |
21 | |
22 namespace offline_pages { | |
23 | |
24 class OfflinerPolicy; | |
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 explicit BackgroundLoaderOffliner(content::BrowserContext* browser_context, | |
fgorski
2016/12/12 17:59:16
nit: no need for explicit if number of arguments !
chili
2016/12/15 10:34:39
Done.
| |
33 const OfflinerPolicy* policy, | |
34 OfflinePageModel* offline_page_model); | |
35 ~BackgroundLoaderOffliner() override; | |
36 | |
37 // Offliner implementation | |
fgorski
2016/12/12 17:59:16
nit: Put colon or period at the end, please.
chili
2016/12/15 10:34:39
Done.
| |
38 bool LoadAndSave(const SavePageRequest& request, | |
39 const CompletionCallback& callback) override; | |
40 void Cancel() override; | |
41 | |
42 // WebContentsObserver implementation | |
fgorski
2016/12/12 17:59:16
Ditto.
chili
2016/12/15 10:34:39
Done.
| |
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; | |
fgorski
2016/12/12 17:59:16
nit: add empty line, please.
chili
2016/12/15 10:34:39
Done.
| |
51 // Called when the page has been saved. | |
52 void OnPageSaved(SavePageResult save_result, int64_t offline_id); | |
53 | |
54 // Called when application state has changed. | |
55 void OnApplicationStateChange( | |
56 base::android::ApplicationState application_state); | |
57 | |
58 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; | |
59 // Not owned. | |
60 content::BrowserContext* browser_context_; | |
61 // Not owned. | |
62 OfflinePageModel* offline_page_model_; | |
63 // Tracks pending request, if any. | |
64 std::unique_ptr<SavePageRequest> pending_request_; | |
65 // Callback when pending request completes. | |
66 CompletionCallback completion_callback_; | |
67 // ApplicationStatusListener to monitor if Chrome moves to the foreground. | |
68 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | |
69 // Whether we are on a low-end device. | |
70 bool is_low_end_device_; | |
71 | |
72 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; | |
73 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); | |
74 }; | |
75 | |
76 } // namespace offline_pages | |
77 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | |
OLD | NEW |