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

Side by Side Diff: ios/chrome/browser/browsing_data/browsing_data_removal_controller.mm

Issue 2892663003: [ObjC ARC] Converts ios/chrome/browser/browsing_data:browsing_data_internal to ARC. (Closed)
Patch Set: Created 3 years, 7 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/browsing_data/BUILD.gn ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browsing_data/browsing_data_removal_controller.h" 5 #import "ios/chrome/browser/browsing_data/browsing_data_removal_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #import "base/ios/weak_nsobject.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #import "base/mac/bind_objc_block.h" 15 #import "base/mac/bind_objc_block.h"
17 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
18 #include "components/open_from_clipboard/clipboard_recent_content.h" 17 #include "components/open_from_clipboard/clipboard_recent_content.h"
19 #include "components/signin/ios/browser/account_consistency_service.h" 18 #include "components/signin/ios/browser/account_consistency_service.h"
20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
21 #include "ios/chrome/browser/browsing_data/browsing_data_remover_helper.h" 20 #include "ios/chrome/browser/browsing_data/browsing_data_remover_helper.h"
22 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" 21 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h"
23 #include "ios/chrome/browser/callback_counter.h" 22 #include "ios/chrome/browser/callback_counter.h"
24 #include "ios/chrome/browser/sessions/session_util.h" 23 #include "ios/chrome/browser/sessions/session_util.h"
25 #include "ios/chrome/browser/signin/account_consistency_service_factory.h" 24 #include "ios/chrome/browser/signin/account_consistency_service_factory.h"
26 #import "ios/chrome/browser/snapshots/snapshots_util.h" 25 #import "ios/chrome/browser/snapshots/snapshots_util.h"
27 #import "ios/chrome/browser/ui/browser_view_controller.h" 26 #import "ios/chrome/browser/ui/browser_view_controller.h"
28 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 27 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
29 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad ata.h" 28 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad ata.h"
30 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white list_manager.h" 29 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white list_manager.h"
31 #include "ios/web/public/web_thread.h" 30 #include "ios/web/public/web_thread.h"
32 #import "ios/web/public/web_view_creation_util.h" 31 #import "ios/web/public/web_view_creation_util.h"
33 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 32 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
34 #include "net/cookies/cookie_store.h" 33 #include "net/cookies/cookie_store.h"
35 #include "net/ssl/channel_id_service.h" 34 #include "net/ssl/channel_id_service.h"
36 #include "net/ssl/channel_id_store.h" 35 #include "net/ssl/channel_id_store.h"
37 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
38 #include "net/url_request/url_request_context_getter.h" 37 #include "net/url_request/url_request_context_getter.h"
39 38
39 #if !defined(__has_feature) || !__has_feature(objc_arc)
40 #error "This file requires ARC support."
41 #endif
42
40 namespace { 43 namespace {
41 // Empty callback used by DeleteAllCreatedBetweenAsync below. 44 // Empty callback used by DeleteAllCreatedBetweenAsync below.
42 void DoNothing(int n) {} 45 void DoNothing(int n) {}
43 } 46 }
44 47
45 @interface BrowsingDataRemovalController () 48 @interface BrowsingDataRemovalController ()
46 // Removes data used by the Google App Launcher. 49 // Removes data used by the Google App Launcher.
47 - (void)removeGALData; 50 - (void)removeGALData;
48 // Removes browsing data that is created by web views associated with 51 // Removes browsing data that is created by web views associated with
49 // |browserState|. |mask| is obtained from 52 // |browserState|. |mask| is obtained from
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Called when a removal operation for |browserState| finishes. 107 // Called when a removal operation for |browserState| finishes.
105 - (void)decrementPendingRemovalCountForBrowserState: 108 - (void)decrementPendingRemovalCountForBrowserState:
106 (ios::ChromeBrowserState*)browserState; 109 (ios::ChromeBrowserState*)browserState;
107 @end 110 @end
108 111
109 @implementation BrowsingDataRemovalController { 112 @implementation BrowsingDataRemovalController {
110 // Wrapper around IOSChromeBrowsingDataRemover that serializes removal 113 // Wrapper around IOSChromeBrowsingDataRemover that serializes removal
111 // operations. 114 // operations.
112 std::unique_ptr<BrowsingDataRemoverHelper> _browsingDataRemoverHelper; 115 std::unique_ptr<BrowsingDataRemoverHelper> _browsingDataRemoverHelper;
113 // The delegate. 116 // The delegate.
114 base::WeakNSProtocol<id<BrowsingDataRemovalControllerDelegate>> _delegate; 117 __weak id<BrowsingDataRemovalControllerDelegate> _delegate;
rohitrao (ping after 24h) 2017/06/05 14:37:10 Should this just become a property instead?
115 // A map that tracks the number of pending removals for a given 118 // A map that tracks the number of pending removals for a given
116 // ChromeBrowserState. 119 // ChromeBrowserState.
117 base::hash_map<ios::ChromeBrowserState*, int> _pendingRemovalCount; 120 base::hash_map<ios::ChromeBrowserState*, int> _pendingRemovalCount;
118 } 121 }
119 122
120 - (instancetype)initWithDelegate: 123 - (instancetype)initWithDelegate:
121 (id<BrowsingDataRemovalControllerDelegate>)delegate { 124 (id<BrowsingDataRemovalControllerDelegate>)delegate {
122 if ((self = [super init])) { 125 if ((self = [super init])) {
123 DCHECK(delegate); 126 DCHECK(delegate);
124 _browsingDataRemoverHelper.reset(new BrowsingDataRemoverHelper()); 127 _browsingDataRemoverHelper.reset(new BrowsingDataRemoverHelper());
125 _delegate.reset(delegate); 128 _delegate = delegate;
126 } 129 }
127 return self; 130 return self;
128 } 131 }
129 132
130 - (instancetype)init { 133 - (instancetype)init {
131 NOTREACHED(); 134 NOTREACHED();
132 return nil; 135 return nil;
133 } 136 }
134 137
135 - (void)removeBrowsingDataFromBrowserState: 138 - (void)removeBrowsingDataFromBrowserState:
(...skipping 15 matching lines...) Expand all
151 ios::AccountConsistencyServiceFactory::GetForBrowserState( 154 ios::AccountConsistencyServiceFactory::GetForBrowserState(
152 browserState)) { 155 browserState)) {
153 accountConsistencyService->OnBrowsingDataRemoved(); 156 accountConsistencyService->OnBrowsingDataRemoved();
154 } 157 }
155 if (completionHandler) { 158 if (completionHandler) {
156 completionHandler(); 159 completionHandler();
157 } 160 }
158 }; 161 };
159 162
160 scoped_refptr<CallbackCounter> callbackCounter = 163 scoped_refptr<CallbackCounter> callbackCounter =
161 new CallbackCounter(base::BindBlock(browsingDataCleared)); 164 new CallbackCounter(base::BindBlockArc(browsingDataCleared));
162 ProceduralBlock decrementCallbackCounterCount = ^{ 165 ProceduralBlock decrementCallbackCounterCount = ^{
163 callbackCounter->DecrementCount(); 166 callbackCounter->DecrementCount();
164 }; 167 };
165 168
166 callbackCounter->IncrementCount(); 169 callbackCounter->IncrementCount();
167 base::Time beginDeleteTime = 170 base::Time beginDeleteTime =
168 browsing_data::CalculateBeginDeleteTime(timePeriod); 171 browsing_data::CalculateBeginDeleteTime(timePeriod);
169 [self removeIOSSpecificBrowsingDataFromBrowserState:browserState 172 [self removeIOSSpecificBrowsingDataFromBrowserState:browserState
170 mask:mask 173 mask:mask
171 deleteBegin:beginDeleteTime 174 deleteBegin:beginDeleteTime
172 completionHandler: 175 completionHandler:
173 decrementCallbackCounterCount]; 176 decrementCallbackCounterCount];
174 177
175 if (mask & IOSChromeBrowsingDataRemover::REMOVE_DOWNLOADS) { 178 if (mask & IOSChromeBrowsingDataRemover::REMOVE_DOWNLOADS) {
176 DCHECK_EQ(browsing_data::TimePeriod::ALL_TIME, timePeriod) 179 DCHECK_EQ(browsing_data::TimePeriod::ALL_TIME, timePeriod)
177 << "Partial clearing not supported"; 180 << "Partial clearing not supported";
178 callbackCounter->IncrementCount(); 181 callbackCounter->IncrementCount();
179 [_delegate 182 [_delegate
180 removeExternalFilesForBrowserState:browserState 183 removeExternalFilesForBrowserState:browserState
181 completionHandler:decrementCallbackCounterCount]; 184 completionHandler:decrementCallbackCounterCount];
182 } 185 }
183 186
184 if (!browserState->IsOffTheRecord()) { 187 if (!browserState->IsOffTheRecord()) {
185 callbackCounter->IncrementCount(); 188 callbackCounter->IncrementCount();
186 _browsingDataRemoverHelper->Remove(browserState, mask, timePeriod, 189 _browsingDataRemoverHelper->Remove(browserState, mask, timePeriod,
187 base::BindBlock(^{ 190 base::BindBlockArc(^{
188 callbackCounter->DecrementCount(); 191 callbackCounter->DecrementCount();
189 })); 192 }));
190 } 193 }
191 } 194 }
192 195
193 - (void)removeIOSSpecificIncognitoBrowsingDataFromBrowserState: 196 - (void)removeIOSSpecificIncognitoBrowsingDataFromBrowserState:
194 (ios::ChromeBrowserState*)browserState 197 (ios::ChromeBrowserState*)browserState
195 mask:(int)mask 198 mask:(int)mask
196 completionHandler: 199 completionHandler:
197 (ProceduralBlock) 200 (ProceduralBlock)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 completionHandler: 272 completionHandler:
270 (ProceduralBlock)completionHandler { 273 (ProceduralBlock)completionHandler {
271 // TODO(crbug.com/480654): Remove this check once browsing data partitioning 274 // TODO(crbug.com/480654): Remove this check once browsing data partitioning
272 // between BrowserStates is achieved. 275 // between BrowserStates is achieved.
273 if (browserState->IsOffTheRecord()) { 276 if (browserState->IsOffTheRecord()) {
274 if (completionHandler) { 277 if (completionHandler) {
275 dispatch_async(dispatch_get_main_queue(), completionHandler); 278 dispatch_async(dispatch_get_main_queue(), completionHandler);
276 } 279 }
277 return; 280 return;
278 } 281 }
279 scoped_refptr<CallbackCounter> callbackCounter = 282 scoped_refptr<CallbackCounter> callbackCounter = new CallbackCounter(
280 new CallbackCounter(base::BindBlock(completionHandler ? completionHandler 283 base::BindBlockArc(completionHandler ? completionHandler
281 : ^{ 284 : ^{
282 })); 285 }));
283 286
284 // Note: Before adding any method below, make sure that it can finish clearing 287 // Note: Before adding any method below, make sure that it can finish clearing
285 // browsing data even when |browserState| is destroyed after this method call. 288 // browsing data even when |browserState| is destroyed after this method call.
286 289
287 callbackCounter->IncrementCount(); 290 callbackCounter->IncrementCount();
288 [self removeWKWebViewCreatedBrowsingDataFromBrowserState:browserState 291 [self removeWKWebViewCreatedBrowsingDataFromBrowserState:browserState
289 mask:mask 292 mask:mask
290 deleteBegin:deleteBegin 293 deleteBegin:deleteBegin
291 completionHandler:^{ 294 completionHandler:^{
292 callbackCounter->DecrementCount(); 295 callbackCounter->DecrementCount();
293 }]; 296 }];
294 } 297 }
295 298
296 - (void) 299 - (void)
297 removeWKWebViewCreatedBrowsingDataFromBrowserState: 300 removeWKWebViewCreatedBrowsingDataFromBrowserState:
298 (ios::ChromeBrowserState*)browserState 301 (ios::ChromeBrowserState*)browserState
299 mask:(int)mask 302 mask:(int)mask
300 deleteBegin:(base::Time)deleteBegin 303 deleteBegin:(base::Time)deleteBegin
301 completionHandler: 304 completionHandler:
302 (ProceduralBlock)completionHandler { 305 (ProceduralBlock)completionHandler {
303 scoped_refptr<CallbackCounter> callbackCounter = 306 scoped_refptr<CallbackCounter> callbackCounter = new CallbackCounter(
304 new CallbackCounter(base::BindBlock(completionHandler ? completionHandler 307 base::BindBlockArc(completionHandler ? completionHandler
305 : ^{ 308 : ^{
306 })); 309 }));
307 ProceduralBlock decrementCallbackCounterCount = ^{ 310 ProceduralBlock decrementCallbackCounterCount = ^{
308 callbackCounter->DecrementCount(); 311 callbackCounter->DecrementCount();
309 }; 312 };
310 313
311 // Converts browsing data types from 314 // Converts browsing data types from
312 // IOSChromeBrowsingDataRemover::RemoveDataMask to 315 // IOSChromeBrowsingDataRemover::RemoveDataMask to
313 // WKWebsiteDataStore strings. 316 // WKWebsiteDataStore strings.
314 base::scoped_nsobject<NSMutableSet> dataTypesToRemove( 317 NSMutableSet* dataTypesToRemove = [[NSMutableSet alloc] init];
315 [[NSMutableSet alloc] init]);
316 if (mask & IOSChromeBrowsingDataRemover::REMOVE_CACHE_STORAGE) { 318 if (mask & IOSChromeBrowsingDataRemover::REMOVE_CACHE_STORAGE) {
317 [dataTypesToRemove addObject:WKWebsiteDataTypeDiskCache]; 319 [dataTypesToRemove addObject:WKWebsiteDataTypeDiskCache];
318 [dataTypesToRemove addObject:WKWebsiteDataTypeMemoryCache]; 320 [dataTypesToRemove addObject:WKWebsiteDataTypeMemoryCache];
319 } 321 }
320 if (mask & IOSChromeBrowsingDataRemover::REMOVE_APPCACHE) { 322 if (mask & IOSChromeBrowsingDataRemover::REMOVE_APPCACHE) {
321 [dataTypesToRemove addObject:WKWebsiteDataTypeOfflineWebApplicationCache]; 323 [dataTypesToRemove addObject:WKWebsiteDataTypeOfflineWebApplicationCache];
322 } 324 }
323 WKWebView* markerWKWebView = nil; 325 WKWebView* markerWKWebView = nil;
324 if (mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) { 326 if (mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) {
325 // TODO(crbug.com/661630): This approach of creating a WKWebView to clear 327 // TODO(crbug.com/661630): This approach of creating a WKWebView to clear
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (mask & IOSChromeBrowsingDataRemover::REMOVE_HISTORY) { 404 if (mask & IOSChromeBrowsingDataRemover::REMOVE_HISTORY) {
403 session_util::DeleteLastSession(browserState); 405 session_util::DeleteLastSession(browserState);
404 } 406 }
405 407
406 // Cookies and server bound certificates should have the same lifetime. 408 // Cookies and server bound certificates should have the same lifetime.
407 DCHECK_EQ((mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) != 0, 409 DCHECK_EQ((mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) != 0,
408 (mask & IOSChromeBrowsingDataRemover::REMOVE_CHANNEL_IDS) != 0); 410 (mask & IOSChromeBrowsingDataRemover::REMOVE_CHANNEL_IDS) != 0);
409 if (mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) { 411 if (mask & IOSChromeBrowsingDataRemover::REMOVE_COOKIES) {
410 scoped_refptr<net::URLRequestContextGetter> contextGetter = 412 scoped_refptr<net::URLRequestContextGetter> contextGetter =
411 browserState->GetRequestContext(); 413 browserState->GetRequestContext();
412 base::Closure callback = base::BindBlock(^{ 414 base::Closure callback = base::BindBlockArc(^{
413 }); 415 });
414 web::WebThread::PostTask( 416 web::WebThread::PostTask(
415 web::WebThread::IO, FROM_HERE, base::BindBlock(^{ 417 web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{
416 net::URLRequestContext* requestContext = 418 net::URLRequestContext* requestContext =
417 contextGetter->GetURLRequestContext(); 419 contextGetter->GetURLRequestContext();
418 net::ChannelIDService* channelIdService = 420 net::ChannelIDService* channelIdService =
419 requestContext->channel_id_service(); 421 requestContext->channel_id_service();
420 DCHECK(channelIdService); 422 DCHECK(channelIdService);
421 DCHECK(channelIdService->GetChannelIDStore()); 423 DCHECK(channelIdService->GetChannelIDStore());
422 channelIdService->GetChannelIDStore()->DeleteAll(callback); 424 channelIdService->GetChannelIDStore()->DeleteAll(callback);
423 DCHECK(requestContext->cookie_store()); 425 DCHECK(requestContext->cookie_store());
424 requestContext->cookie_store()->DeleteAllCreatedBetweenAsync( 426 requestContext->cookie_store()->DeleteAllCreatedBetweenAsync(
425 base::Time(), base::Time(), base::Bind(&DoNothing)); 427 base::Time(), base::Time(), base::Bind(&DoNothing));
(...skipping 18 matching lines...) Expand all
444 446
445 - (BOOL)hasPendingRemovalOperations:(ios::ChromeBrowserState*)browserState { 447 - (BOOL)hasPendingRemovalOperations:(ios::ChromeBrowserState*)browserState {
446 return _pendingRemovalCount[browserState] != 0; 448 return _pendingRemovalCount[browserState] != 0;
447 } 449 }
448 450
449 - (void)browserStateDestroyed:(ios::ChromeBrowserState*)browserState { 451 - (void)browserStateDestroyed:(ios::ChromeBrowserState*)browserState {
450 _pendingRemovalCount.erase(browserState); 452 _pendingRemovalCount.erase(browserState);
451 } 453 }
452 454
453 @end 455 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/browsing_data/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698