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

Side by Side Diff: ios/chrome/browser/ui/preload_controller.h

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix gn check Created 3 years, 8 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_ 5 #ifndef IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
6 #define IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_ 6 #define IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
7 7
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/mac/scoped_nsobject.h"
13 #include "components/prefs/pref_change_registrar.h" 12 #include "components/prefs/pref_change_registrar.h"
14 #import "ios/chrome/browser/net/connection_type_observer_bridge.h" 13 #import "ios/chrome/browser/net/connection_type_observer_bridge.h"
15 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" 14 #import "ios/chrome/browser/prefs/pref_observer_bridge.h"
16 #import "ios/chrome/browser/tabs/tab_delegate.h" 15 #import "ios/chrome/browser/tabs/tab_delegate.h"
17 #import "ios/chrome/browser/ui/omnibox/preload_provider.h" 16 #import "ios/chrome/browser/ui/omnibox/preload_provider.h"
18 #include "ios/web/public/referrer.h" 17 #include "ios/web/public/referrer.h"
19 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 18 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
20 #import "net/url_request/url_fetcher.h" 19 #import "net/url_request/url_fetcher.h"
21 #include "ui/base/page_transition_types.h" 20 #include "ui/base/page_transition_types.h"
22 #include "url/gurl.h" 21 #include "url/gurl.h"
23 22
23 @protocol PreloadControllerDelegate;
24
24 namespace ios { 25 namespace ios {
25 class ChromeBrowserState; 26 class ChromeBrowserState;
26 } 27 }
27 28
28 class PrefetchDelegate; 29 namespace web {
29 @protocol PreloadControllerDelegate; 30 class WebState;
30 @class Tab; 31 }
31 32
32 // ID of the URLFetcher responsible for prefetches. 33 // ID of the URLFetcher responsible for prefetches.
33 extern const int kPreloadControllerURLFetcherID; 34 extern const int kPreloadControllerURLFetcherID;
34 35
35 // PreloadController owns and manages a Tab that contains a prerendered 36 // PreloadController owns and manages a Tab that contains a prerendered
36 // webpage. This class contains methods to queue and cancel prerendering for a 37 // webpage. This class contains methods to queue and cancel prerendering for a
37 // given URL as well as a method to return the prerendered Tab. 38 // given URL as well as a method to return the prerendered Tab.
38 // 39 //
39 // This class also handles queuing and canceling prefetch requests for a given 40 // This class also handles queuing and canceling prefetch requests for a given
40 // URL. The prefetched content is stored in the network layer cache so there is 41 // URL. The prefetched content is stored in the network layer cache so there is
41 // no API to expose that content to users of this class. 42 // no API to expose that content to users of this class.
42 @interface PreloadController : NSObject<CRWNativeContentProvider, 43 @interface PreloadController : NSObject<CRWNativeContentProvider,
43 PrefObserverDelegate, 44 PrefObserverDelegate,
44 PreloadProvider, 45 PreloadProvider,
45 TabDelegate, 46 TabDelegate,
46 CRConnectionTypeObserverBridge> { 47 CRConnectionTypeObserverBridge>
47 @private
48 ios::ChromeBrowserState* browserState_; // Weak.
49
50 // The prerendered tab. Can be nil.
51 base::scoped_nsobject<Tab> tab_;
52
53 // The URL that is prerendered in |tab_|. This can be different from the
54 // value returned by |tab_.url|, for example in cases where there was a
55 // redirect.
56 //
57 // When choosing whether or not to use a prerendered Tab,
58 // BrowserViewController compares the URL being loaded by the omnibox with the
59 // URL of the prerendered Tab. Comparing against the Tab's currently URL
60 // could return false negatives in cases of redirect, hence the need to store
61 // the originally prerendered URL.
62 GURL prerenderedURL_;
63
64 // The URL that is scheduled to be prerendered, its associated transition and
65 // referrer. |scheduledTransition_| and |scheduledReferrer_| are not valid
66 // when |scheduledURL_| is empty.
67 GURL scheduledURL_;
68 ui::PageTransition scheduledTransition_;
69 web::Referrer scheduledReferrer_;
70
71 // The most-recently prefetched URL, or nil if there have been no prefetched
72 // URLs.
73 GURL prefetchedURL_;
74
75 // The URLFetcher and associated delegate used to prefetch URLs. The delegate
76 // simply forwards callbacks from URLFetcher back to the PrerenderController.
77 std::unique_ptr<PrefetchDelegate> prefetcherDelegate_;
78 std::unique_ptr<net::URLFetcher> prefetcher_;
79
80 // Bridge to listen to pref changes.
81 std::unique_ptr<PrefObserverBridge> observerBridge_;
82 // Registrar for pref changes notifications.
83 PrefChangeRegistrar prefChangeRegistrar_;
84 // Observer for the WWAN setting. Contains a valid object only if the
85 // instant setting is set to wifi-only.
86 std::unique_ptr<ConnectionTypeObserverBridge> connectionTypeObserverBridge_;
87
88 // Whether or not the preference is enabled.
89 BOOL enabled_;
90 // Whether or not prerendering is only when on wifi.
91 BOOL wifiOnly_;
92 // Whether or not the current connection is using WWAN.
93 BOOL usingWWAN_;
94
95 // Number of successful prerenders (i.e. the user viewed the prerendered page)
96 // during the lifetime of this controller.
97 int successfulPrerendersPerSessionCount_;
98
99 id<PreloadControllerDelegate> delegate_; // weak
100 }
101
102 // The URL of the currently prerendered Tab. Empty if there is no prerendered 48 // The URL of the currently prerendered Tab. Empty if there is no prerendered
103 // Tab. 49 // Tab.
104 @property(nonatomic, readonly, assign) GURL prerenderedURL; 50 @property(nonatomic, readonly, assign) GURL prerenderedURL;
105 // The URL of the currently prefetched content. Empty if there is no prefetched 51 // The URL of the currently prefetched content. Empty if there is no prefetched
106 // content. 52 // content.
107 @property(nonatomic, readonly, assign) GURL prefetchedURL; 53 @property(nonatomic, readonly, assign) GURL prefetchedURL;
108 @property(nonatomic, assign) id<PreloadControllerDelegate> delegate; 54 @property(nonatomic, assign) id<PreloadControllerDelegate> delegate;
109 55
110 // Designated initializer. 56 // Designated initializer.
111 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState; 57 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState;
112 58
113 // Called when the browser state this object was initialized with is being 59 // Called when the browser state this object was initialized with is being
114 // destroyed. 60 // destroyed.
115 - (void)browserStateDestroyed; 61 - (void)browserStateDestroyed;
116 62
117 // Returns the currently prerendered Tab, or nil if none exists. The caller 63 // Returns the currently prerendered WebState, or nil if none exists. After
118 // must retain the returned Tab if needed. After this method is called, the 64 // this method is called, the PrerenderController reverts to a non-prerendering
119 // PrerenderController reverts to a non-prerendering state. 65 // state.
120 - (Tab*)releasePrerenderContents; 66 - (std::unique_ptr<web::WebState>)releasePrerenderContents;
121 67
122 // Returns true if the content of |url| has been prefetched. 68 // Returns true if the content of |url| has been prefetched.
123 - (BOOL)hasPrefetchedURL:(const GURL&)url; 69 - (BOOL)hasPrefetchedURL:(const GURL&)url;
124 @end 70 @end
125 71
126 #endif // IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_ 72 #endif // IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm ('k') | ios/chrome/browser/ui/preload_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698