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

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

Issue 2655233007: Get rid of RefCounted for ActivityIconLoader. (Closed)
Patch Set: 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 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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "components/arc/arc_bridge_service.h" 11 #include "components/arc/arc_bridge_service.h"
12 #include "components/arc/arc_service_manager.h" 12 #include "components/arc/arc_service_manager.h"
13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" 13 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
14 #include "components/google/core/browser/google_util.h" 14 #include "components/google/core/browser/google_util.h"
15 #include "url/gurl.h"
16 #include "url/url_util.h" 15 #include "url/url_util.h"
17 16
18 namespace arc { 17 namespace arc {
19 18
20 namespace { 19 namespace {
21 20
22 constexpr int kMaxValueLen = 2048; 21 constexpr int kMaxValueLen = 2048;
23 22
24 bool GetQueryValue(const GURL& url, 23 bool GetQueryValue(const GURL& url,
25 const std::string& key_to_find, 24 const std::string& key_to_find,
(...skipping 15 matching lines...) Expand all
41 &output); 40 &output);
42 *out = base::string16(output.data(), output.length()); 41 *out = base::string16(output.data(), output.length());
43 return true; 42 return true;
44 } 43 }
45 } 44 }
46 return false; 45 return false;
47 } 46 }
48 47
49 } // namespace 48 } // namespace
50 49
51 LinkHandlerModelImpl::LinkHandlerModelImpl( 50 LinkHandlerModelImpl::LinkHandlerModelImpl() : weak_ptr_factory_(this) {}
52 scoped_refptr<ActivityIconLoader> icon_loader)
53 : icon_loader_(icon_loader), weak_ptr_factory_(this) {}
54 51
55 LinkHandlerModelImpl::~LinkHandlerModelImpl() {} 52 LinkHandlerModelImpl::~LinkHandlerModelImpl() = default;
56 53
57 bool LinkHandlerModelImpl::Init(const GURL& url) { 54 bool LinkHandlerModelImpl::Init(const GURL& url) {
58 auto* arc_service_manager = ArcServiceManager::Get(); 55 auto* arc_service_manager = ArcServiceManager::Get();
59 if (!arc_service_manager) 56 if (!arc_service_manager)
60 return false; 57 return false;
61 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( 58 auto* instance = ARC_GET_INSTANCE_FOR_METHOD(
62 arc_service_manager->arc_bridge_service()->intent_helper(), 59 arc_service_manager->arc_bridge_service()->intent_helper(),
63 RequestUrlHandlerList); 60 RequestUrlHandlerList);
64 if (!instance) 61 if (!instance)
65 return false; 62 return false;
(...skipping 26 matching lines...) Expand all
92 return; 89 return;
93 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url)); 90 const GURL rewritten(RewriteUrlFromQueryIfAvailable(url));
94 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name); 91 instance->HandleUrl(rewritten.spec(), handlers_[handler_id]->package_name);
95 } 92 }
96 93
97 void LinkHandlerModelImpl::OnUrlHandlerList( 94 void LinkHandlerModelImpl::OnUrlHandlerList(
98 std::vector<mojom::IntentHandlerInfoPtr> handlers) { 95 std::vector<mojom::IntentHandlerInfoPtr> handlers) {
99 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers)); 96 handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
100 97
101 bool icon_info_notified = false; 98 bool icon_info_notified = false;
102 if (icon_loader_) { 99 auto* intent_helper_bridge =
100 ArcServiceManager::GetGlobalService<ArcIntentHelperBridge>();
101 if (intent_helper_bridge) {
103 std::vector<ActivityIconLoader::ActivityName> activities; 102 std::vector<ActivityIconLoader::ActivityName> activities;
104 for (size_t i = 0; i < handlers_.size(); ++i) { 103 for (size_t i = 0; i < handlers_.size(); ++i) {
105 activities.emplace_back(handlers_[i]->package_name, 104 activities.emplace_back(handlers_[i]->package_name,
106 handlers_[i]->activity_name); 105 handlers_[i]->activity_name);
107 } 106 }
108 const ActivityIconLoader::GetResult result = icon_loader_->GetActivityIcons( 107 const ActivityIconLoader::GetResult result =
109 activities, base::Bind(&LinkHandlerModelImpl::NotifyObserver, 108 intent_helper_bridge->icon_loader()->GetActivityIcons(
110 weak_ptr_factory_.GetWeakPtr())); 109 activities, base::Bind(&LinkHandlerModelImpl::NotifyObserver,
110 weak_ptr_factory_.GetWeakPtr()));
111 icon_info_notified = ActivityIconLoader::HasIconsReadyCallbackRun(result); 111 icon_info_notified = ActivityIconLoader::HasIconsReadyCallbackRun(result);
112 } 112 }
113 113
114 if (!icon_info_notified) { 114 if (!icon_info_notified) {
115 // Call NotifyObserver() without icon information, unless 115 // Call NotifyObserver() without icon information, unless
116 // GetActivityIcons has already called it. Otherwise if we delay the 116 // GetActivityIcons has already called it. Otherwise if we delay the
117 // notification waiting for all icons, context menu may flicker. 117 // notification waiting for all icons, context menu may flicker.
118 NotifyObserver(nullptr); 118 NotifyObserver(nullptr);
119 } 119 }
120 } 120 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!GetQueryValue(url, kKeyToFind, &value)) 164 if (!GetQueryValue(url, kKeyToFind, &value))
165 return url; 165 return url;
166 166
167 const GURL new_url(value); 167 const GURL new_url(value);
168 if (!new_url.is_valid()) 168 if (!new_url.is_valid())
169 return url; 169 return url;
170 return new_url; 170 return new_url;
171 } 171 }
172 172
173 } // namespace arc 173 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698