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

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

Issue 1923953005: Files app: Prepare all information necessary for Arc task execution. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 #include "chrome/browser/chromeos/file_manager/file_tasks.h" 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "apps/launcher.h" 11 #include "apps/launcher.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/browser/chromeos/drive/file_system_util.h" 16 #include "chrome/browser/chromeos/drive/file_system_util.h"
17 #include "chrome/browser/chromeos/drive/file_task_executor.h" 17 #include "chrome/browser/chromeos/drive/file_task_executor.h"
18 #include "chrome/browser/chromeos/file_manager/app_id.h" 18 #include "chrome/browser/chromeos/file_manager/app_id.h"
19 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" 19 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
20 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 20 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
21 #include "chrome/browser/chromeos/file_manager/open_util.h" 21 #include "chrome/browser/chromeos/file_manager/open_util.h"
22 #include "chrome/browser/extensions/api/file_handlers/mime_util.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 23 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/extensions/extension_util.h" 24 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/extensions/application_launch.h" 26 #include "chrome/browser/ui/extensions/application_launch.h"
26 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 27 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
27 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle r.h" 28 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle r.h"
28 #include "chrome/common/extensions/api/file_manager_private.h" 29 #include "chrome/common/extensions/api/file_manager_private.h"
29 #include "chrome/common/extensions/extension_constants.h" 30 #include "chrome/common/extensions/extension_constants.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chromeos/chromeos_switches.h" 32 #include "chromeos/chromeos_switches.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 extension_misc::kQuickOfficeExtensionId, 134 extension_misc::kQuickOfficeExtensionId,
134 }; 135 };
135 136
136 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { 137 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) {
137 if (task.app_id == kBuiltInApps[i]) 138 if (task.app_id == kBuiltInApps[i])
138 return true; 139 return true;
139 } 140 }
140 return false; 141 return false;
141 } 142 }
142 143
144 void FindArcTasks(Profile* profile,
145 const std::vector<extensions::EntryInfo>& entries,
146 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
147 const FindTasksCallback& callback) {
148 // TODO(kinaba): implement.
149 callback.Run(std::move(result_list));
150 }
151
152 void ExecuteByArcAfterMimeTypesCollected(
153 Profile* profile,
154 const TaskDescriptor& task,
155 const std::vector<FileSystemURL>& file_urls,
156 const FileTaskFinishedCallback& done,
157 extensions::app_file_handler_util::MimeTypeCollector* mime_collector,
158 std::unique_ptr<std::vector<std::string>> mime_types) {
159 // TODO(kinaba): implement.
160 NOTIMPLEMENTED();
161 done.Run(extensions::api::file_manager_private::TASK_RESULT_FAILED);
162 }
163
164 void PostProcessFoundTasks(
165 Profile* profile,
166 const std::vector<extensions::EntryInfo>& entries,
167 const FindTasksCallback& callback,
168 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) {
169 // Google documents can only be handled by internal handlers.
170 if (ContainsGoogleDocument(entries))
171 KeepOnlyFileManagerInternalTasks(result_list.get());
172 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get());
173 callback.Run(std::move(result_list));
174 }
175
143 } // namespace 176 } // namespace
144 177
145 FullTaskDescriptor::FullTaskDescriptor( 178 FullTaskDescriptor::FullTaskDescriptor(
146 const TaskDescriptor& task_descriptor, 179 const TaskDescriptor& task_descriptor,
147 const std::string& task_title, 180 const std::string& task_title,
148 const GURL& icon_url, 181 const GURL& icon_url,
149 bool is_default, 182 bool is_default,
150 bool is_generic_file_handler) 183 bool is_generic_file_handler)
151 : task_descriptor_(task_descriptor), 184 : task_descriptor_(task_descriptor),
152 task_title_(task_title), 185 task_title_(task_title),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 task->action_id = result[2]; 301 task->action_id = result[2];
269 302
270 return true; 303 return true;
271 } 304 }
272 305
273 bool ExecuteFileTask(Profile* profile, 306 bool ExecuteFileTask(Profile* profile,
274 const GURL& source_url, 307 const GURL& source_url,
275 const TaskDescriptor& task, 308 const TaskDescriptor& task,
276 const std::vector<FileSystemURL>& file_urls, 309 const std::vector<FileSystemURL>& file_urls,
277 const FileTaskFinishedCallback& done) { 310 const FileTaskFinishedCallback& done) {
311 // ARC apps needs mime types for launching. Retrieve them first.
278 if (task.task_type == TASK_TYPE_ARC_APP) { 312 if (task.task_type == TASK_TYPE_ARC_APP) {
279 NOTIMPLEMENTED(); 313 extensions::app_file_handler_util::MimeTypeCollector* mime_collector =
280 return false; 314 new extensions::app_file_handler_util::MimeTypeCollector(profile);
315 mime_collector->CollectForURLs(
316 file_urls,
317 base::Bind(&ExecuteByArcAfterMimeTypesCollected, profile, task,
318 file_urls, done, base::Owned(mime_collector)));
319 return true;
281 } 320 }
282 321
283 // drive::FileTaskExecutor is responsible to handle drive tasks. 322 // drive::FileTaskExecutor is responsible to handle drive tasks.
284 if (task.task_type == TASK_TYPE_DRIVE_APP) { 323 if (task.task_type == TASK_TYPE_DRIVE_APP) {
285 DCHECK_EQ(kDriveAppActionID, task.action_id); 324 DCHECK_EQ(kDriveAppActionID, task.action_id);
286 drive::FileTaskExecutor* executor = 325 drive::FileTaskExecutor* executor =
287 new drive::FileTaskExecutor(profile, task.app_id); 326 new drive::FileTaskExecutor(profile, task.app_id);
288 executor->Execute(file_urls, done); 327 executor->Execute(file_urls, done);
289 return true; 328 return true;
290 } 329 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 false /* is_generic_file_handler */)); 557 false /* is_generic_file_handler */));
519 } 558 }
520 } 559 }
521 560
522 void FindAllTypesOfTasks(Profile* profile, 561 void FindAllTypesOfTasks(Profile* profile,
523 const drive::DriveAppRegistry* drive_app_registry, 562 const drive::DriveAppRegistry* drive_app_registry,
524 const std::vector<extensions::EntryInfo>& entries, 563 const std::vector<extensions::EntryInfo>& entries,
525 const std::vector<GURL>& file_urls, 564 const std::vector<GURL>& file_urls,
526 const FindTasksCallback& callback) { 565 const FindTasksCallback& callback) {
527 DCHECK(profile); 566 DCHECK(profile);
528 std::vector<FullTaskDescriptor> result_list; 567 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list(
568 new std::vector<FullTaskDescriptor>);
529 569
530 // Find Drive app tasks, if the drive app registry is present. 570 // Find Drive app tasks, if the drive app registry is present.
531 if (drive_app_registry) 571 if (drive_app_registry)
532 FindDriveAppTasks(*drive_app_registry, entries, &result_list); 572 FindDriveAppTasks(*drive_app_registry, entries, result_list.get());
533 573
534 // Find and append file handler tasks. We know there aren't duplicates 574 // Find and append file handler tasks. We know there aren't duplicates
535 // because Drive apps and platform apps are entirely different kinds of 575 // because Drive apps and platform apps are entirely different kinds of
536 // tasks. 576 // tasks.
537 FindFileHandlerTasks(profile, entries, &result_list); 577 FindFileHandlerTasks(profile, entries, result_list.get());
538 578
539 // Find and append file browser handler tasks. We know there aren't 579 // Find and append file browser handler tasks. We know there aren't
540 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't 580 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't
541 // be used in the same manifest.json. 581 // be used in the same manifest.json.
542 FindFileBrowserHandlerTasks(profile, file_urls, &result_list); 582 FindFileBrowserHandlerTasks(profile, file_urls, result_list.get());
543 583
544 // Google documents can only be handled by internal handlers. 584 // Find and append ARC handler tasks.
545 if (ContainsGoogleDocument(entries)) 585 FindArcTasks(profile, entries, std::move(result_list),
546 KeepOnlyFileManagerInternalTasks(&result_list); 586 base::Bind(&PostProcessFoundTasks, profile, entries, callback));
547
548 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, &result_list);
549
550 callback.Run(result_list);
551 } 587 }
552 588
553 void ChooseAndSetDefaultTask(const PrefService& pref_service, 589 void ChooseAndSetDefaultTask(const PrefService& pref_service,
554 const std::vector<extensions::EntryInfo>& entries, 590 const std::vector<extensions::EntryInfo>& entries,
555 std::vector<FullTaskDescriptor>* tasks) { 591 std::vector<FullTaskDescriptor>* tasks) {
556 // Collect the task IDs of default tasks from the preferences into a set. 592 // Collect the task IDs of default tasks from the preferences into a set.
557 std::set<std::string> default_task_ids; 593 std::set<std::string> default_task_ids;
558 for (std::vector<extensions::EntryInfo>::const_iterator it = entries.begin(); 594 for (std::vector<extensions::EntryInfo>::const_iterator it = entries.begin();
559 it != entries.end(); ++it) { 595 it != entries.end(); ++it) {
560 const base::FilePath& file_path = it->path; 596 const base::FilePath& file_path = it->path;
(...skipping 22 matching lines...) Expand all
583 DCHECK(!task->is_default()); 619 DCHECK(!task->is_default());
584 if (IsFallbackFileHandler(task->task_descriptor())) { 620 if (IsFallbackFileHandler(task->task_descriptor())) {
585 task->set_is_default(true); 621 task->set_is_default(true);
586 return; 622 return;
587 } 623 }
588 } 624 }
589 } 625 }
590 626
591 } // namespace file_tasks 627 } // namespace file_tasks
592 } // namespace file_manager 628 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_tasks.h ('k') | chrome/browser/chromeos/file_manager/file_tasks_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698