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

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

Issue 2589803002: Upstream Chrome on iOS source code [6/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
6 #define IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
7
8 #import <UIKit/UIKit.h>
9
10 #include <memory>
11
12 #include "base/mac/scoped_nsobject.h"
13 #include "components/prefs/pref_change_registrar.h"
14 #import "ios/chrome/browser/net/connection_type_observer_bridge.h"
15 #import "ios/chrome/browser/prefs/pref_observer_bridge.h"
16 #import "ios/chrome/browser/tabs/tab_delegate.h"
17 #import "ios/chrome/browser/ui/omnibox/preload_provider.h"
18 #include "ios/web/public/referrer.h"
19 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
20 #import "net/url_request/url_fetcher.h"
21 #include "ui/base/page_transition_types.h"
22 #include "url/gurl.h"
23
24 namespace ios {
25 class ChromeBrowserState;
26 }
27
28 class PrefetchDelegate;
29 @protocol PreloadControllerDelegate;
30 @class Tab;
31
32 // ID of the URLFetcher responsible for prefetches.
33 extern const int kPreloadControllerURLFetcherID;
34
35 // PreloadController owns and manages a Tab that contains a prerendered
36 // 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 //
39 // 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 // no API to expose that content to users of this class.
42 @interface PreloadController : NSObject<CRWNativeContentProvider,
43 PrefObserverDelegate,
44 PreloadProvider,
45 TabDelegate,
46 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
103 // Tab.
104 @property(nonatomic, readonly, assign) GURL prerenderedURL;
105 // The URL of the currently prefetched content. Empty if there is no prefetched
106 // content.
107 @property(nonatomic, readonly, assign) GURL prefetchedURL;
108 @property(nonatomic, assign) id<PreloadControllerDelegate> delegate;
109
110 // Designated initializer.
111 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState;
112
113 // Returns the currently prerendered Tab, or nil if none exists. The caller
114 // must retain the returned Tab if needed. After this method is called, the
115 // PrerenderController reverts to a non-prerendering state.
116 - (Tab*)releasePrerenderContents;
117
118 // Returns true if the content of |url| has been prefetched.
119 - (BOOL)hasPrefetchedURL:(const GURL&)url;
120 @end
121
122 #endif // IOS_CHROME_BROWSER_UI_PRELOAD_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/popup_menu/popup_menu_view.mm ('k') | ios/chrome/browser/ui/preload_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698