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

Side by Side Diff: ios/chrome/browser/web/network_activity_indicator_tab_helper.mm

Issue 2585863002: Ensure network activity is stopped on deallocation. (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
« no previous file with comments | « no previous file | 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 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 #import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h" 5 #import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h"
6 6
7 #import "ios/chrome/browser/ui/network_activity_indicator_manager.h" 7 #import "ios/chrome/browser/ui/network_activity_indicator_manager.h"
8 #import "ios/web/public/web_state/web_state.h" 8 #import "ios/web/public/web_state/web_state.h"
9 9
10 DEFINE_WEB_STATE_USER_DATA_KEY(NetworkActivityIndicatorTabHelper); 10 DEFINE_WEB_STATE_USER_DATA_KEY(NetworkActivityIndicatorTabHelper);
11 11
12 // static 12 // static
13 void NetworkActivityIndicatorTabHelper::CreateForWebState( 13 void NetworkActivityIndicatorTabHelper::CreateForWebState(
14 web::WebState* web_state, 14 web::WebState* web_state,
15 NSString* tab_id) { 15 NSString* tab_id) {
16 DCHECK(web_state); 16 DCHECK(web_state);
17 if (!FromWebState(web_state)) { 17 if (!FromWebState(web_state)) {
18 web_state->SetUserData(UserDataKey(), new NetworkActivityIndicatorTabHelper( 18 web_state->SetUserData(UserDataKey(), new NetworkActivityIndicatorTabHelper(
19 web_state, tab_id)); 19 web_state, tab_id));
20 } 20 }
21 } 21 }
22 22
23 NetworkActivityIndicatorTabHelper::NetworkActivityIndicatorTabHelper( 23 NetworkActivityIndicatorTabHelper::NetworkActivityIndicatorTabHelper(
24 web::WebState* web_state, 24 web::WebState* web_state,
25 NSString* tab_id) 25 NSString* tab_id)
26 : web::WebStateObserver(web_state), network_activity_key_([tab_id copy]) {} 26 : web::WebStateObserver(web_state), network_activity_key_([tab_id copy]) {}
27 27
28 NetworkActivityIndicatorTabHelper::~NetworkActivityIndicatorTabHelper() {} 28 NetworkActivityIndicatorTabHelper::~NetworkActivityIndicatorTabHelper() {
29 NetworkActivityIndicatorManager* shared_manager =
30 [NetworkActivityIndicatorManager sharedInstance];
31 // Verifies that there is a network task associated with this instance
32 // before stopping a task, so that this method is idempotent.
33 if ([shared_manager numNetworkTasksForGroup:network_activity_key_])
34 [shared_manager stopNetworkTaskForGroup:network_activity_key_];
35 }
29 36
30 void NetworkActivityIndicatorTabHelper::DidStartLoading() { 37 void NetworkActivityIndicatorTabHelper::DidStartLoading() {
31 NetworkActivityIndicatorManager* shared_manager = 38 NetworkActivityIndicatorManager* shared_manager =
32 [NetworkActivityIndicatorManager sharedInstance]; 39 [NetworkActivityIndicatorManager sharedInstance];
33 // Verifies that there are not any network tasks associated with this instance 40 // Verifies that there are not any network tasks associated with this instance
34 // before starting another task, so that this method is idempotent. 41 // before starting another task, so that this method is idempotent.
35 if (![shared_manager numNetworkTasksForGroup:network_activity_key_]) 42 if (![shared_manager numNetworkTasksForGroup:network_activity_key_])
36 [shared_manager startNetworkTaskForGroup:network_activity_key_]; 43 [shared_manager startNetworkTaskForGroup:network_activity_key_];
37 } 44 }
38 45
39 void NetworkActivityIndicatorTabHelper::DidStopLoading() { 46 void NetworkActivityIndicatorTabHelper::DidStopLoading() {
40 NetworkActivityIndicatorManager* shared_manager = 47 NetworkActivityIndicatorManager* shared_manager =
41 [NetworkActivityIndicatorManager sharedInstance]; 48 [NetworkActivityIndicatorManager sharedInstance];
42 // Verifies that there is a network task associated with this instance 49 // Verifies that there is a network task associated with this instance
43 // before stopping a task, so that this method is idempotent. 50 // before stopping a task, so that this method is idempotent.
44 if ([shared_manager numNetworkTasksForGroup:network_activity_key_]) 51 if ([shared_manager numNetworkTasksForGroup:network_activity_key_])
45 [shared_manager stopNetworkTaskForGroup:network_activity_key_]; 52 [shared_manager stopNetworkTaskForGroup:network_activity_key_];
46 } 53 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698