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

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

Issue 2149773002: PrerenderingOffliner will abort background load if it sees chrome transitioning to foreground on lo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nutha try Created 4 years, 5 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_OFFLINER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/android/application_status_listener.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/android/offline_pages/prerendering_loader.h" 12 #include "chrome/browser/android/offline_pages/prerendering_loader.h"
12 #include "components/offline_pages/background/offliner.h" 13 #include "components/offline_pages/background/offliner.h"
13 #include "components/offline_pages/offline_page_model.h" 14 #include "components/offline_pages/offline_page_model.h"
14 #include "components/offline_pages/offline_page_types.h" 15 #include "components/offline_pages/offline_page_types.h"
15 16
16 namespace content { 17 namespace content {
17 class BrowserContext; 18 class BrowserContext;
18 class WebContents; 19 class WebContents;
19 } // namespace content 20 } // namespace content
(...skipping 14 matching lines...) Expand all
34 35
35 // Offliner implementation. 36 // Offliner implementation.
36 bool LoadAndSave(const SavePageRequest& request, 37 bool LoadAndSave(const SavePageRequest& request,
37 const CompletionCallback& callback) override; 38 const CompletionCallback& callback) override;
38 void Cancel() override; 39 void Cancel() override;
39 40
40 // Allows a loader to be injected for testing. This may only be done once 41 // Allows a loader to be injected for testing. This may only be done once
41 // and must be called before any of the Offliner interface methods are called. 42 // and must be called before any of the Offliner interface methods are called.
42 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader); 43 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader);
43 44
45 void SetApplicationStateForTesting(
46 base::android::ApplicationState application_state);
47
44 protected: 48 protected:
45 // Internal method for requesting OfflinePageModel to save page. 49 // Internal method for requesting OfflinePageModel to save page.
46 // Exposed for unit testing. 50 // Exposed for unit testing.
47 // TODO(dougarnett): Consider making OfflinePageModel mockable instead. 51 // TODO(dougarnett): Consider making OfflinePageModel mockable instead.
48 virtual void SavePage(const GURL& url, 52 virtual void SavePage(const GURL& url,
49 const ClientId& client_id, 53 const ClientId& client_id,
50 std::unique_ptr<OfflinePageArchiver> archiver, 54 std::unique_ptr<OfflinePageArchiver> archiver,
51 const SavePageCallback& callback); 55 const SavePageCallback& save_callback);
52 56
53 private: 57 private:
54 // Callback logic for PrerenderingLoader::LoadPage(). 58 // Callback logic for PrerenderingLoader::LoadPage().
55 void OnLoadPageDone(const SavePageRequest& request, 59 void OnLoadPageDone(const SavePageRequest& request,
56 const CompletionCallback& completion_callback,
57 Offliner::RequestStatus load_status, 60 Offliner::RequestStatus load_status,
58 content::WebContents* web_contents); 61 content::WebContents* web_contents);
59 62
60 // Callback logic for OfflinePageModel::SavePage(). 63 // Callback logic for OfflinePageModel::SavePage().
61 void OnSavePageDone(const SavePageRequest& request, 64 void OnSavePageDone(const SavePageRequest& request,
62 const CompletionCallback& completion_callback,
63 SavePageResult save_result, 65 SavePageResult save_result,
64 int64_t offline_id); 66 int64_t offline_id);
65 67
66 PrerenderingLoader* GetOrCreateLoader(); 68 PrerenderingLoader* GetOrCreateLoader();
67 void SetPendingRequest(int64_t request_id); 69
68 void ClearPendingRequest(); 70 // Listener function for changes to application background/foreground state.
71 void OnApplicationStateChange(
72 base::android::ApplicationState application_state);
69 73
70 // Not owned. 74 // Not owned.
71 content::BrowserContext* browser_context_; 75 content::BrowserContext* browser_context_;
72 // Not owned. 76 // Not owned.
73 OfflinePageModel* offline_page_model_; 77 OfflinePageModel* offline_page_model_;
74 // Lazily created. 78 // Lazily created.
75 std::unique_ptr<PrerenderingLoader> loader_; 79 std::unique_ptr<PrerenderingLoader> loader_;
76 // Tracks pending request, if any. Owned copy. 80 // Tracks pending request, if any. Owned copy.
77 // May be used to ensure a callback applies to the pending request (e.g., in 81 // May be used to ensure a callback applies to the pending request (e.g., in
78 // case we receive a save page callback for an old, canceled request). 82 // case we receive a save page callback for an old, canceled request).
79 std::unique_ptr<SavePageRequest> pending_request_; 83 std::unique_ptr<SavePageRequest> pending_request_;
84 // Callback to call when pending request completes/fails.
85 CompletionCallback completion_callback_;
86 // ApplicationStatusListener to monitor if the Chrome moves to the foreground.
87 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
80 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_; 88 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_;
81 89
82 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner); 90 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner);
83 }; 91 };
84 92
85 } // namespace offline_pages 93 } // namespace offline_pages
86 94
87 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ 95 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698