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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (Closed)
Patch Set: review Created 4 years, 3 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 <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/base64.h" 13 #include "base/base64.h"
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
18 #include "chrome/browser/chromeos/file_manager/path_util.h" 19 #include "chrome/browser/chromeos/file_manager/path_util.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
(...skipping 24 matching lines...) Expand all
44 FILE_PATH_LITERAL("/sdcard/Download"); 45 FILE_PATH_LITERAL("/sdcard/Download");
45 constexpr base::FilePath::CharType kRemovableMediaPath[] = 46 constexpr base::FilePath::CharType kRemovableMediaPath[] =
46 FILE_PATH_LITERAL("/media/removable"); 47 FILE_PATH_LITERAL("/media/removable");
47 constexpr char kArcRemovableMediaProviderUrl[] = 48 constexpr char kArcRemovableMediaProviderUrl[] =
48 "content://org.chromium.arc.removablemediaprovider/"; 49 "content://org.chromium.arc.removablemediaprovider/";
49 constexpr char kAppIdSeparator = '/'; 50 constexpr char kAppIdSeparator = '/';
50 constexpr char kPngDataUrlPrefix[] = "data:image/png;base64,"; 51 constexpr char kPngDataUrlPrefix[] = "data:image/png;base64,";
51 52
52 // Returns the Mojo interface for ARC Intent Helper, with version |minVersion| 53 // Returns the Mojo interface for ARC Intent Helper, with version |minVersion|
53 // or above. If the ARC bridge is not established, returns null. 54 // or above. If the ARC bridge is not established, returns null.
54 arc::mojom::IntentHelperInstance* GetArcIntentHelper(Profile* profile, 55 arc::mojom::IntentHelperInstance* GetArcIntentHelper(
55 uint32_t min_version) { 56 Profile* profile,
57 const std::string& method_name_for_logging,
58 uint32_t min_version) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 60
58 // File manager in secondary profile cannot access ARC. 61 // File manager in secondary profile cannot access ARC.
59 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile)) 62 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile))
60 return nullptr; 63 return nullptr;
61 return arc::ArcIntentHelperBridge::GetIntentHelperInstance(min_version); 64 return arc::ArcIntentHelperBridge::GetIntentHelperInstance(
65 method_name_for_logging, min_version);
62 } 66 }
63 67
64 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper. 68 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper.
65 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() { 69 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() {
66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
67 71
68 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); 72 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get();
69 if (!arc_service_manager) 73 if (!arc_service_manager)
70 return nullptr; 74 return nullptr;
71 return arc_service_manager->icon_loader(); 75 return arc_service_manager->icon_loader();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 271
268 } // namespace 272 } // namespace
269 273
270 void FindArcTasks(Profile* profile, 274 void FindArcTasks(Profile* profile,
271 const std::vector<extensions::EntryInfo>& entries, 275 const std::vector<extensions::EntryInfo>& entries,
272 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 276 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
273 const FindTasksCallback& callback) { 277 const FindTasksCallback& callback) {
274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 278 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
275 279
276 arc::mojom::IntentHelperInstance* arc_intent_helper = 280 arc::mojom::IntentHelperInstance* arc_intent_helper =
277 GetArcIntentHelper(profile, kArcIntentHelperVersionWithUrlListSupport); 281 GetArcIntentHelper(profile, "RequestUrlListHandlerList",
282 kArcIntentHelperVersionWithUrlListSupport);
278 if (!arc_intent_helper) { 283 if (!arc_intent_helper) {
279 callback.Run(std::move(result_list)); 284 callback.Run(std::move(result_list));
280 return; 285 return;
281 } 286 }
282 287
283 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls; 288 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls;
284 for (const extensions::EntryInfo& entry : entries) { 289 for (const extensions::EntryInfo& entry : entries) {
285 if (entry.is_directory) { // ARC apps don't support directories. 290 if (entry.is_directory) { // ARC apps don't support directories.
286 callback.Run(std::move(result_list)); 291 callback.Run(std::move(result_list));
287 return; 292 return;
(...skipping 17 matching lines...) Expand all
305 } 310 }
306 311
307 bool ExecuteArcTask(Profile* profile, 312 bool ExecuteArcTask(Profile* profile,
308 const TaskDescriptor& task, 313 const TaskDescriptor& task,
309 const std::vector<storage::FileSystemURL>& file_urls, 314 const std::vector<storage::FileSystemURL>& file_urls,
310 const std::vector<std::string>& mime_types) { 315 const std::vector<std::string>& mime_types) {
311 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 316 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
312 DCHECK_EQ(file_urls.size(), mime_types.size()); 317 DCHECK_EQ(file_urls.size(), mime_types.size());
313 318
314 arc::mojom::IntentHelperInstance* const arc_intent_helper = 319 arc::mojom::IntentHelperInstance* const arc_intent_helper =
315 GetArcIntentHelper(profile, kArcIntentHelperVersionWithUrlListSupport); 320 GetArcIntentHelper(profile, "HandleUrlListDeprecated",
321 kArcIntentHelperVersionWithUrlListSupport);
316 if (!arc_intent_helper) 322 if (!arc_intent_helper)
317 return false; 323 return false;
318 324
319 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls; 325 mojo::Array<arc::mojom::UrlWithMimeTypePtr> urls;
320 for (size_t i = 0; i < file_urls.size(); ++i) { 326 for (size_t i = 0; i < file_urls.size(); ++i) {
321 GURL url; 327 GURL url;
322 if (!ConvertToArcUrl(file_urls[i].path(), &url)) { 328 if (!ConvertToArcUrl(file_urls[i].path(), &url)) {
323 LOG(ERROR) << "File on unsuppored path"; 329 LOG(ERROR) << "File on unsuppored path";
324 return false; 330 return false;
325 } 331 }
326 332
327 arc::mojom::UrlWithMimeTypePtr url_with_type = 333 arc::mojom::UrlWithMimeTypePtr url_with_type =
328 arc::mojom::UrlWithMimeType::New(); 334 arc::mojom::UrlWithMimeType::New();
329 url_with_type->url = url.spec(); 335 url_with_type->url = url.spec();
330 url_with_type->mime_type = mime_types[i]; 336 url_with_type->mime_type = mime_types[i];
331 urls.push_back(std::move(url_with_type)); 337 urls.push_back(std::move(url_with_type));
332 } 338 }
333 339
334 if (GetArcIntentHelper(profile, 340 if (GetArcIntentHelper(profile, "HandleUrlList",
335 kArcIntentHelperVersionWithFullActivityName)) { 341 kArcIntentHelperVersionWithFullActivityName)) {
336 arc_intent_helper->HandleUrlList(std::move(urls), 342 arc_intent_helper->HandleUrlList(std::move(urls),
337 AppIdToActivityName(task.app_id), 343 AppIdToActivityName(task.app_id),
338 StringToArcAction(task.action_id)); 344 StringToArcAction(task.action_id));
339 } else { 345 } else {
340 arc_intent_helper->HandleUrlListDeprecated( 346 arc_intent_helper->HandleUrlListDeprecated(
341 std::move(urls), AppIdToActivityName(task.app_id)->package_name, 347 std::move(urls), AppIdToActivityName(task.app_id)->package_name,
342 StringToArcAction(task.action_id)); 348 StringToArcAction(task.action_id));
343 } 349 }
344 return true; 350 return true;
345 } 351 }
346 352
347 } // namespace file_tasks 353 } // namespace file_tasks
348 } // namespace file_manager 354 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698