OLD | NEW |
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 "apps/launcher.h" | 7 #include "apps/launcher.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/strings/string_split.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/drive/file_task_executor.h" | 14 #include "chrome/browser/chromeos/drive/file_task_executor.h" |
14 #include "chrome/browser/chromeos/file_manager/app_id.h" | 15 #include "chrome/browser/chromeos/file_manager/app_id.h" |
15 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" | 16 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" |
16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
17 #include "chrome/browser/chromeos/file_manager/open_util.h" | 18 #include "chrome/browser/chromeos/file_manager/open_util.h" |
18 #include "chrome/browser/drive/drive_api_util.h" | 19 #include "chrome/browser/drive/drive_api_util.h" |
19 #include "chrome/browser/drive/drive_app_registry.h" | 20 #include "chrome/browser/drive/drive_app_registry.h" |
20 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 215 |
215 std::string TaskDescriptorToId(const TaskDescriptor& task_descriptor) { | 216 std::string TaskDescriptorToId(const TaskDescriptor& task_descriptor) { |
216 return MakeTaskID(task_descriptor.app_id, | 217 return MakeTaskID(task_descriptor.app_id, |
217 task_descriptor.task_type, | 218 task_descriptor.task_type, |
218 task_descriptor.action_id); | 219 task_descriptor.action_id); |
219 } | 220 } |
220 | 221 |
221 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task) { | 222 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task) { |
222 DCHECK(task); | 223 DCHECK(task); |
223 | 224 |
224 std::vector<std::string> result; | 225 std::vector<std::string> result = base::SplitString( |
225 int count = Tokenize(task_id, std::string("|"), &result); | 226 task_id, "|", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
226 | 227 |
227 // Parse a legacy task ID that only contain two parts. Drive tasks are | 228 // Parse a legacy task ID that only contain two parts. Drive tasks are |
228 // identified by a prefix "drive-app:" on the extension ID. The legacy task | 229 // identified by a prefix "drive-app:" on the extension ID. The legacy task |
229 // IDs can be stored in preferences. | 230 // IDs can be stored in preferences. |
230 if (count == 2) { | 231 if (result.size() == 2) { |
231 if (base::StartsWithASCII(result[0], kDriveTaskExtensionPrefix, true)) { | 232 if (base::StartsWithASCII(result[0], kDriveTaskExtensionPrefix, true)) { |
232 task->task_type = TASK_TYPE_DRIVE_APP; | 233 task->task_type = TASK_TYPE_DRIVE_APP; |
233 task->app_id = result[0].substr(kDriveTaskExtensionPrefixLength); | 234 task->app_id = result[0].substr(kDriveTaskExtensionPrefixLength); |
234 } else { | 235 } else { |
235 task->task_type = TASK_TYPE_FILE_BROWSER_HANDLER; | 236 task->task_type = TASK_TYPE_FILE_BROWSER_HANDLER; |
236 task->app_id = result[0]; | 237 task->app_id = result[0]; |
237 } | 238 } |
238 | 239 |
239 task->action_id = result[1]; | 240 task->action_id = result[1]; |
240 | 241 |
241 return true; | 242 return true; |
242 } | 243 } |
243 | 244 |
244 if (count != 3) | 245 if (result.size() != 3) |
245 return false; | 246 return false; |
246 | 247 |
247 TaskType task_type = StringToTaskType(result[1]); | 248 TaskType task_type = StringToTaskType(result[1]); |
248 if (task_type == TASK_TYPE_UNKNOWN) | 249 if (task_type == TASK_TYPE_UNKNOWN) |
249 return false; | 250 return false; |
250 | 251 |
251 task->app_id = result[0]; | 252 task->app_id = result[0]; |
252 task->task_type = task_type; | 253 task->task_type = task_type; |
253 task->action_id = result[2]; | 254 task->action_id = result[2]; |
254 | 255 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 DCHECK(!task->is_default()); | 564 DCHECK(!task->is_default()); |
564 if (IsFallbackFileHandler(task->task_descriptor())) { | 565 if (IsFallbackFileHandler(task->task_descriptor())) { |
565 task->set_is_default(true); | 566 task->set_is_default(true); |
566 return; | 567 return; |
567 } | 568 } |
568 } | 569 } |
569 } | 570 } |
570 | 571 |
571 } // namespace file_tasks | 572 } // namespace file_tasks |
572 } // namespace file_manager | 573 } // namespace file_manager |
OLD | NEW |