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

Side by Side Diff: ios/chrome/common/app_group/app_group_metrics_mainapp.mm

Issue 2622903003: [ObjC ARC] Converts ios/chrome/common/app_group:main_app to ARC. (Closed)
Patch Set: Remove scoped_block Created 3 years, 11 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/common/app_group/app_group_metrics_mainapp.h ('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 #include "ios/chrome/common/app_group/app_group_metrics_mainapp.h" 5 #include "ios/chrome/common/app_group/app_group_metrics_mainapp.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "ios/chrome/common/app_group/app_group_constants.h" 10 #include "ios/chrome/common/app_group/app_group_constants.h"
12 #include "ios/chrome/common/app_group/app_group_metrics.h" 11 #include "ios/chrome/common/app_group/app_group_metrics.h"
13 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
14 namespace app_group { 17 namespace app_group {
15 18
16 namespace main_app { 19 namespace main_app {
17 20
18 void ProcessPendingLogs( 21 void ProcessPendingLogs(ProceduralBlockWithData callback) {
19 const base::mac::ScopedBlock<ProceduralBlockWithData>& callback) {
20 NSFileManager* file_manager = [NSFileManager defaultManager]; 22 NSFileManager* file_manager = [NSFileManager defaultManager];
21 NSURL* store_url = [file_manager 23 NSURL* store_url = [file_manager
22 containerURLForSecurityApplicationGroupIdentifier:ApplicationGroup()]; 24 containerURLForSecurityApplicationGroupIdentifier:ApplicationGroup()];
23 NSURL* log_dir_url = 25 NSURL* log_dir_url =
24 [store_url URLByAppendingPathComponent:app_group::kPendingLogFileDirectory 26 [store_url URLByAppendingPathComponent:app_group::kPendingLogFileDirectory
25 isDirectory:YES]; 27 isDirectory:YES];
26 28
27 NSArray* pending_logs = 29 NSArray* pending_logs =
28 [file_manager contentsOfDirectoryAtPath:[log_dir_url path] error:nil]; 30 [file_manager contentsOfDirectoryAtPath:[log_dir_url path] error:nil];
29 if (!pending_logs) 31 if (!pending_logs)
30 return; 32 return;
31 for (NSString* pending_log : pending_logs) { 33 for (NSString* pending_log : pending_logs) {
32 if ([pending_log hasSuffix:app_group::kPendingLogFileSuffix]) { 34 if ([pending_log hasSuffix:app_group::kPendingLogFileSuffix]) {
33 NSURL* file_url = 35 NSURL* file_url =
34 [log_dir_url URLByAppendingPathComponent:pending_log isDirectory:NO]; 36 [log_dir_url URLByAppendingPathComponent:pending_log isDirectory:NO];
35 if (callback) { 37 if (callback) {
36 NSData* log_content = [file_manager contentsAtPath:[file_url path]]; 38 NSData* log_content = [file_manager contentsAtPath:[file_url path]];
37 callback.get()(log_content); 39 callback(log_content);
38 } 40 }
39 [file_manager removeItemAtURL:file_url error:nil]; 41 [file_manager removeItemAtURL:file_url error:nil];
40 } 42 }
41 } 43 }
42 } 44 }
43 45
44 void EnableMetrics(NSString* client_id, 46 void EnableMetrics(NSString* client_id,
45 NSString* brand_code, 47 NSString* brand_code,
46 int64_t install_date, 48 int64_t install_date,
47 int64_t enable_metrics_date) { 49 int64_t enable_metrics_date) {
48 base::scoped_nsobject<NSUserDefaults> shared_defaults( 50 NSUserDefaults* shared_defaults =
49 [[NSUserDefaults alloc] initWithSuiteName:ApplicationGroup()]); 51 [[NSUserDefaults alloc] initWithSuiteName:ApplicationGroup()];
50 [shared_defaults setObject:client_id forKey:@(kChromeAppClientID)]; 52 [shared_defaults setObject:client_id forKey:@(kChromeAppClientID)];
51 53
52 [shared_defaults 54 [shared_defaults
53 setObject:[NSString stringWithFormat:@"%lld", enable_metrics_date] 55 setObject:[NSString stringWithFormat:@"%lld", enable_metrics_date]
54 forKey:@(kUserMetricsEnabledDate)]; 56 forKey:@(kUserMetricsEnabledDate)];
55 57
56 [shared_defaults setObject:[NSString stringWithFormat:@"%lld", install_date] 58 [shared_defaults setObject:[NSString stringWithFormat:@"%lld", install_date]
57 forKey:@(kInstallDate)]; 59 forKey:@(kInstallDate)];
58 60
59 [shared_defaults setObject:brand_code forKey:@(kBrandCode)]; 61 [shared_defaults setObject:brand_code forKey:@(kBrandCode)];
60 } 62 }
61 63
62 void DisableMetrics() { 64 void DisableMetrics() {
63 base::scoped_nsobject<NSUserDefaults> shared_defaults( 65 NSUserDefaults* shared_defaults =
64 [[NSUserDefaults alloc] initWithSuiteName:ApplicationGroup()]); 66 [[NSUserDefaults alloc] initWithSuiteName:ApplicationGroup()];
65 [shared_defaults removeObjectForKey:@(kChromeAppClientID)]; 67 [shared_defaults removeObjectForKey:@(kChromeAppClientID)];
66 } 68 }
67 69
68 } // namespace main_app 70 } // namespace main_app
69 71
70 } // namespace app_group 72 } // namespace app_group
OLDNEW
« no previous file with comments | « ios/chrome/common/app_group/app_group_metrics_mainapp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698