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

Side by Side Diff: components/arc/intent_helper/link_handler_model_impl.cc

Issue 2337193005: Consolidate 4 GetIntentHelper functions (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 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 "components/arc/intent_helper/link_handler_model_impl.h" 5 #include "components/arc/intent_helper/link_handler_model_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 } // namespace 50 } // namespace
51 51
52 LinkHandlerModelImpl::LinkHandlerModelImpl( 52 LinkHandlerModelImpl::LinkHandlerModelImpl(
53 scoped_refptr<ActivityIconLoader> icon_loader) 53 scoped_refptr<ActivityIconLoader> icon_loader)
54 : icon_loader_(icon_loader), weak_ptr_factory_(this) {} 54 : icon_loader_(icon_loader), weak_ptr_factory_(this) {}
55 55
56 LinkHandlerModelImpl::~LinkHandlerModelImpl() {} 56 LinkHandlerModelImpl::~LinkHandlerModelImpl() {}
57 57
58 bool LinkHandlerModelImpl::Init(const GURL& url) { 58 bool LinkHandlerModelImpl::Init(const GURL& url) {
59 mojom::IntentHelperInstance* intent_helper_instance = GetIntentHelper(); 59 mojom::IntentHelperInstance* intent_helper_instance =
60 ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion,
61 nullptr);
60 if (!intent_helper_instance) 62 if (!intent_helper_instance)
61 return false; 63 return false;
62 64
63 // Check if ARC apps can handle the |url|. Since the information is held in 65 // Check if ARC apps can handle the |url|. Since the information is held in
64 // a different (ARC) process, issue a mojo IPC request. Usually, the 66 // a different (ARC) process, issue a mojo IPC request. Usually, the
65 // callback function, OnUrlHandlerList, is called within a few milliseconds 67 // callback function, OnUrlHandlerList, is called within a few milliseconds
66 // even on the slowest Chromebook we support. 68 // even on the slowest Chromebook we support.
67 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); 69 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url));
68 intent_helper_instance->RequestUrlHandlerList( 70 intent_helper_instance->RequestUrlHandlerList(
69 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList, 71 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList,
70 weak_ptr_factory_.GetWeakPtr())); 72 weak_ptr_factory_.GetWeakPtr()));
71 return true; 73 return true;
72 } 74 }
73 75
74 void LinkHandlerModelImpl::AddObserver(Observer* observer) { 76 void LinkHandlerModelImpl::AddObserver(Observer* observer) {
75 observer_list_.AddObserver(observer); 77 observer_list_.AddObserver(observer);
76 } 78 }
77 79
78 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url, 80 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url,
79 uint32_t handler_id) { 81 uint32_t handler_id) {
80 mojom::IntentHelperInstance* intent_helper_instance = GetIntentHelper(); 82 mojom::IntentHelperInstance* intent_helper_instance =
83 ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion,
84 nullptr);
81 if (!intent_helper_instance) 85 if (!intent_helper_instance)
82 return; 86 return;
83 if (handler_id >= handlers_.size()) 87 if (handler_id >= handlers_.size())
84 return; 88 return;
85 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); 89 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url));
86 intent_helper_instance->HandleUrl(rewritten.spec(), 90 intent_helper_instance->HandleUrl(rewritten.spec(),
87 handlers_[handler_id]->package_name); 91 handlers_[handler_id]->package_name);
88 } 92 }
89 93
90 mojom::IntentHelperInstance* LinkHandlerModelImpl::GetIntentHelper() {
91 ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
92 if (!bridge_service) {
93 DLOG(WARNING) << "ARC bridge is not ready.";
94 return nullptr;
95 }
96 mojom::IntentHelperInstance* intent_helper_instance =
97 bridge_service->intent_helper()->instance();
98 if (!intent_helper_instance) {
99 DLOG(WARNING) << "ARC intent helper instance is not ready.";
100 return nullptr;
101 }
102 if (bridge_service->intent_helper()->version() < kMinInstanceVersion) {
103 DLOG(WARNING) << "ARC intent helper instance is too old.";
104 return nullptr;
105 }
106 return intent_helper_instance;
107 }
108
109 void LinkHandlerModelImpl::OnUrlHandlerList( 94 void LinkHandlerModelImpl::OnUrlHandlerList(
110 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { 95 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) {
111 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); 96 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
112 97
113 bool icon_info_notified = false; 98 bool icon_info_notified = false;
114 if (icon_loader_) { 99 if (icon_loader_) {
115 std::vector<ActivityIconLoader::ActivityName> activities; 100 std::vector<ActivityIconLoader::ActivityName> activities;
116 for (size_t i = 0; i < handlers_.size(); ++i) { 101 for (size_t i = 0; i < handlers_.size(); ++i) {
117 activities.emplace_back(handlers_[i]->package_name, 102 activities.emplace_back(handlers_[i]->package_name,
118 handlers_[i]->activity_name); 103 handlers_[i]->activity_name);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!GetQueryValue(url, kKeyToFind, &value)) 160 if (!GetQueryValue(url, kKeyToFind, &value))
176 return url; 161 return url;
177 162
178 const GURL new_url(value); 163 const GURL new_url(value);
179 if (!new_url.is_valid()) 164 if (!new_url.is_valid())
180 return url; 165 return url;
181 return new_url; 166 return new_url;
182 } 167 }
183 168
184 } // namespace arc 169 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698