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

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

Issue 2337193005: Consolidate 4 GetIntentHelper functions (Closed)
Patch Set: Address comments 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);
60 if (!intent_helper_instance) 61 if (!intent_helper_instance)
61 return false; 62 return false;
62 63
63 // Check if ARC apps can handle the |url|. Since the information is held in 64 // 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 65 // a different (ARC) process, issue a mojo IPC request. Usually, the
65 // callback function, OnUrlHandlerList, is called within a few milliseconds 66 // callback function, OnUrlHandlerList, is called within a few milliseconds
66 // even on the slowest Chromebook we support. 67 // even on the slowest Chromebook we support.
67 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); 68 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url));
68 intent_helper_instance->RequestUrlHandlerList( 69 intent_helper_instance->RequestUrlHandlerList(
69 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList, 70 rewritten.spec(), base::Bind(&LinkHandlerModelImpl::OnUrlHandlerList,
70 weak_ptr_factory_.GetWeakPtr())); 71 weak_ptr_factory_.GetWeakPtr()));
71 return true; 72 return true;
72 } 73 }
73 74
74 void LinkHandlerModelImpl::AddObserver(Observer* observer) { 75 void LinkHandlerModelImpl::AddObserver(Observer* observer) {
75 observer_list_.AddObserver(observer); 76 observer_list_.AddObserver(observer);
76 } 77 }
77 78
78 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url, 79 void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url,
79 uint32_t handler_id) { 80 uint32_t handler_id) {
80 mojom::IntentHelperInstance* intent_helper_instance = GetIntentHelper(); 81 mojom::IntentHelperInstance* intent_helper_instance =
82 ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
81 if (!intent_helper_instance) 83 if (!intent_helper_instance)
82 return; 84 return;
83 if (handler_id >= handlers_.size()) 85 if (handler_id >= handlers_.size())
84 return; 86 return;
85 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); 87 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url));
86 intent_helper_instance->HandleUrl(rewritten.spec(), 88 intent_helper_instance->HandleUrl(rewritten.spec(),
87 handlers_[handler_id]->package_name); 89 handlers_[handler_id]->package_name);
88 } 90 }
89 91
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( 92 void LinkHandlerModelImpl::OnUrlHandlerList(
110 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) { 93 mojo::Array<mojom::UrlHandlerInfoPtr> handlers) {
111 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); 94 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
112 95
113 bool icon_info_notified = false; 96 bool icon_info_notified = false;
114 if (icon_loader_) { 97 if (icon_loader_) {
115 std::vector<ActivityIconLoader::ActivityName> activities; 98 std::vector<ActivityIconLoader::ActivityName> activities;
116 for (size_t i = 0; i < handlers_.size(); ++i) { 99 for (size_t i = 0; i < handlers_.size(); ++i) {
117 activities.emplace_back(handlers_[i]->package_name, 100 activities.emplace_back(handlers_[i]->package_name,
118 handlers_[i]->activity_name); 101 handlers_[i]->activity_name);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!GetQueryValue(url, kKeyToFind, &value)) 158 if (!GetQueryValue(url, kKeyToFind, &value))
176 return url; 159 return url;
177 160
178 const GURL new_url(value); 161 const GURL new_url(value);
179 if (!new_url.is_valid()) 162 if (!new_url.is_valid())
180 return url; 163 return url;
181 return new_url; 164 return new_url;
182 } 165 }
183 166
184 } // namespace arc 167 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698