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

Side by Side Diff: ios/chrome/app/spotlight/actions_spotlight_manager.mm

Issue 2704193002: [ObjC ARC] Converts ios/chrome/app/spotlight:spotlight to ARC. (Closed)
Patch Set: s/unsafe/weak Created 3 years, 10 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/app/spotlight/BUILD.gn ('k') | ios/chrome/app/spotlight/base_spotlight_manager.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/app/spotlight/actions_spotlight_manager.h" 5 #import "ios/chrome/app/spotlight/actions_spotlight_manager.h"
6 6
7 #import <CoreSpotlight/CoreSpotlight.h> 7 #import <CoreSpotlight/CoreSpotlight.h>
8 8
9 #include "base/ios/weak_nsobject.h"
10 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
11 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
13 #include "ios/chrome/browser/app_startup_parameters.h" 12 #include "ios/chrome/browser/app_startup_parameters.h"
14 #include "ios/chrome/browser/experimental_flags.h" 13 #include "ios/chrome/browser/experimental_flags.h"
15 #include "ios/chrome/common/app_group/app_group_constants.h" 14 #include "ios/chrome/common/app_group/app_group_constants.h"
16 #include "ios/chrome/grit/ios_strings.h" 15 #include "ios/chrome/grit/ios_strings.h"
17 #include "net/base/mac/url_conversions.h" 16 #include "net/base/mac/url_conversions.h"
18 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
19 #include "url/gurl.h" 18 #include "url/gurl.h"
20 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
21 namespace { 24 namespace {
22 25
23 NSString* SpotlightActionFromString(NSString* query) { 26 NSString* SpotlightActionFromString(NSString* query) {
24 NSString* domain = 27 NSString* domain =
25 [NSString stringWithFormat:@"%@.", spotlight::StringFromSpotlightDomain( 28 [NSString stringWithFormat:@"%@.", spotlight::StringFromSpotlightDomain(
26 spotlight::DOMAIN_ACTIONS)]; 29 spotlight::DOMAIN_ACTIONS)];
27 DCHECK([query hasPrefix:domain]); 30 DCHECK([query hasPrefix:domain]);
28 return 31 return
29 [query substringWithRange:NSMakeRange([domain length], 32 [query substringWithRange:NSMakeRange([domain length],
30 [query length] - [domain length])]; 33 [query length] - [domain length])];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title; 104 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title;
102 105
103 // Clears and re-inserts all Spotlight actions. 106 // Clears and re-inserts all Spotlight actions.
104 - (void)clearAndAddSpotlightActions; 107 - (void)clearAndAddSpotlightActions;
105 108
106 @end 109 @end
107 110
108 @implementation ActionsSpotlightManager 111 @implementation ActionsSpotlightManager
109 112
110 + (ActionsSpotlightManager*)actionsSpotlightManager { 113 + (ActionsSpotlightManager*)actionsSpotlightManager {
111 return [[[ActionsSpotlightManager alloc] 114 return [[ActionsSpotlightManager alloc]
112 initWithLargeIconService:nil 115 initWithLargeIconService:nil
113 domain:spotlight::DOMAIN_ACTIONS] autorelease]; 116 domain:spotlight::DOMAIN_ACTIONS];
114 } 117 }
115 118
116 #pragma mark public methods 119 #pragma mark public methods
117 120
118 - (void)indexActions { 121 - (void)indexActions {
119 base::WeakNSObject<ActionsSpotlightManager> weakSelf(self); 122 __weak ActionsSpotlightManager* weakSelf = self;
120 dispatch_after( 123 dispatch_after(
121 dispatch_time(DISPATCH_TIME_NOW, static_cast<int64_t>(1 * NSEC_PER_SEC)), 124 dispatch_time(DISPATCH_TIME_NOW, static_cast<int64_t>(1 * NSEC_PER_SEC)),
122 dispatch_get_main_queue(), ^{ 125 dispatch_get_main_queue(), ^{
123 base::scoped_nsobject<ActionsSpotlightManager> strongSelf( 126 ActionsSpotlightManager* strongSelf = weakSelf;
124 [weakSelf retain]);
125 [strongSelf clearAndAddSpotlightActions]; 127 [strongSelf clearAndAddSpotlightActions];
126 }); 128 });
127 } 129 }
128 130
129 #pragma mark private methods 131 #pragma mark private methods
130 132
131 - (void)clearAndAddSpotlightActions { 133 - (void)clearAndAddSpotlightActions {
132 [self clearAllSpotlightItems:^(NSError* error) { 134 [self clearAllSpotlightItems:^(NSError* error) {
133 if (!experimental_flags::IsSpotlightActionsEnabled()) { 135 if (!experimental_flags::IsSpotlightActionsEnabled()) {
134 return; 136 return;
135 } 137 }
136 base::WeakNSObject<ActionsSpotlightManager> weakSelf(self); 138 __weak ActionsSpotlightManager* weakSelf = self;
137 dispatch_after( 139 dispatch_after(
138 dispatch_time(DISPATCH_TIME_NOW, 140 dispatch_time(DISPATCH_TIME_NOW,
139 static_cast<int64_t>(1 * NSEC_PER_SEC)), 141 static_cast<int64_t>(1 * NSEC_PER_SEC)),
140 dispatch_get_main_queue(), ^{ 142 dispatch_get_main_queue(), ^{
141 base::scoped_nsobject<ActionsSpotlightManager> strongSelf( 143 ActionsSpotlightManager* strongSelf = weakSelf;
142 [weakSelf retain]);
143 144
144 if (!strongSelf) { 145 if (!strongSelf) {
145 return; 146 return;
146 } 147 }
147 148
148 NSString* voiceSearchTitle = l10n_util::GetNSString( 149 NSString* voiceSearchTitle = l10n_util::GetNSString(
149 IDS_IOS_APPLICATION_SHORTCUT_VOICE_SEARCH_TITLE); 150 IDS_IOS_APPLICATION_SHORTCUT_VOICE_SEARCH_TITLE);
150 NSString* voiceSearchAction = 151 NSString* voiceSearchAction =
151 base::SysUTF8ToNSString(spotlight::kSpotlightActionVoiceSearch); 152 base::SysUTF8ToNSString(spotlight::kSpotlightActionVoiceSearch);
152 153
(...skipping 21 matching lines...) Expand all
174 ]; 175 ];
175 176
176 [[CSSearchableIndex defaultSearchableIndex] 177 [[CSSearchableIndex defaultSearchableIndex]
177 indexSearchableItems:spotlightItems 178 indexSearchableItems:spotlightItems
178 completionHandler:nil]; 179 completionHandler:nil];
179 }); 180 });
180 }]; 181 }];
181 } 182 }
182 183
183 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title { 184 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title {
184 base::scoped_nsobject<CSSearchableItemAttributeSet> attributeSet( 185 CSSearchableItemAttributeSet* attributeSet =
185 [[CSSearchableItemAttributeSet alloc] 186 [[CSSearchableItemAttributeSet alloc]
186 initWithItemContentType:spotlight::StringFromSpotlightDomain( 187 initWithItemContentType:spotlight::StringFromSpotlightDomain(
187 spotlight::DOMAIN_ACTIONS)]); 188 spotlight::DOMAIN_ACTIONS)];
188 [attributeSet setTitle:title]; 189 [attributeSet setTitle:title];
189 [attributeSet setDisplayName:title]; 190 [attributeSet setDisplayName:title];
190 191
191 NSString* domainID = 192 NSString* domainID =
192 spotlight::StringFromSpotlightDomain(spotlight::DOMAIN_ACTIONS); 193 spotlight::StringFromSpotlightDomain(spotlight::DOMAIN_ACTIONS);
193 NSString* itemID = [NSString stringWithFormat:@"%@.%@", domainID, action]; 194 NSString* itemID = [NSString stringWithFormat:@"%@.%@", domainID, action];
194 195
195 return [self spotlightItemWithItemID:itemID attributeSet:attributeSet]; 196 return [self spotlightItemWithItemID:itemID attributeSet:attributeSet];
196 } 197 }
197 198
198 @end 199 @end
OLDNEW
« no previous file with comments | « ios/chrome/app/spotlight/BUILD.gn ('k') | ios/chrome/app/spotlight/base_spotlight_manager.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698