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

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

Issue 2614173002: Use ARC_GET_INSTANCE_FOR_METHOD for getting intent_helper instance (Closed)
Patch Set: address comment Created 3 years, 11 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) 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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "extensions/browser/entry_info.h" 27 #include "extensions/browser/entry_info.h"
28 #include "storage/browser/fileapi/file_system_url.h" 28 #include "storage/browser/fileapi/file_system_url.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 namespace file_manager { 31 namespace file_manager {
32 namespace file_tasks { 32 namespace file_tasks {
33 33
34 namespace { 34 namespace {
35 35
36 constexpr int kArcIntentHelperVersionWithUrlListSupport = 4;
37 constexpr int kArcIntentHelperVersionWithFullActivityName = 5;
38
39 constexpr char kAppIdSeparator = '/'; 36 constexpr char kAppIdSeparator = '/';
40 37
41 // Returns the Mojo interface for ARC Intent Helper, with version |minVersion|
42 // or above. If the ARC bridge is not established, returns null.
43 arc::mojom::IntentHelperInstance* GetArcIntentHelper(
44 Profile* profile,
45 const std::string& method_name_for_logging,
46 uint32_t min_version) {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
48
49 // File manager in secondary profile cannot access ARC.
50 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile))
51 return nullptr;
52 return arc::ArcIntentHelperBridge::GetIntentHelperInstance(
53 method_name_for_logging, min_version);
54 }
55
56 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper. 38 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper.
57 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() { 39 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() {
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
59 41
60 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); 42 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get();
61 if (!arc_service_manager) 43 if (!arc_service_manager)
62 return nullptr; 44 return nullptr;
63 return arc_service_manager->icon_loader(); 45 return arc_service_manager->icon_loader();
64 } 46 }
65 47
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 164 }
183 165
184 } // namespace 166 } // namespace
185 167
186 void FindArcTasks(Profile* profile, 168 void FindArcTasks(Profile* profile,
187 const std::vector<extensions::EntryInfo>& entries, 169 const std::vector<extensions::EntryInfo>& entries,
188 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 170 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
189 const FindTasksCallback& callback) { 171 const FindTasksCallback& callback) {
190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 172 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
191 173
192 arc::mojom::IntentHelperInstance* arc_intent_helper = 174 arc::mojom::IntentHelperInstance* arc_intent_helper = nullptr;
193 GetArcIntentHelper(profile, "RequestUrlListHandlerList", 175 // File manager in secondary profile cannot access ARC.
194 kArcIntentHelperVersionWithUrlListSupport); 176 if (chromeos::ProfileHelper::IsPrimaryProfile(profile)) {
177 auto* arc_service_manager = arc::ArcServiceManager::Get();
178 if (arc_service_manager) {
179 arc_intent_helper = ARC_GET_INSTANCE_FOR_METHOD(
180 arc_service_manager->arc_bridge_service()->intent_helper(),
181 RequestUrlListHandlerList);
182 }
183 }
195 if (!arc_intent_helper) { 184 if (!arc_intent_helper) {
196 callback.Run(std::move(result_list)); 185 callback.Run(std::move(result_list));
197 return; 186 return;
198 } 187 }
199 188
200 std::vector<arc::mojom::UrlWithMimeTypePtr> urls; 189 std::vector<arc::mojom::UrlWithMimeTypePtr> urls;
201 for (const extensions::EntryInfo& entry : entries) { 190 for (const extensions::EntryInfo& entry : entries) {
202 if (entry.is_directory) { // ARC apps don't support directories. 191 if (entry.is_directory) { // ARC apps don't support directories.
203 callback.Run(std::move(result_list)); 192 callback.Run(std::move(result_list));
204 return; 193 return;
(...skipping 16 matching lines...) Expand all
221 base::Bind(&OnArcHandlerList, base::Passed(&result_list), callback)); 210 base::Bind(&OnArcHandlerList, base::Passed(&result_list), callback));
222 } 211 }
223 212
224 bool ExecuteArcTask(Profile* profile, 213 bool ExecuteArcTask(Profile* profile,
225 const TaskDescriptor& task, 214 const TaskDescriptor& task,
226 const std::vector<storage::FileSystemURL>& file_urls, 215 const std::vector<storage::FileSystemURL>& file_urls,
227 const std::vector<std::string>& mime_types) { 216 const std::vector<std::string>& mime_types) {
228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 217 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
229 DCHECK_EQ(file_urls.size(), mime_types.size()); 218 DCHECK_EQ(file_urls.size(), mime_types.size());
230 219
231 arc::mojom::IntentHelperInstance* const arc_intent_helper = 220 arc::mojom::IntentHelperInstance* arc_intent_helper = nullptr;
232 GetArcIntentHelper(profile, "HandleUrlList", 221 // File manager in secondary profile cannot access ARC.
233 kArcIntentHelperVersionWithFullActivityName); 222 if (chromeos::ProfileHelper::IsPrimaryProfile(profile)) {
223 auto* arc_service_manager = arc::ArcServiceManager::Get();
224 if (arc_service_manager) {
225 arc_intent_helper = ARC_GET_INSTANCE_FOR_METHOD(
226 arc_service_manager->arc_bridge_service()->intent_helper(),
227 HandleUrlList);
228 }
229 }
234 if (!arc_intent_helper) 230 if (!arc_intent_helper)
235 return false; 231 return false;
236 232
237 std::vector<arc::mojom::UrlWithMimeTypePtr> urls; 233 std::vector<arc::mojom::UrlWithMimeTypePtr> urls;
238 for (size_t i = 0; i < file_urls.size(); ++i) { 234 for (size_t i = 0; i < file_urls.size(); ++i) {
239 GURL url; 235 GURL url;
240 if (!util::ConvertPathToArcUrl(file_urls[i].path(), &url)) { 236 if (!util::ConvertPathToArcUrl(file_urls[i].path(), &url)) {
241 LOG(ERROR) << "File on unsuppored path"; 237 LOG(ERROR) << "File on unsuppored path";
242 return false; 238 return false;
243 } 239 }
244 240
245 arc::mojom::UrlWithMimeTypePtr url_with_type = 241 arc::mojom::UrlWithMimeTypePtr url_with_type =
246 arc::mojom::UrlWithMimeType::New(); 242 arc::mojom::UrlWithMimeType::New();
247 url_with_type->url = url.spec(); 243 url_with_type->url = url.spec();
248 url_with_type->mime_type = mime_types[i]; 244 url_with_type->mime_type = mime_types[i];
249 urls.push_back(std::move(url_with_type)); 245 urls.push_back(std::move(url_with_type));
250 } 246 }
251 247
252 arc_intent_helper->HandleUrlList( 248 arc_intent_helper->HandleUrlList(
253 std::move(urls), AppIdToActivityName(task.app_id), 249 std::move(urls), AppIdToActivityName(task.app_id),
254 FileTaskActionIdToArcActionType(task.action_id)); 250 FileTaskActionIdToArcActionType(task.action_id));
255 return true; 251 return true;
256 } 252 }
257 253
258 } // namespace file_tasks 254 } // namespace file_tasks
259 } // namespace file_manager 255 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698