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

Side by Side Diff: chrome/browser/chromeos/note_taking_helper.cc

Issue 2599673005: arc: Use GET_INTERFACE_FOR_METHOD macro (Closed)
Patch Set: Addressed feedback 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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/note_taking_helper.h" 5 #include "chrome/browser/chromeos/note_taking_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "apps/launcher.h" 10 #include "apps/launcher.h"
11 #include "ash/common/system/chromeos/palette/palette_utils.h" 11 #include "ash/common/system/chromeos/palette/palette_utils.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/chromeos/file_manager/path_util.h" 21 #include "chrome/browser/chromeos/file_manager/path_util.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chromeos/chromeos_switches.h" 25 #include "chromeos/chromeos_switches.h"
26 #include "components/arc/arc_bridge_service.h" 26 #include "components/arc/arc_bridge_service.h"
27 #include "components/arc/arc_service_manager.h"
27 #include "components/arc/common/intent_helper.mojom.h" 28 #include "components/arc/common/intent_helper.mojom.h"
28 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
31 #include "extensions/browser/extension_registry.h" 32 #include "extensions/browser/extension_registry.h"
32 #include "extensions/common/api/app_runtime.h" 33 #include "extensions/common/api/app_runtime.h"
33 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 namespace app_runtime = extensions::api::app_runtime; 37 namespace app_runtime = extensions::api::app_runtime;
(...skipping 13 matching lines...) Expand all
50 51
51 // Returns true if |app_id|, a value from prefs::kNoteTakingAppId, looks like 52 // Returns true if |app_id|, a value from prefs::kNoteTakingAppId, looks like
52 // it's probably an Android package name rather than a Chrome extension ID. 53 // it's probably an Android package name rather than a Chrome extension ID.
53 bool LooksLikeAndroidPackageName(const std::string& app_id) { 54 bool LooksLikeAndroidPackageName(const std::string& app_id) {
54 // Android package names are required to contain at least one period (see 55 // Android package names are required to contain at least one period (see
55 // validateName() in PackageParser.java), while Chrome extension IDs contain 56 // validateName() in PackageParser.java), while Chrome extension IDs contain
56 // only characters in [a-p]. 57 // only characters in [a-p].
57 return app_id.find(".") != std::string::npos; 58 return app_id.find(".") != std::string::npos;
58 } 59 }
59 60
60 // Returns the helper used for intent-related communication with Android, or
61 // null if it's unavailable.
62 arc::mojom::IntentHelperInstance* GetIntentHelper(const std::string& method,
63 uint32_t min_version) {
64 return arc::ArcServiceManager::Get()
65 ->arc_bridge_service()
66 ->intent_helper()
67 ->GetInstanceForMethod(method, min_version);
68 }
69
70 // Creates a new Mojo IntentInfo struct for launching an Android note-taking app 61 // Creates a new Mojo IntentInfo struct for launching an Android note-taking app
71 // with an optional ClipData URI. 62 // with an optional ClipData URI.
72 arc::mojom::IntentInfoPtr CreateIntentInfo(const GURL& clip_data_uri) { 63 arc::mojom::IntentInfoPtr CreateIntentInfo(const GURL& clip_data_uri) {
73 arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New(); 64 arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New();
74 intent->action = NoteTakingHelper::kIntentAction; 65 intent->action = NoteTakingHelper::kIntentAction;
75 if (!clip_data_uri.is_empty()) 66 if (!clip_data_uri.is_empty())
76 intent->clip_data_uri = clip_data_uri.spec(); 67 intent->clip_data_uri = clip_data_uri.spec();
77 return intent; 68 return intent;
78 } 69 }
79 70
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (enabled_extensions.Contains(id)) { 261 if (enabled_extensions.Contains(id)) {
271 extensions.push_back(extension_registry->GetExtensionById( 262 extensions.push_back(extension_registry->GetExtensionById(
272 id, extensions::ExtensionRegistry::ENABLED)); 263 id, extensions::ExtensionRegistry::ENABLED));
273 } 264 }
274 } 265 }
275 return extensions; 266 return extensions;
276 } 267 }
277 268
278 void NoteTakingHelper::UpdateAndroidApps() { 269 void NoteTakingHelper::UpdateAndroidApps() {
279 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 270 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
280 auto* helper = GetIntentHelper("RequestIntentHandlerList", 12); 271 auto* helper = ARC_GET_INSTANCE_FOR_METHOD(
272 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(),
273 RequestIntentHandlerList);
281 if (!helper) 274 if (!helper)
282 return; 275 return;
283 helper->RequestIntentHandlerList( 276 helper->RequestIntentHandlerList(
284 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, 277 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps,
285 weak_ptr_factory_.GetWeakPtr())); 278 weak_ptr_factory_.GetWeakPtr()));
286 } 279 }
287 280
288 void NoteTakingHelper::OnGotAndroidApps( 281 void NoteTakingHelper::OnGotAndroidApps(
289 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { 282 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) {
290 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 283 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 16 matching lines...) Expand all
307 const std::string& app_id, 300 const std::string& app_id,
308 const base::FilePath& path) { 301 const base::FilePath& path) {
309 DCHECK(profile); 302 DCHECK(profile);
310 303
311 if (LooksLikeAndroidPackageName(app_id)) { 304 if (LooksLikeAndroidPackageName(app_id)) {
312 // Android app. 305 // Android app.
313 if (!arc::ArcSessionManager::Get()->IsAllowedForProfile(profile)) { 306 if (!arc::ArcSessionManager::Get()->IsAllowedForProfile(profile)) {
314 LOG(WARNING) << "Can't launch Android app " << app_id << " for profile"; 307 LOG(WARNING) << "Can't launch Android app " << app_id << " for profile";
315 return false; 308 return false;
316 } 309 }
317 auto* helper = GetIntentHelper("HandleIntent", 10); 310 auto* helper = ARC_GET_INSTANCE_FOR_METHOD(
311 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(),
312 HandleIntent);
318 if (!helper) 313 if (!helper)
319 return false; 314 return false;
320 315
321 GURL clip_data_uri; 316 GURL clip_data_uri;
322 if (!path.empty()) { 317 if (!path.empty()) {
323 if (!file_manager::util::ConvertPathToArcUrl(path, &clip_data_uri) || 318 if (!file_manager::util::ConvertPathToArcUrl(path, &clip_data_uri) ||
324 !clip_data_uri.is_valid()) { 319 !clip_data_uri.is_valid()) {
325 LOG(WARNING) << "Failed to convert " << path.value() << " to ARC URI"; 320 LOG(WARNING) << "Failed to convert " << path.value() << " to ARC URI";
326 return false; 321 return false;
327 } 322 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 for (auto& observer : observers_) 373 for (auto& observer : observers_)
379 observer.OnAvailableNoteTakingAppsUpdated(); 374 observer.OnAvailableNoteTakingAppsUpdated();
380 } 375 }
381 } 376 }
382 377
383 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { 378 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) {
384 extension_registry_observer_.Remove(registry); 379 extension_registry_observer_.Remove(registry);
385 } 380 }
386 381
387 } // namespace chromeos 382 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698