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

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

Issue 2804703002: [ObjC ARC] Converts ios/chrome/browser/ui:ui_internal_arc to ARC. (Closed)
Patch Set: comments 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
« no previous file with comments | « ios/chrome/browser/ui/preload_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import <UIKit/UIKit.h> 5 #import <UIKit/UIKit.h>
6 6
7 #include "ios/chrome/browser/ui/preload_controller.h" 7 #include "ios/chrome/browser/ui/preload_controller.h"
8 8
9 #include "base/ios/device_util.h" 9 #include "base/ios/device_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
15 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/chrome/browser/pref_names.h" 16 #include "ios/chrome/browser/pref_names.h"
18 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" 17 #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
19 #import "ios/chrome/browser/tabs/tab.h" 18 #import "ios/chrome/browser/tabs/tab.h"
20 #import "ios/chrome/browser/tabs/tab_helper_util.h" 19 #import "ios/chrome/browser/tabs/tab_helper_util.h"
21 #import "ios/chrome/browser/tabs/tab_private.h" 20 #import "ios/chrome/browser/tabs/tab_private.h"
22 #include "ios/chrome/browser/ui/preload_controller_delegate.h" 21 #include "ios/chrome/browser/ui/preload_controller_delegate.h"
23 #include "ios/chrome/browser/ui/prerender_final_status.h" 22 #include "ios/chrome/browser/ui/prerender_final_status.h"
24 #import "ios/web/public/web_state/ui/crw_native_content.h" 23 #import "ios/web/public/web_state/ui/crw_native_content.h"
25 #include "ios/web/public/web_thread.h" 24 #include "ios/web/public/web_thread.h"
26 #import "ios/web/web_state/ui/crw_web_controller.h" 25 #import "ios/web/web_state/ui/crw_web_controller.h"
27 #import "net/base/mac/url_conversions.h" 26 #import "net/base/mac/url_conversions.h"
28 #include "net/url_request/url_fetcher.h" 27 #include "net/url_request/url_fetcher.h"
29 #include "net/url_request/url_fetcher_delegate.h" 28 #include "net/url_request/url_fetcher_delegate.h"
30 #include "ui/base/page_transition_types.h" 29 #include "ui/base/page_transition_types.h"
31 30
31 #if !defined(__has_feature) || !__has_feature(objc_arc)
32 #error "This file requires ARC support."
33 #endif
34
32 // ID of the URLFetcher responsible for prefetches. 35 // ID of the URLFetcher responsible for prefetches.
33 const int kPreloadControllerURLFetcherID = 1; 36 const int kPreloadControllerURLFetcherID = 1;
34 37
35 namespace { 38 namespace {
36 // Delay before starting to prerender a URL. 39 // Delay before starting to prerender a URL.
37 const NSTimeInterval kPrerenderDelay = 0.5; 40 const NSTimeInterval kPrerenderDelay = 0.5;
38 41
39 // The finch experiment to turn off prefetching as a field trial. 42 // The finch experiment to turn off prefetching as a field trial.
40 const char kTabEvictionFieldTrialName[] = "TabEviction"; 43 const char kTabEvictionFieldTrialName[] = "TabEviction";
41 // The associated group. 44 // The associated group.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 98
96 // Delegate to handle completion of URLFetcher operations. 99 // Delegate to handle completion of URLFetcher operations.
97 class PrefetchDelegate : public net::URLFetcherDelegate { 100 class PrefetchDelegate : public net::URLFetcherDelegate {
98 public: 101 public:
99 explicit PrefetchDelegate(PreloadController* owner) : owner_(owner) {} 102 explicit PrefetchDelegate(PreloadController* owner) : owner_(owner) {}
100 void OnURLFetchComplete(const net::URLFetcher* source) override { 103 void OnURLFetchComplete(const net::URLFetcher* source) override {
101 [owner_ prefetchDidComplete:source]; 104 [owner_ prefetchDidComplete:source];
102 } 105 }
103 106
104 private: 107 private:
105 PreloadController* owner_; // weak 108 __weak PreloadController* owner_;
106 }; 109 };
107 110
108 @implementation PreloadController { 111 @implementation PreloadController {
109 ios::ChromeBrowserState* browserState_; // Weak. 112 ios::ChromeBrowserState* browserState_; // Weak.
110 113
111 // The WebState used for prerendering. 114 // The WebState used for prerendering.
112 std::unique_ptr<web::WebState> webState_; 115 std::unique_ptr<web::WebState> webState_;
113 116
114 // The URL that is prerendered in |webState_|. This can be different from 117 // The URL that is prerendered in |webState_|. This can be different from
115 // the value returned by WebState last committed navigation item, for example 118 // the value returned by WebState last committed navigation item, for example
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Whether or not the preference is enabled. 152 // Whether or not the preference is enabled.
150 BOOL enabled_; 153 BOOL enabled_;
151 // Whether or not prerendering is only when on wifi. 154 // Whether or not prerendering is only when on wifi.
152 BOOL wifiOnly_; 155 BOOL wifiOnly_;
153 // Whether or not the current connection is using WWAN. 156 // Whether or not the current connection is using WWAN.
154 BOOL usingWWAN_; 157 BOOL usingWWAN_;
155 158
156 // Number of successful prerenders (i.e. the user viewed the prerendered page) 159 // Number of successful prerenders (i.e. the user viewed the prerendered page)
157 // during the lifetime of this controller. 160 // during the lifetime of this controller.
158 int successfulPrerendersPerSessionCount_; 161 int successfulPrerendersPerSessionCount_;
159
160 id<PreloadControllerDelegate> delegate_; // weak
161 } 162 }
162 163
163 @synthesize prerenderedURL = prerenderedURL_; 164 @synthesize prerenderedURL = prerenderedURL_;
164 @synthesize prefetchedURL = prefetchedURL_; 165 @synthesize prefetchedURL = prefetchedURL_;
165 @synthesize delegate = delegate_; 166 @synthesize delegate = delegate_;
166 167
167 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { 168 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
168 DCHECK(browserState); 169 DCHECK(browserState);
169 DCHECK_CURRENTLY_ON(web::WebThread::UI); 170 DCHECK_CURRENTLY_ON(web::WebThread::UI);
170 if ((self = [super init])) { 171 if ((self = [super init])) {
(...skipping 27 matching lines...) Expand all
198 - (void)browserStateDestroyed { 199 - (void)browserStateDestroyed {
199 [self cancelPrerender]; 200 [self cancelPrerender];
200 connectionTypeObserverBridge_.reset(); 201 connectionTypeObserverBridge_.reset();
201 } 202 }
202 203
203 - (void)dealloc { 204 - (void)dealloc {
204 UMA_HISTOGRAM_COUNTS(kPrerendersPerSessionCountHistogramName, 205 UMA_HISTOGRAM_COUNTS(kPrerendersPerSessionCountHistogramName,
205 successfulPrerendersPerSessionCount_); 206 successfulPrerendersPerSessionCount_);
206 [[NSNotificationCenter defaultCenter] removeObserver:self]; 207 [[NSNotificationCenter defaultCenter] removeObserver:self];
207 [self cancelPrerender]; 208 [self cancelPrerender];
208 [super dealloc];
209 } 209 }
210 210
211 - (void)prerenderURL:(const GURL&)url 211 - (void)prerenderURL:(const GURL&)url
212 referrer:(const web::Referrer&)referrer 212 referrer:(const web::Referrer&)referrer
213 transition:(ui::PageTransition)transition 213 transition:(ui::PageTransition)transition
214 immediately:(BOOL)immediately { 214 immediately:(BOOL)immediately {
215 // TODO(rohitrao): If shouldPrerenderURL returns false, should we cancel any 215 // TODO(rohitrao): If shouldPrerenderURL returns false, should we cancel any
216 // scheduled prerender requests? 216 // scheduled prerender requests?
217 if (![self isPrerenderingEnabled] || ![self shouldPreloadURL:url]) 217 if (![self isPrerenderingEnabled] || ![self shouldPreloadURL:url])
218 return; 218 return;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 scheduledURL_ = GURL(); 476 scheduledURL_ = GURL();
477 } 477 }
478 478
479 #pragma mark - TabDelegate 479 #pragma mark - TabDelegate
480 480
481 - (void)discardPrerender { 481 - (void)discardPrerender {
482 [self schedulePrerenderCancel]; 482 [self schedulePrerenderCancel];
483 } 483 }
484 484
485 @end 485 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/preload_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698