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

Side by Side Diff: ios/chrome/browser/share_extension/share_extension_item_receiver.mm

Issue 2522943003: [iOS/ARC] Fix a violation of ODR in base::BindBlock under ARC. (Closed)
Patch Set: Use EXPECT_NSEQ instead of EXPECT_EQ/EXPECT_TRUE. 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/share_extension/share_extension_item_receiver.h" 5 #import "ios/chrome/browser/share_extension/share_extension_item_receiver.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/ios/block_types.h" 9 #include "base/ios/block_types.h"
10 #include "base/mac/bind_objc_block.h" 10 #include "base/mac/bind_objc_block.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return; 103 return;
104 } 104 }
105 #else 105 #else
106 DCHECK([self presentedItemURL]); 106 DCHECK([self presentedItemURL]);
107 #endif 107 #endif
108 108
109 _readingListModel = readingListModel; 109 _readingListModel = readingListModel;
110 _bookmarkModel = bookmarkModel; 110 _bookmarkModel = bookmarkModel;
111 111
112 web::WebThread::PostTask(web::WebThread::FILE, FROM_HERE, 112 web::WebThread::PostTask(web::WebThread::FILE, FROM_HERE,
113 base::BindBlock(^() { 113 base::BindBlockArc(^() {
114 [self createReadingListFolder]; 114 [self createReadingListFolder];
115 })); 115 }));
116 [[NSNotificationCenter defaultCenter] 116 [[NSNotificationCenter defaultCenter]
117 addObserver:self 117 addObserver:self
118 selector:@selector(applicationDidBecomeActive) 118 selector:@selector(applicationDidBecomeActive)
119 name:UIApplicationDidBecomeActiveNotification 119 name:UIApplicationDidBecomeActiveNotification
120 object:nil]; 120 object:nil];
121 [[NSNotificationCenter defaultCenter] 121 [[NSNotificationCenter defaultCenter]
122 addObserver:self 122 addObserver:self
123 selector:@selector(applicationWillResignActive) 123 selector:@selector(applicationWillResignActive)
(...skipping 18 matching lines...) Expand all
142 DCHECK_CURRENTLY_ON(web::WebThread::FILE); 142 DCHECK_CURRENTLY_ON(web::WebThread::FILE);
143 if (![[NSFileManager defaultManager] 143 if (![[NSFileManager defaultManager]
144 fileExistsAtPath:[[self presentedItemURL] path]]) { 144 fileExistsAtPath:[[self presentedItemURL] path]]) {
145 [[NSFileManager defaultManager] 145 [[NSFileManager defaultManager]
146 createDirectoryAtPath:[[self presentedItemURL] path] 146 createDirectoryAtPath:[[self presentedItemURL] path]
147 withIntermediateDirectories:NO 147 withIntermediateDirectories:NO
148 attributes:nil 148 attributes:nil
149 error:nil]; 149 error:nil];
150 } 150 }
151 web::WebThread::PostTask( 151 web::WebThread::PostTask(
152 web::WebThread::UI, FROM_HERE, base::BindBlock(^() { 152 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^() {
153 if ([[UIApplication sharedApplication] applicationState] == 153 if ([[UIApplication sharedApplication] applicationState] ==
154 UIApplicationStateActive) { 154 UIApplicationStateActive) {
155 _folderCreated = YES; 155 _folderCreated = YES;
156 [self applicationDidBecomeActive]; 156 [self applicationDidBecomeActive];
157 } 157 }
158 })); 158 }));
159 } 159 }
160 160
161 - (BOOL)receivedData:(NSData*)data withCompletion:(ProceduralBlock)completion { 161 - (BOOL)receivedData:(NSData*)data withCompletion:(ProceduralBlock)completion {
162 id entryID = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 162 id entryID = [NSKeyedUnarchiver unarchiveObjectWithData:data];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 completion(); 198 completion();
199 } 199 }
200 return NO; 200 return NO;
201 } 201 }
202 202
203 UMA_HISTOGRAM_TIMES("IOS.ShareExtension.ReceivedEntryDelay", 203 UMA_HISTOGRAM_TIMES("IOS.ShareExtension.ReceivedEntryDelay",
204 base::TimeDelta::FromSecondsD( 204 base::TimeDelta::FromSecondsD(
205 [[NSDate date] timeIntervalSinceDate:entryDate])); 205 [[NSDate date] timeIntervalSinceDate:entryDate]));
206 206
207 // Entry is valid. Add it to the reading list model. 207 // Entry is valid. Add it to the reading list model.
208 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, base::BindBlock(^() { 208 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
209 base::BindBlockArc(^() {
209 if (!_readingListModel || !_bookmarkModel) { 210 if (!_readingListModel || !_bookmarkModel) {
210 // Models may have been deleted after the file 211 // Models may have been deleted after the file
211 // processing started. 212 // processing started.
212 return; 213 return;
213 } 214 }
214 app_group::ShareExtensionItemType type = 215 app_group::ShareExtensionItemType type =
215 static_cast<app_group::ShareExtensionItemType>( 216 static_cast<app_group::ShareExtensionItemType>(
216 [entryType integerValue]); 217 [entryType integerValue]);
217 if (type == app_group::READING_LIST_ITEM) { 218 if (type == app_group::READING_LIST_ITEM) {
218 LogHistogramReceivedItem(READINGLIST_ENTRY); 219 LogHistogramReceivedItem(READINGLIST_ENTRY);
219 _readingListModel->AddEntry(entryURL, 220 _readingListModel->AddEntry(entryURL,
220 entryTitle); 221 entryTitle);
221 } 222 }
222 if (type == app_group::BOOKMARK_ITEM) { 223 if (type == app_group::BOOKMARK_ITEM) {
223 LogHistogramReceivedItem(BOOKMARK_ENTRY); 224 LogHistogramReceivedItem(BOOKMARK_ENTRY);
224 _bookmarkModel->AddURL( 225 _bookmarkModel->AddURL(
225 _bookmarkModel->mobile_node(), 0, 226 _bookmarkModel->mobile_node(), 0,
226 base::ASCIIToUTF16(entryTitle), entryURL); 227 base::ASCIIToUTF16(entryTitle), entryURL);
227 } 228 }
228 if (completion) { 229 if (completion) {
229 web::WebThread::PostTask(web::WebThread::FILE, 230 web::WebThread::PostTask(web::WebThread::FILE,
230 FROM_HERE, 231 FROM_HERE,
231 base::BindBlock(^() { 232 base::BindBlockArc(^() {
232 completion(); 233 completion();
233 })); 234 }));
234 } 235 }
235 })); 236 }));
236 return YES; 237 return YES;
237 } 238 }
238 239
239 - (void)handleFileAtURL:(NSURL*)url withCompletion:(ProceduralBlock)completion { 240 - (void)handleFileAtURL:(NSURL*)url withCompletion:(ProceduralBlock)completion {
240 DCHECK_CURRENTLY_ON(web::WebThread::FILE); 241 DCHECK_CURRENTLY_ON(web::WebThread::FILE);
241 if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]]) { 242 if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]]) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 - (void)applicationDidBecomeActive { 286 - (void)applicationDidBecomeActive {
286 if (!_folderCreated || _isObservingFolder) { 287 if (!_folderCreated || _isObservingFolder) {
287 return; 288 return;
288 } 289 }
289 _isObservingFolder = YES; 290 _isObservingFolder = YES;
290 // Start observing for new files. 291 // Start observing for new files.
291 [NSFileCoordinator addFilePresenter:self]; 292 [NSFileCoordinator addFilePresenter:self];
292 293
293 // There may already be files. Process them. 294 // There may already be files. Process them.
294 web::WebThread::PostTask( 295 web::WebThread::PostTask(
295 web::WebThread::FILE, FROM_HERE, base::BindBlock(^() { 296 web::WebThread::FILE, FROM_HERE, base::BindBlockArc(^() {
296 NSArray<NSURL*>* files = [[NSFileManager defaultManager] 297 NSArray<NSURL*>* files = [[NSFileManager defaultManager]
297 contentsOfDirectoryAtURL:[self presentedItemURL] 298 contentsOfDirectoryAtURL:[self presentedItemURL]
298 includingPropertiesForKeys:nil 299 includingPropertiesForKeys:nil
299 options:NSDirectoryEnumerationSkipsHiddenFiles 300 options:NSDirectoryEnumerationSkipsHiddenFiles
300 error:nil]; 301 error:nil];
301 if ([files count] == 0) { 302 if ([files count] == 0) {
302 return; 303 return;
303 } 304 }
304 web::WebThread::PostTask( 305 web::WebThread::PostTask(
305 web::WebThread::UI, FROM_HERE, base::BindBlock(^() { 306 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^() {
306 UMA_HISTOGRAM_COUNTS_100( 307 UMA_HISTOGRAM_COUNTS_100(
307 "IOS.ShareExtension.ReceivedEntriesCount", [files count]); 308 "IOS.ShareExtension.ReceivedEntriesCount", [files count]);
308 for (NSURL* fileURL : files) { 309 for (NSURL* fileURL : files) {
309 __block std::unique_ptr< 310 __block std::unique_ptr<
310 ReadingListModel::ScopedReadingListBatchUpdate> 311 ReadingListModel::ScopedReadingListBatchUpdate>
311 batchToken(_readingListModel->BeginBatchUpdates()); 312 batchToken(_readingListModel->BeginBatchUpdates());
312 web::WebThread::PostTask( 313 web::WebThread::PostTask(
313 web::WebThread::FILE, FROM_HERE, base::BindBlock(^() { 314 web::WebThread::FILE, FROM_HERE, base::BindBlockArc(^() {
314 [self handleFileAtURL:fileURL 315 [self handleFileAtURL:fileURL
315 withCompletion:^{ 316 withCompletion:^{
316 web::WebThread::PostTask(web::WebThread::UI, 317 web::WebThread::PostTask(web::WebThread::UI,
317 FROM_HERE, 318 FROM_HERE,
318 base::BindBlock(^() { 319 base::BindBlockArc(^() {
319 batchToken.reset(); 320 batchToken.reset();
320 })); 321 }));
321 }]; 322 }];
322 })); 323 }));
323 } 324 }
324 })); 325 }));
325 })); 326 }));
326 } 327 }
327 328
328 - (void)applicationWillResignActive { 329 - (void)applicationWillResignActive {
329 if (!_isObservingFolder) { 330 if (!_isObservingFolder) {
330 return; 331 return;
331 } 332 }
332 _isObservingFolder = NO; 333 _isObservingFolder = NO;
333 [NSFileCoordinator removeFilePresenter:self]; 334 [NSFileCoordinator removeFilePresenter:self];
334 } 335 }
335 336
336 #pragma mark - 337 #pragma mark -
337 #pragma mark NSFilePresenter methods 338 #pragma mark NSFilePresenter methods
338 339
339 - (void)presentedSubitemDidChangeAtURL:(NSURL*)url { 340 - (void)presentedSubitemDidChangeAtURL:(NSURL*)url {
340 web::WebThread::PostTask(web::WebThread::FILE, FROM_HERE, 341 web::WebThread::PostTask(web::WebThread::FILE, FROM_HERE,
341 base::BindBlock(^() { 342 base::BindBlockArc(^() {
342 [self handleFileAtURL:url withCompletion:nil]; 343 [self handleFileAtURL:url withCompletion:nil];
343 })); 344 }));
344 } 345 }
345 346
346 - (NSOperationQueue*)presentedItemOperationQueue { 347 - (NSOperationQueue*)presentedItemOperationQueue {
347 return [NSOperationQueue mainQueue]; 348 return [NSOperationQueue mainQueue];
348 } 349 }
349 350
350 - (NSURL*)presentedItemURL { 351 - (NSURL*)presentedItemURL {
351 return app_group::ShareExtensionItemsFolder(); 352 return app_group::ShareExtensionItemsFolder();
352 } 353 }
353 354
354 @end 355 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698