| OLD | NEW |
| 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 #include "base/memory/ptr_util.h" |
| 7 #import "ios/chrome/browser/ui/network_activity_indicator_manager.h" | 8 #import "ios/chrome/browser/ui/network_activity_indicator_manager.h" |
| 8 #import "ios/web/public/web_state/web_state.h" | 9 #import "ios/web/public/web_state/web_state.h" |
| 9 | 10 |
| 10 DEFINE_WEB_STATE_USER_DATA_KEY(NetworkActivityIndicatorTabHelper); | 11 DEFINE_WEB_STATE_USER_DATA_KEY(NetworkActivityIndicatorTabHelper); |
| 11 | 12 |
| 12 // static | 13 // static |
| 13 void NetworkActivityIndicatorTabHelper::CreateForWebState( | 14 void NetworkActivityIndicatorTabHelper::CreateForWebState( |
| 14 web::WebState* web_state, | 15 web::WebState* web_state, |
| 15 NSString* tab_id) { | 16 NSString* tab_id) { |
| 16 DCHECK(web_state); | 17 DCHECK(web_state); |
| 17 if (!FromWebState(web_state)) { | 18 if (!FromWebState(web_state)) { |
| 18 web_state->SetUserData(UserDataKey(), new NetworkActivityIndicatorTabHelper( | 19 web_state->SetUserData( |
| 19 web_state, tab_id)); | 20 UserDataKey(), base::WrapUnique(new NetworkActivityIndicatorTabHelper( |
| 21 web_state, tab_id))); |
| 20 } | 22 } |
| 21 } | 23 } |
| 22 | 24 |
| 23 NetworkActivityIndicatorTabHelper::NetworkActivityIndicatorTabHelper( | 25 NetworkActivityIndicatorTabHelper::NetworkActivityIndicatorTabHelper( |
| 24 web::WebState* web_state, | 26 web::WebState* web_state, |
| 25 NSString* tab_id) | 27 NSString* tab_id) |
| 26 : web::WebStateObserver(web_state), network_activity_key_([tab_id copy]) {} | 28 : web::WebStateObserver(web_state), network_activity_key_([tab_id copy]) {} |
| 27 | 29 |
| 28 NetworkActivityIndicatorTabHelper::~NetworkActivityIndicatorTabHelper() { | 30 NetworkActivityIndicatorTabHelper::~NetworkActivityIndicatorTabHelper() { |
| 29 Stop(); | 31 Stop(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 } | 45 } |
| 44 | 46 |
| 45 void NetworkActivityIndicatorTabHelper::Stop() { | 47 void NetworkActivityIndicatorTabHelper::Stop() { |
| 46 NetworkActivityIndicatorManager* shared_manager = | 48 NetworkActivityIndicatorManager* shared_manager = |
| 47 [NetworkActivityIndicatorManager sharedInstance]; | 49 [NetworkActivityIndicatorManager sharedInstance]; |
| 48 // Verifies that there is a network task associated with this instance | 50 // Verifies that there is a network task associated with this instance |
| 49 // before stopping a task, so that this method is idempotent. | 51 // before stopping a task, so that this method is idempotent. |
| 50 if ([shared_manager numNetworkTasksForGroup:network_activity_key_]) | 52 if ([shared_manager numNetworkTasksForGroup:network_activity_key_]) |
| 51 [shared_manager stopNetworkTaskForGroup:network_activity_key_]; | 53 [shared_manager stopNetworkTaskForGroup:network_activity_key_]; |
| 52 } | 54 } |
| OLD | NEW |