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/open_util.h" | 5 #include "chrome/browser/chromeos/file_manager/open_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 file_urls.push_back(url); | 96 file_urls.push_back(url); |
97 | 97 |
98 std::vector<file_tasks::FullTaskDescriptor> tasks; | 98 std::vector<file_tasks::FullTaskDescriptor> tasks; |
99 file_tasks::FindAllTypesOfTasks( | 99 file_tasks::FindAllTypesOfTasks( |
100 profile, | 100 profile, |
101 drive::util::GetDriveAppRegistryByProfile(profile), | 101 drive::util::GetDriveAppRegistryByProfile(profile), |
102 path_mime_set, | 102 path_mime_set, |
103 file_urls, | 103 file_urls, |
104 &tasks); | 104 &tasks); |
105 | 105 |
106 if (tasks.empty()) { | 106 // Select a default handler. If a default handler is not available, select |
107 callback.Run(false); | 107 // a non-generic file handler. |
108 return; | 108 const file_tasks::FullTaskDescriptor* chosen_task = nullptr; |
109 } | |
110 | |
111 const file_tasks::FullTaskDescriptor* chosen_task = &tasks[0]; | |
112 for (size_t i = 0; i < tasks.size(); ++i) { | 109 for (size_t i = 0; i < tasks.size(); ++i) { |
mtomasz
2015/02/09 04:28:00
nit: Can we use auto and for range loop?
yawano
2015/02/09 04:44:26
Done.
| |
113 if (tasks[i].is_default()) { | 110 if (!tasks[i].is_generic_file_handler()) { |
114 chosen_task = &tasks[i]; | 111 chosen_task = &tasks[i]; |
115 break; | 112 if (tasks[i].is_default()) |
113 break; | |
116 } | 114 } |
117 } | 115 } |
118 | 116 |
119 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url); | 117 if (chosen_task != nullptr) { |
120 callback.Run(true); | 118 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url); |
119 callback.Run(true); | |
120 } else { | |
121 callback.Run(false); | |
122 } | |
121 } | 123 } |
122 | 124 |
123 // Opens the file specified by |url| by finding and executing a file task for | 125 // Opens the file specified by |url| by finding and executing a file task for |
124 // the file. In case of success, calls |callback| with true. Otherwise the | 126 // the file. In case of success, calls |callback| with true. Otherwise the |
125 // returned value is false. | 127 // returned value is false. |
126 void OpenFile(Profile* profile, | 128 void OpenFile(Profile* profile, |
127 const base::FilePath& path, | 129 const base::FilePath& path, |
128 const GURL& url, | 130 const GURL& url, |
129 const base::Callback<void(bool)>& callback) { | 131 const base::Callback<void(bool)>& callback) { |
130 extensions::app_file_handler_util::GetMimeTypeForLocalPath( | 132 extensions::app_file_handler_util::GetMimeTypeForLocalPath( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 GURL url; | 206 GURL url; |
205 if (!ConvertPath(profile, file_path, &url)) | 207 if (!ConvertPath(profile, file_path, &url)) |
206 return; | 208 return; |
207 | 209 |
208 // This action changes the selection so we do not reuse existing tabs. | 210 // This action changes the selection so we do not reuse existing tabs. |
209 OpenFileManagerWithInternalActionId(profile, url, "select"); | 211 OpenFileManagerWithInternalActionId(profile, url, "select"); |
210 } | 212 } |
211 | 213 |
212 } // namespace util | 214 } // namespace util |
213 } // namespace file_manager | 215 } // namespace file_manager |
OLD | NEW |