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

Side by Side Diff: ios/chrome/browser/ui/external_file_remover.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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ios/chrome/browser/ui/external_file_remover.h" 5 #import "ios/chrome/browser/ui/external_file_remover.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/bind_objc_block.h" 8 #import "base/mac/bind_objc_block.h"
9 #include "components/sessions/core/tab_restore_service.h" 9 #include "components/sessions/core/tab_restore_service.h"
10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" 11 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h"
12 #import "ios/chrome/browser/ui/browser_view_controller.h" 12 #import "ios/chrome/browser/ui/browser_view_controller.h"
13 #import "ios/chrome/browser/ui/external_file_controller.h" 13 #import "ios/chrome/browser/ui/external_file_controller.h"
14 #include "ios/web/public/web_thread.h" 14 #include "ios/web/public/web_thread.h"
15 15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
16 ExternalFileRemover::ExternalFileRemover(BrowserViewController* bvc) 20 ExternalFileRemover::ExternalFileRemover(BrowserViewController* bvc)
17 : tabRestoreService_(NULL), bvc_(bvc), weak_ptr_factory_(this) {} 21 : tabRestoreService_(NULL), bvc_(bvc), weak_ptr_factory_(this) {}
18 22
19 ExternalFileRemover::~ExternalFileRemover() { 23 ExternalFileRemover::~ExternalFileRemover() {
20 if (tabRestoreService_) 24 if (tabRestoreService_)
21 tabRestoreService_->RemoveObserver(this); 25 tabRestoreService_->RemoveObserver(this);
22 } 26 }
23 27
24 void ExternalFileRemover::TabRestoreServiceChanged( 28 void ExternalFileRemover::TabRestoreServiceChanged(
25 sessions::TabRestoreService* service) { 29 sessions::TabRestoreService* service) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 const base::Closure& callback) { 65 const base::Closure& callback) {
62 NSSet* referencedFiles = all_files ? nil : [bvc_ referencedExternalFiles]; 66 NSSet* referencedFiles = all_files ? nil : [bvc_ referencedExternalFiles];
63 const NSInteger kMinimumAgeInDays = 30; 67 const NSInteger kMinimumAgeInDays = 30;
64 NSInteger ageInDays = all_files ? 0 : kMinimumAgeInDays; 68 NSInteger ageInDays = all_files ? 0 : kMinimumAgeInDays;
65 69
66 base::Closure callback_wrapper = callback; 70 base::Closure callback_wrapper = callback;
67 if (callback_wrapper.is_null()) { 71 if (callback_wrapper.is_null()) {
68 callback_wrapper = base::Bind(&base::DoNothing); 72 callback_wrapper = base::Bind(&base::DoNothing);
69 } 73 }
70 web::WebThread::PostBlockingPoolTaskAndReply( 74 web::WebThread::PostBlockingPoolTaskAndReply(
71 FROM_HERE, base::BindBlock(^{ 75 FROM_HERE, base::BindBlockArc(^{
72 [ExternalFileController removeFilesExcluding:referencedFiles 76 [ExternalFileController removeFilesExcluding:referencedFiles
73 olderThan:ageInDays]; 77 olderThan:ageInDays];
74 }), 78 }),
75 callback_wrapper); 79 callback_wrapper);
76 } 80 }
77 81
78 void ExternalFileRemover::RemoveAfterDelay(const base::TimeDelta& delay, 82 void ExternalFileRemover::RemoveAfterDelay(const base::TimeDelta& delay,
79 const base::Closure& callback) { 83 const base::Closure& callback) {
80 bool remove_all_files = delay == base::TimeDelta::FromSeconds(0); 84 bool remove_all_files = delay == base::TimeDelta::FromSeconds(0);
81 // Creating a copy so it can be used from the block underneath. 85 // Creating a copy so it can be used from the block underneath.
82 base::Closure callback_copy = callback; 86 base::Closure callback_copy = callback;
83 // Since a method on |this| is called from a block, this dance is necessary to 87 // Since a method on |this| is called from a block, this dance is necessary to
84 // make sure a method on |this| is not called when the object has gone away. 88 // make sure a method on |this| is not called when the object has gone away.
85 base::WeakPtr<ExternalFileRemover> weak_this = weak_ptr_factory_.GetWeakPtr(); 89 base::WeakPtr<ExternalFileRemover> weak_this = weak_ptr_factory_.GetWeakPtr();
86 web::WebThread::PostDelayedTask( 90 web::WebThread::PostDelayedTask(
87 web::WebThread::UI, FROM_HERE, base::BindBlock(^{ 91 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
88 if (weak_this) { 92 if (weak_this) {
89 weak_this->Remove(remove_all_files, callback_copy); 93 weak_this->Remove(remove_all_files, callback_copy);
90 } else if (!callback_copy.is_null()) { 94 } else if (!callback_copy.is_null()) {
91 callback_copy.Run(); 95 callback_copy.Run();
92 } 96 }
93 }), 97 }),
94 delay); 98 delay);
95 } 99 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/external_file_remover.h ('k') | ios/chrome/browser/ui/fade_truncated_label.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698