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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (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/arc_intent_helper_bridge.h" 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/new_window_delegate.h" 10 #include "ash/common/new_window_delegate.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 ArcIntentHelperBridge::~ArcIntentHelperBridge() { 43 ArcIntentHelperBridge::~ArcIntentHelperBridge() {
44 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
45 arc_bridge_service()->intent_helper()->RemoveObserver(this); 45 arc_bridge_service()->intent_helper()->RemoveObserver(this);
46 } 46 }
47 47
48 void ArcIntentHelperBridge::OnInstanceReady() { 48 void ArcIntentHelperBridge::OnInstanceReady() {
49 DCHECK(thread_checker_.CalledOnValidThread()); 49 DCHECK(thread_checker_.CalledOnValidThread());
50 ash::Shell::GetInstance()->set_link_handler_model_factory(this); 50 ash::Shell::GetInstance()->set_link_handler_model_factory(this);
51 arc_bridge_service()->intent_helper()->instance()->Init( 51 auto* instance =
52 binding_.CreateInterfacePtrAndBind()); 52 arc_bridge_service()->intent_helper()->GetInstanceForMethod("Init");
53 if (!instance)
54 return;
55 instance->Init(binding_.CreateInterfacePtrAndBind());
53 } 56 }
54 57
55 void ArcIntentHelperBridge::OnInstanceClosed() { 58 void ArcIntentHelperBridge::OnInstanceClosed() {
56 DCHECK(thread_checker_.CalledOnValidThread()); 59 DCHECK(thread_checker_.CalledOnValidThread());
57 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); 60 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr);
58 } 61 }
59 62
60 void ArcIntentHelperBridge::OnIconInvalidated( 63 void ArcIntentHelperBridge::OnIconInvalidated(
61 const mojo::String& package_name) { 64 const mojo::String& package_name) {
62 DCHECK(thread_checker_.CalledOnValidThread()); 65 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 if (IsIntentHelperPackage(handler->package_name.get())) 117 if (IsIntentHelperPackage(handler->package_name.get()))
115 continue; 118 continue;
116 handlers_filtered.push_back(std::move(handler)); 119 handlers_filtered.push_back(std::move(handler));
117 } 120 }
118 return handlers_filtered; 121 return handlers_filtered;
119 } 122 }
120 123
121 // static 124 // static
122 mojom::IntentHelperInstance* 125 mojom::IntentHelperInstance*
123 ArcIntentHelperBridge::GetIntentHelperInstanceWithErrorCode( 126 ArcIntentHelperBridge::GetIntentHelperInstanceWithErrorCode(
124 int min_instance_version, 127 const std::string& method_name_for_logging,
128 uint32_t min_instance_version,
125 GetResult* out_error_code) { 129 GetResult* out_error_code) {
126 ArcBridgeService* bridge_service = ArcBridgeService::Get(); 130 ArcBridgeService* bridge_service = ArcBridgeService::Get();
127 if (!bridge_service) { 131 if (!bridge_service) {
128 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { 132 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) {
129 VLOG(2) << "ARC bridge is not supported."; 133 VLOG(2) << "ARC bridge is not supported.";
130 if (out_error_code) 134 if (out_error_code)
131 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED; 135 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED;
132 } else { 136 } else {
133 VLOG(2) << "ARC bridge is not ready."; 137 VLOG(2) << "ARC bridge is not ready.";
134 if (out_error_code) 138 if (out_error_code)
135 *out_error_code = GetResult::FAILED_ARC_NOT_READY; 139 *out_error_code = GetResult::FAILED_ARC_NOT_READY;
136 } 140 }
137 return nullptr; 141 return nullptr;
138 } 142 }
139 mojom::IntentHelperInstance* intent_helper_instance = 143
140 bridge_service->intent_helper()->instance(); 144 if (!bridge_service->intent_helper()->HasInstance()) {
141 if (!intent_helper_instance) {
142 VLOG(2) << "ARC intent helper instance is not ready."; 145 VLOG(2) << "ARC intent helper instance is not ready.";
143 if (out_error_code) 146 if (out_error_code)
144 *out_error_code = GetResult::FAILED_ARC_NOT_READY; 147 *out_error_code = GetResult::FAILED_ARC_NOT_READY;
145 return nullptr; 148 return nullptr;
146 } 149 }
147 const int version = bridge_service->intent_helper()->version(); 150
148 if (version < min_instance_version) { 151 auto* instance = bridge_service->intent_helper()->GetInstanceForMethod(
149 VLOG(1) << "ARC intent helper instance is too old. required: " 152 method_name_for_logging, min_instance_version);
150 << min_instance_version << ", actual: " << version; 153 if (!instance) {
151 if (out_error_code) 154 if (out_error_code)
152 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED; 155 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED;
153 return nullptr; 156 return nullptr;
154 } 157 }
155 return intent_helper_instance; 158 return instance;
156 } 159 }
157 160
158 // static 161 // static
159 mojom::IntentHelperInstance* ArcIntentHelperBridge::GetIntentHelperInstance( 162 mojom::IntentHelperInstance* ArcIntentHelperBridge::GetIntentHelperInstance(
160 int min_instance_version) { 163 const std::string& method_name_for_logging,
161 return GetIntentHelperInstanceWithErrorCode(min_instance_version, nullptr); 164 uint32_t min_instance_version) {
165 return GetIntentHelperInstanceWithErrorCode(method_name_for_logging,
166 min_instance_version, nullptr);
162 } 167 }
163 168
164 void ArcIntentHelperBridge::OnIntentFiltersUpdated( 169 void ArcIntentHelperBridge::OnIntentFiltersUpdated(
165 mojo::Array<mojom::IntentFilterPtr> filters) { 170 mojo::Array<mojom::IntentFilterPtr> filters) {
166 DCHECK(thread_checker_.CalledOnValidThread()); 171 DCHECK(thread_checker_.CalledOnValidThread());
167 activity_resolver_->UpdateIntentFilters(std::move(filters)); 172 activity_resolver_->UpdateIntentFilters(std::move(filters));
168 } 173 }
169 174
170 } // namespace arc 175 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698