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

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

Issue 2587173002: Cleanup NetworkActivityIndicatorTabHelper and add unittest. (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
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 = 29 Stop();
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 } 30 }
36 31
37 void NetworkActivityIndicatorTabHelper::DidStartLoading() { 32 void NetworkActivityIndicatorTabHelper::DidStartLoading() {
38 NetworkActivityIndicatorManager* shared_manager = 33 NetworkActivityIndicatorManager* shared_manager =
39 [NetworkActivityIndicatorManager sharedInstance]; 34 [NetworkActivityIndicatorManager sharedInstance];
40 // Verifies that there are not any network tasks associated with this instance 35 // Verifies that there are not any network tasks associated with this instance
41 // before starting another task, so that this method is idempotent. 36 // before starting another task, so that this method is idempotent.
42 if (![shared_manager numNetworkTasksForGroup:network_activity_key_]) 37 if (![shared_manager numNetworkTasksForGroup:network_activity_key_])
43 [shared_manager startNetworkTaskForGroup:network_activity_key_]; 38 [shared_manager startNetworkTaskForGroup:network_activity_key_];
44 } 39 }
45 40
46 void NetworkActivityIndicatorTabHelper::DidStopLoading() { 41 void NetworkActivityIndicatorTabHelper::DidStopLoading() {
42 Stop();
43 }
44
45 void NetworkActivityIndicatorTabHelper::Stop() {
Eugene But (OOO till 7-30) 2016/12/19 20:53:01 nit: Could you please keep the same method order a
michaeldo 2016/12/19 21:43:44 Fixed.
47 NetworkActivityIndicatorManager* shared_manager = 46 NetworkActivityIndicatorManager* shared_manager =
48 [NetworkActivityIndicatorManager sharedInstance]; 47 [NetworkActivityIndicatorManager sharedInstance];
49 // Verifies that there is a network task associated with this instance 48 // Verifies that there is a network task associated with this instance
50 // before stopping a task, so that this method is idempotent. 49 // before stopping a task, so that this method is idempotent.
51 if ([shared_manager numNetworkTasksForGroup:network_activity_key_]) 50 if ([shared_manager numNetworkTasksForGroup:network_activity_key_])
52 [shared_manager stopNetworkTaskForGroup:network_activity_key_]; 51 [shared_manager stopNetworkTaskForGroup:network_activity_key_];
53 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698