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

Side by Side Diff: chrome/browser/chromeos/file_manager/arc_file_tasks.cc

Issue 2498223002: arc: enable use_new_wrapper_types for intent_helper.mojom (Closed)
Patch Set: rebase Created 4 years, 1 month 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chrome/browser/chromeos/file_manager/arc_file_tasks.h" 5 #include "chrome/browser/chromeos/file_manager/arc_file_tasks.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base64.h" 13 #include "base/base64.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
19 #include "chrome/browser/chromeos/file_manager/path_util.h" 19 #include "chrome/browser/chromeos/file_manager/path_util.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/common/extensions/api/file_manager_private.h" 21 #include "chrome/common/extensions/api/file_manager_private.h"
22 #include "components/arc/arc_bridge_service.h" 22 #include "components/arc/arc_bridge_service.h"
23 #include "components/arc/arc_service_manager.h" 23 #include "components/arc/arc_service_manager.h"
24 #include "components/arc/common/intent_helper.mojom.h" 24 #include "components/arc/common/intent_helper.mojom.h"
25 #include "components/arc/intent_helper/activity_icon_loader.h" 25 #include "components/arc/intent_helper/activity_icon_loader.h"
26 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" 26 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
27 #include "components/arc/intent_helper/intent_constants.h" 27 #include "components/arc/intent_helper/intent_constants.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "extensions/browser/entry_info.h" 29 #include "extensions/browser/entry_info.h"
30 #include "mojo/public/cpp/bindings/binding.h"
31 #include "storage/browser/fileapi/file_system_url.h" 30 #include "storage/browser/fileapi/file_system_url.h"
32 #include "url/gurl.h" 31 #include "url/gurl.h"
33 32
34 namespace file_manager { 33 namespace file_manager {
35 namespace file_tasks { 34 namespace file_tasks {
36 35
37 namespace { 36 namespace {
38 37
39 constexpr int kArcIntentHelperVersionWithUrlListSupport = 4; 38 constexpr int kArcIntentHelperVersionWithUrlListSupport = 4;
40 constexpr int kArcIntentHelperVersionWithFullActivityName = 5; 39 constexpr int kArcIntentHelperVersionWithFullActivityName = 5;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const std::string& activity_name) { 98 const std::string& activity_name) {
100 return package_name + kAppIdSeparator + activity_name; 99 return package_name + kAppIdSeparator + activity_name;
101 } 100 }
102 101
103 arc::mojom::ActivityNamePtr AppIdToActivityName(const std::string& id) { 102 arc::mojom::ActivityNamePtr AppIdToActivityName(const std::string& id) {
104 arc::mojom::ActivityNamePtr name = arc::mojom::ActivityName::New(); 103 arc::mojom::ActivityNamePtr name = arc::mojom::ActivityName::New();
105 104
106 const size_t separator = id.find(kAppIdSeparator); 105 const size_t separator = id.find(kAppIdSeparator);
107 if (separator == std::string::npos) { 106 if (separator == std::string::npos) {
108 name->package_name = id; 107 name->package_name = id;
109 name->activity_name = mojo::String(); 108 name->activity_name = std::string();
110 } else { 109 } else {
111 name->package_name = id.substr(0, separator); 110 name->package_name = id.substr(0, separator);
112 name->activity_name = id.substr(separator + 1); 111 name->activity_name = id.substr(separator + 1);
113 } 112 }
114 return name; 113 return name;
115 } 114 }
116 115
117 // Below is the sequence of thread-hopping for loading ARC file tasks. 116 // Below is the sequence of thread-hopping for loading ARC file tasks.
118 void OnArcHandlerList( 117 void OnArcHandlerList(
119 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 118 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
120 const FindTasksCallback& callback, 119 const FindTasksCallback& callback,
121 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers); 120 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers);
122 121
123 void OnArcIconLoaded( 122 void OnArcIconLoaded(
124 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 123 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
125 const FindTasksCallback& callback, 124 const FindTasksCallback& callback,
126 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, 125 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
127 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons); 126 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons);
128 127
129 typedef std::map<arc::ActivityIconLoader::ActivityName, GURL> IconUrlMap; 128 typedef std::map<arc::ActivityIconLoader::ActivityName, GURL> IconUrlMap;
130 129
131 std::unique_ptr<IconUrlMap> EncodeIconsToDataURLs( 130 std::unique_ptr<IconUrlMap> EncodeIconsToDataURLs(
132 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons); 131 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons);
133 132
134 void OnArcIconEncoded( 133 void OnArcIconEncoded(
135 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 134 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
136 const FindTasksCallback& callback, 135 const FindTasksCallback& callback,
137 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, 136 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
138 std::unique_ptr<IconUrlMap> icons); 137 std::unique_ptr<IconUrlMap> icons);
139 138
140 // Called after the handlers from ARC is obtained. Proceeds to OnArcIconLoaded. 139 // Called after the handlers from ARC is obtained. Proceeds to OnArcIconLoaded.
141 void OnArcHandlerList( 140 void OnArcHandlerList(
142 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 141 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
143 const FindTasksCallback& callback, 142 const FindTasksCallback& callback,
144 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers) { 143 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) {
145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
146 145
147 scoped_refptr<arc::ActivityIconLoader> icon_loader = 146 scoped_refptr<arc::ActivityIconLoader> icon_loader =
148 GetArcActivityIconLoader(); 147 GetArcActivityIconLoader();
149 if (!icon_loader) { 148 if (!icon_loader) {
150 callback.Run(std::move(result_list)); 149 callback.Run(std::move(result_list));
151 return; 150 return;
152 } 151 }
153 152
154 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers_filtered = 153 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers_filtered =
155 arc::ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); 154 arc::ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
156 std::vector<arc::ActivityIconLoader::ActivityName> activity_names; 155 std::vector<arc::ActivityIconLoader::ActivityName> activity_names;
157 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers_filtered) 156 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers_filtered)
158 activity_names.emplace_back(handler->package_name, handler->activity_name); 157 activity_names.emplace_back(handler->package_name, handler->activity_name);
159 158
160 icon_loader->GetActivityIcons( 159 icon_loader->GetActivityIcons(
161 activity_names, base::Bind(&OnArcIconLoaded, base::Passed(&result_list), 160 activity_names, base::Bind(&OnArcIconLoaded, base::Passed(&result_list),
162 callback, base::Passed(&handlers_filtered))); 161 callback, base::Passed(&handlers_filtered)));
163 } 162 }
164 163
165 // Called after icon data for ARC apps are loaded. Proceeds to OnArcIconEncoded. 164 // Called after icon data for ARC apps are loaded. Proceeds to OnArcIconEncoded.
166 void OnArcIconLoaded( 165 void OnArcIconLoaded(
167 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 166 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
168 const FindTasksCallback& callback, 167 const FindTasksCallback& callback,
169 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, 168 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
170 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { 169 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) {
171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
172 171
173 base::PostTaskAndReplyWithResult( 172 base::PostTaskAndReplyWithResult(
174 content::BrowserThread::GetBlockingPool(), FROM_HERE, 173 content::BrowserThread::GetBlockingPool(), FROM_HERE,
175 base::Bind(&EncodeIconsToDataURLs, base::Passed(&icons)), 174 base::Bind(&EncodeIconsToDataURLs, base::Passed(&icons)),
176 base::Bind(&OnArcIconEncoded, base::Passed(&result_list), callback, 175 base::Bind(&OnArcIconEncoded, base::Passed(&result_list), callback,
177 base::Passed(&handlers))); 176 base::Passed(&handlers)));
178 } 177 }
179 178
(...skipping 15 matching lines...) Expand all
195 result->insert( 194 result->insert(
196 std::make_pair(entry.first, GURL(kPngDataUrlPrefix + encoded))); 195 std::make_pair(entry.first, GURL(kPngDataUrlPrefix + encoded)));
197 } 196 }
198 return result; 197 return result;
199 } 198 }
200 199
201 // Called after icon data is encoded on the blocking pool. 200 // Called after icon data is encoded on the blocking pool.
202 void OnArcIconEncoded( 201 void OnArcIconEncoded(
203 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 202 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
204 const FindTasksCallback& callback, 203 const FindTasksCallback& callback,
205 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, 204 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
206 std::unique_ptr<IconUrlMap> icons) { 205 std::unique_ptr<IconUrlMap> icons) {
207 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
208 207
209 using extensions::api::file_manager_private::Verb; 208 using extensions::api::file_manager_private::Verb;
210 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) { 209 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) {
210 std::string action(arc::kIntentActionView);
211 if (handler->action.has_value())
212 action = *handler->action;
211 std::string name(handler->name); 213 std::string name(handler->name);
212 Verb handler_verb = Verb::VERB_NONE; 214 Verb handler_verb = Verb::VERB_NONE;
213 if (handler->action == arc::kIntentActionSend || 215 if (action == arc::kIntentActionSend ||
214 handler->action == arc::kIntentActionSendMultiple) { 216 action == arc::kIntentActionSendMultiple) {
215 handler_verb = Verb::VERB_SHARE_WITH; 217 handler_verb = Verb::VERB_SHARE_WITH;
216 } 218 }
217 const GURL& icon_url = (*icons)[arc::ActivityIconLoader::ActivityName( 219 const GURL& icon_url = (*icons)[arc::ActivityIconLoader::ActivityName(
218 handler->package_name, handler->activity_name)]; 220 handler->package_name, handler->activity_name)];
219 result_list->push_back(FullTaskDescriptor( 221 result_list->push_back(FullTaskDescriptor(
220 TaskDescriptor( 222 TaskDescriptor(
221 ActivityNameToAppId(handler->package_name, handler->activity_name), 223 ActivityNameToAppId(handler->package_name, handler->activity_name),
222 TASK_TYPE_ARC_APP, ArcActionToFileTaskActionId(handler->action)), 224 TASK_TYPE_ARC_APP, ArcActionToFileTaskActionId(action)),
223 name, handler_verb, icon_url, false /* is_default */, 225 name, handler_verb, icon_url, false /* is_default */,
224 handler->action != arc::kIntentActionView /* is_generic */)); 226 action != arc::kIntentActionView /* is_generic */));
225 } 227 }
226 callback.Run(std::move(result_list)); 228 callback.Run(std::move(result_list));
227 } 229 }
228 230
229 } // namespace 231 } // namespace
230 232
231 void FindArcTasks(Profile* profile, 233 void FindArcTasks(Profile* profile,
232 const std::vector<extensions::EntryInfo>& entries, 234 const std::vector<extensions::EntryInfo>& entries,
233 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 235 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
234 const FindTasksCallback& callback) { 236 const FindTasksCallback& callback) {
235 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 237 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
236 238
237 arc::mojom::IntentHelperInstance* arc_intent_helper = 239 arc::mojom::IntentHelperInstance* arc_intent_helper =
238 GetArcIntentHelper(profile, "RequestUrlListHandlerList", 240 GetArcIntentHelper(profile, "RequestUrlListHandlerList",
239 kArcIntentHelperVersionWithUrlListSupport); 241 kArcIntentHelperVersionWithUrlListSupport);
240 if (!arc_intent_helper) { 242 if (!arc_intent_helper) {
241 callback.Run(std::move(result_list)); 243 callback.Run(std::move(result_list));
242 return; 244 return;
243 } 245 }
244 246
245 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls; 247 std::vector<arc::mojom::UrlWithMimeTypePtr> urls;
246 for (const extensions::EntryInfo& entry : entries) { 248 for (const extensions::EntryInfo& entry : entries) {
247 if (entry.is_directory) { // ARC apps don't support directories. 249 if (entry.is_directory) { // ARC apps don't support directories.
248 callback.Run(std::move(result_list)); 250 callback.Run(std::move(result_list));
249 return; 251 return;
250 } 252 }
251 253
252 GURL url; 254 GURL url;
253 if (!util::ConvertPathToArcUrl(entry.path, &url)) { 255 if (!util::ConvertPathToArcUrl(entry.path, &url)) {
254 callback.Run(std::move(result_list)); 256 callback.Run(std::move(result_list));
255 return; 257 return;
(...skipping 16 matching lines...) Expand all
272 const std::vector<std::string>& mime_types) { 274 const std::vector<std::string>& mime_types) {
273 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
274 DCHECK_EQ(file_urls.size(), mime_types.size()); 276 DCHECK_EQ(file_urls.size(), mime_types.size());
275 277
276 arc::mojom::IntentHelperInstance* const arc_intent_helper = 278 arc::mojom::IntentHelperInstance* const arc_intent_helper =
277 GetArcIntentHelper(profile, "HandleUrlList", 279 GetArcIntentHelper(profile, "HandleUrlList",
278 kArcIntentHelperVersionWithFullActivityName); 280 kArcIntentHelperVersionWithFullActivityName);
279 if (!arc_intent_helper) 281 if (!arc_intent_helper)
280 return false; 282 return false;
281 283
282 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls; 284 std::vector<arc::mojom::UrlWithMimeTypePtr> urls;
283 for (size_t i = 0; i < file_urls.size(); ++i) { 285 for (size_t i = 0; i < file_urls.size(); ++i) {
284 GURL url; 286 GURL url;
285 if (!util::ConvertPathToArcUrl(file_urls[i].path(), &url)) { 287 if (!util::ConvertPathToArcUrl(file_urls[i].path(), &url)) {
286 LOG(ERROR) << "File on unsuppored path"; 288 LOG(ERROR) << "File on unsuppored path";
287 return false; 289 return false;
288 } 290 }
289 291
290 arc::mojom::UrlWithMimeTypePtr url_with_type = 292 arc::mojom::UrlWithMimeTypePtr url_with_type =
291 arc::mojom::UrlWithMimeType::New(); 293 arc::mojom::UrlWithMimeType::New();
292 url_with_type->url = url.spec(); 294 url_with_type->url = url.spec();
293 url_with_type->mime_type = mime_types[i]; 295 url_with_type->mime_type = mime_types[i];
294 urls.push_back(std::move(url_with_type)); 296 urls.push_back(std::move(url_with_type));
295 } 297 }
296 298
297 arc_intent_helper->HandleUrlList( 299 arc_intent_helper->HandleUrlList(
298 std::move(urls), AppIdToActivityName(task.app_id), 300 std::move(urls), AppIdToActivityName(task.app_id),
299 FileTaskActionIdToArcActionType(task.action_id)); 301 FileTaskActionIdToArcActionType(task.action_id));
300 return true; 302 return true;
301 } 303 }
302 304
303 } // namespace file_tasks 305 } // namespace file_tasks
304 } // namespace file_manager 306 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/intent_helper/arc_navigation_throttle_unittest.cc ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698