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

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

Issue 2655233007: Get rid of RefCounted for ActivityIconLoader. (Closed)
Patch Set: address comments Created 3 years, 10 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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
17 #include "chrome/browser/chromeos/file_manager/path_util.h" 17 #include "chrome/browser/chromeos/file_manager/path_util.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/common/extensions/api/file_manager_private.h" 19 #include "chrome/common/extensions/api/file_manager_private.h"
20 #include "components/arc/arc_bridge_service.h" 20 #include "components/arc/arc_bridge_service.h"
21 #include "components/arc/arc_service_manager.h" 21 #include "components/arc/arc_service_manager.h"
22 #include "components/arc/common/intent_helper.mojom.h" 22 #include "components/arc/common/intent_helper.mojom.h"
23 #include "components/arc/intent_helper/activity_icon_loader.h"
24 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" 23 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
25 #include "components/arc/intent_helper/intent_constants.h" 24 #include "components/arc/intent_helper/intent_constants.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 #include "extensions/browser/entry_info.h" 26 #include "extensions/browser/entry_info.h"
28 #include "storage/browser/fileapi/file_system_url.h" 27 #include "storage/browser/fileapi/file_system_url.h"
29 #include "url/gurl.h" 28 #include "url/gurl.h"
30 29
31 namespace file_manager { 30 namespace file_manager {
32 namespace file_tasks { 31 namespace file_tasks {
33 32
34 namespace { 33 namespace {
35 34
36 constexpr char kAppIdSeparator = '/'; 35 constexpr char kAppIdSeparator = '/';
37 36
38 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper.
39 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41
42 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get();
43 if (!arc_service_manager)
44 return nullptr;
45 return arc_service_manager->icon_loader();
46 }
47
48 // Converts an Android intent action (see kIntentAction* in 37 // Converts an Android intent action (see kIntentAction* in
49 // components/arc/intent_helper/intent_constants.h) to a file task action ID 38 // components/arc/intent_helper/intent_constants.h) to a file task action ID
50 // (see chrome/browser/chromeos/file_manager/file_tasks.h). 39 // (see chrome/browser/chromeos/file_manager/file_tasks.h).
51 std::string ArcActionToFileTaskActionId(const std::string& action) { 40 std::string ArcActionToFileTaskActionId(const std::string& action) {
52 if (action == arc::kIntentActionView) 41 if (action == arc::kIntentActionView)
53 return "view"; 42 return "view";
54 else if (action == arc::kIntentActionSend) 43 else if (action == arc::kIntentActionSend)
55 return "send"; 44 return "send";
56 else if (action == arc::kIntentActionSendMultiple) 45 else if (action == arc::kIntentActionSendMultiple)
57 return "send_multiple"; 46 return "send_multiple";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // Below is the sequence of thread-hopping for loading ARC file tasks. 84 // Below is the sequence of thread-hopping for loading ARC file tasks.
96 void OnArcHandlerList( 85 void OnArcHandlerList(
97 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 86 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
98 const FindTasksCallback& callback, 87 const FindTasksCallback& callback,
99 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers); 88 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers);
100 89
101 void OnArcIconLoaded( 90 void OnArcIconLoaded(
102 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 91 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
103 const FindTasksCallback& callback, 92 const FindTasksCallback& callback,
104 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers, 93 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
105 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons); 94 std::unique_ptr<arc::ArcIntentHelperBridge::ActivityToIconsMap> icons);
106 95
107 // Called after the handlers from ARC is obtained. Proceeds to OnArcIconLoaded. 96 // Called after the handlers from ARC is obtained. Proceeds to OnArcIconLoaded.
108 void OnArcHandlerList( 97 void OnArcHandlerList(
109 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 98 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
110 const FindTasksCallback& callback, 99 const FindTasksCallback& callback,
111 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { 100 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) {
112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
113 102
114 scoped_refptr<arc::ActivityIconLoader> icon_loader = 103 auto* intent_helper_bridge =
115 GetArcActivityIconLoader(); 104 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>();
116 if (!icon_loader) { 105 if (!intent_helper_bridge) {
117 callback.Run(std::move(result_list)); 106 callback.Run(std::move(result_list));
118 return; 107 return;
119 } 108 }
120 109
121 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers_filtered = 110 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers_filtered =
122 arc::ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); 111 arc::ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
123 std::vector<arc::ActivityIconLoader::ActivityName> activity_names; 112 std::vector<arc::ArcIntentHelperBridge::ActivityName> activity_names;
124 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers_filtered) 113 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers_filtered)
125 activity_names.emplace_back(handler->package_name, handler->activity_name); 114 activity_names.emplace_back(handler->package_name, handler->activity_name);
126 115
127 icon_loader->GetActivityIcons( 116 intent_helper_bridge->GetActivityIcons(
128 activity_names, base::Bind(&OnArcIconLoaded, base::Passed(&result_list), 117 activity_names, base::Bind(&OnArcIconLoaded, base::Passed(&result_list),
129 callback, base::Passed(&handlers_filtered))); 118 callback, base::Passed(&handlers_filtered)));
130 } 119 }
131 120
132 // Called after icon data for ARC apps are loaded. Proceeds to OnArcIconEncoded. 121 // Called after icon data for ARC apps are loaded. Proceeds to OnArcIconEncoded.
133 void OnArcIconLoaded( 122 void OnArcIconLoaded(
134 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, 123 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
135 const FindTasksCallback& callback, 124 const FindTasksCallback& callback,
136 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers, 125 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers,
137 std::unique_ptr<arc::ActivityIconLoader::ActivityToIconsMap> icons) { 126 std::unique_ptr<arc::ArcIntentHelperBridge::ActivityToIconsMap> icons) {
138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 127 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
139 128
140 using extensions::api::file_manager_private::Verb; 129 using extensions::api::file_manager_private::Verb;
141 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) { 130 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) {
142 std::string action(arc::kIntentActionView); 131 std::string action(arc::kIntentActionView);
143 if (handler->action.has_value()) 132 if (handler->action.has_value())
144 action = *handler->action; 133 action = *handler->action;
145 std::string name(handler->name); 134 std::string name(handler->name);
146 Verb handler_verb = Verb::VERB_NONE; 135 Verb handler_verb = Verb::VERB_NONE;
147 if (action == arc::kIntentActionSend || 136 if (action == arc::kIntentActionSend ||
148 action == arc::kIntentActionSendMultiple) { 137 action == arc::kIntentActionSendMultiple) {
149 handler_verb = Verb::VERB_SHARE_WITH; 138 handler_verb = Verb::VERB_SHARE_WITH;
150 } 139 }
151 auto it = icons->find(arc::ActivityIconLoader::ActivityName( 140 auto it = icons->find(arc::ArcIntentHelperBridge::ActivityName(
152 handler->package_name, handler->activity_name)); 141 handler->package_name, handler->activity_name));
153 const GURL& icon_url = 142 const GURL& icon_url =
154 (it == icons->end() ? GURL::EmptyGURL() 143 (it == icons->end() ? GURL::EmptyGURL()
155 : it->second.icon16_dataurl->data); 144 : it->second.icon16_dataurl->data);
156 result_list->push_back(FullTaskDescriptor( 145 result_list->push_back(FullTaskDescriptor(
157 TaskDescriptor( 146 TaskDescriptor(
158 ActivityNameToAppId(handler->package_name, handler->activity_name), 147 ActivityNameToAppId(handler->package_name, handler->activity_name),
159 TASK_TYPE_ARC_APP, ArcActionToFileTaskActionId(action)), 148 TASK_TYPE_ARC_APP, ArcActionToFileTaskActionId(action)),
160 name, handler_verb, icon_url, false /* is_default */, 149 name, handler_verb, icon_url, false /* is_default */,
161 action != arc::kIntentActionView /* is_generic */)); 150 action != arc::kIntentActionView /* is_generic */));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 235 }
247 236
248 arc_intent_helper->HandleUrlList( 237 arc_intent_helper->HandleUrlList(
249 std::move(urls), AppIdToActivityName(task.app_id), 238 std::move(urls), AppIdToActivityName(task.app_id),
250 FileTaskActionIdToArcActionType(task.action_id)); 239 FileTaskActionIdToArcActionType(task.action_id));
251 return true; 240 return true;
252 } 241 }
253 242
254 } // namespace file_tasks 243 } // namespace file_tasks
255 } // namespace file_manager 244 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698