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

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

Issue 2707133006: Start ARC and sign in after Chrome OS login (Closed)
Patch Set: rebase to ToT Created 3 years, 9 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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if (infos.empty()) 179 if (infos.empty())
180 LOG(WARNING) << "Unable to launch note-taking app; none available"; 180 LOG(WARNING) << "Unable to launch note-taking app; none available";
181 else 181 else
182 result = LaunchAppInternal(profile, infos[0].app_id, path); 182 result = LaunchAppInternal(profile, infos[0].app_id, path);
183 UMA_HISTOGRAM_ENUMERATION(kDefaultLaunchResultHistogramName, 183 UMA_HISTOGRAM_ENUMERATION(kDefaultLaunchResultHistogramName,
184 static_cast<int>(result), 184 static_cast<int>(result),
185 static_cast<int>(LaunchResult::MAX)); 185 static_cast<int>(LaunchResult::MAX));
186 } 186 }
187 187
188 void NoteTakingHelper::OnIntentFiltersUpdated() { 188 void NoteTakingHelper::OnIntentFiltersUpdated() {
189 if (android_enabled_) 189 if (play_store_enabled_)
190 UpdateAndroidApps(); 190 UpdateAndroidApps();
191 } 191 }
192 192
193 void NoteTakingHelper::OnArcPlayStoreEnabledChanged(bool enabled) { 193 void NoteTakingHelper::OnArcPlayStoreEnabledChanged(bool enabled) {
194 android_enabled_ = enabled; 194 play_store_enabled_ = enabled;
195 if (!enabled) { 195 if (!enabled) {
196 android_apps_.clear(); 196 android_apps_.clear();
197 android_apps_received_ = false; 197 android_apps_received_ = false;
198 } 198 }
199 for (auto& observer : observers_) 199 for (auto& observer : observers_)
200 observer.OnAvailableNoteTakingAppsUpdated(); 200 observer.OnAvailableNoteTakingAppsUpdated();
201 } 201 }
202 202
203 NoteTakingHelper::NoteTakingHelper() 203 NoteTakingHelper::NoteTakingHelper()
204 : launch_chrome_app_callback_( 204 : launch_chrome_app_callback_(
205 base::Bind(&apps::LaunchPlatformAppWithAction)), 205 base::Bind(&apps::LaunchPlatformAppWithAction)),
206 extension_registry_observer_(this), 206 extension_registry_observer_(this),
207 weak_ptr_factory_(this) { 207 weak_ptr_factory_(this) {
208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
209 209
210 const std::string switch_value = 210 const std::string switch_value =
211 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 211 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
212 switches::kNoteTakingAppIds); 212 switches::kNoteTakingAppIds);
213 if (!switch_value.empty()) { 213 if (!switch_value.empty()) {
214 whitelisted_chrome_app_ids_ = base::SplitString( 214 whitelisted_chrome_app_ids_ = base::SplitString(
215 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 215 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
216 } 216 }
217 whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(), 217 whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(),
218 kExtensionIds, 218 kExtensionIds,
219 kExtensionIds + arraysize(kExtensionIds)); 219 kExtensionIds + arraysize(kExtensionIds));
220 220
221 // Track profiles so we can observe their extension registries. 221 // Track profiles so we can observe their extension registries.
222 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 222 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
223 content::NotificationService::AllBrowserContextsAndSources()); 223 content::NotificationService::AllBrowserContextsAndSources());
224 android_enabled_ = false; 224 play_store_enabled_ = false;
225 for (Profile* profile : 225 for (Profile* profile :
226 g_browser_process->profile_manager()->GetLoadedProfiles()) { 226 g_browser_process->profile_manager()->GetLoadedProfiles()) {
227 extension_registry_observer_.Add( 227 extension_registry_observer_.Add(
228 extensions::ExtensionRegistry::Get(profile)); 228 extensions::ExtensionRegistry::Get(profile));
229 // Check if the profile has already enabled Google Play Store. 229 // Check if the profile has already enabled Google Play Store.
230 // IsArcPlayStoreEnabledForProfile() can return true only for the primary 230 // IsArcPlayStoreEnabledForProfile() can return true only for the primary
231 // profile. 231 // profile.
232 android_enabled_ |= arc::IsArcPlayStoreEnabledForProfile(profile); 232 play_store_enabled_ |= arc::IsArcPlayStoreEnabledForProfile(profile);
233 } 233 }
234 234
235 // Watch for changes of Google Play Store enabled state. 235 // Watch for changes of Google Play Store enabled state.
236 auto* session_manager = arc::ArcSessionManager::Get(); 236 auto* session_manager = arc::ArcSessionManager::Get();
237 session_manager->AddObserver(this); 237 session_manager->AddObserver(this);
238 238
239 // ArcIntentHelperBridge will notify us about changes to the list of available 239 // ArcIntentHelperBridge will notify us about changes to the list of available
240 // Android apps. 240 // Android apps.
241 auto* intent_helper_bridge = 241 auto* intent_helper_bridge =
242 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); 242 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>();
243 if (intent_helper_bridge) 243 if (intent_helper_bridge)
244 intent_helper_bridge->AddObserver(this); 244 intent_helper_bridge->AddObserver(this);
245 245
246 // If the ARC intent helper is ready, get the Android apps. Otherwise, 246 // If the ARC intent helper is ready, get the Android apps. Otherwise,
247 // UpdateAndroidApps() will be called when ArcServiceManager calls 247 // UpdateAndroidApps() will be called when ArcServiceManager calls
248 // OnIntentFiltersUpdated(). 248 // OnIntentFiltersUpdated().
249 if (android_enabled_ && 249 if (play_store_enabled_ && arc::ArcServiceManager::Get()
250 arc::ArcServiceManager::Get() 250 ->arc_bridge_service()
251 ->arc_bridge_service() 251 ->intent_helper()
252 ->intent_helper() 252 ->has_instance()) {
253 ->has_instance())
254 UpdateAndroidApps(); 253 UpdateAndroidApps();
254 }
255 } 255 }
256 256
257 NoteTakingHelper::~NoteTakingHelper() { 257 NoteTakingHelper::~NoteTakingHelper() {
258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
259 259
260 // ArcSessionManagerTest shuts down ARC before NoteTakingHelper. 260 // ArcSessionManagerTest shuts down ARC before NoteTakingHelper.
261 auto* intent_helper_bridge = 261 auto* intent_helper_bridge =
262 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); 262 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>();
263 if (intent_helper_bridge) 263 if (intent_helper_bridge)
264 intent_helper_bridge->RemoveObserver(this); 264 intent_helper_bridge->RemoveObserver(this);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 if (!helper) 311 if (!helper)
312 return; 312 return;
313 helper->RequestIntentHandlerList( 313 helper->RequestIntentHandlerList(
314 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, 314 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps,
315 weak_ptr_factory_.GetWeakPtr())); 315 weak_ptr_factory_.GetWeakPtr()));
316 } 316 }
317 317
318 void NoteTakingHelper::OnGotAndroidApps( 318 void NoteTakingHelper::OnGotAndroidApps(
319 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { 319 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) {
320 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 320 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
321 if (!android_enabled_) 321 if (!play_store_enabled_)
322 return; 322 return;
323 323
324 android_apps_.clear(); 324 android_apps_.clear();
325 android_apps_.reserve(handlers.size()); 325 android_apps_.reserve(handlers.size());
326 for (const auto& it : handlers) { 326 for (const auto& it : handlers) {
327 android_apps_.emplace_back( 327 android_apps_.emplace_back(
328 NoteTakingAppInfo{it->name, it->package_name, false}); 328 NoteTakingAppInfo{it->name, it->package_name, false});
329 } 329 }
330 android_apps_received_ = true; 330 android_apps_received_ = true;
331 331
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 for (auto& observer : observers_) 418 for (auto& observer : observers_)
419 observer.OnAvailableNoteTakingAppsUpdated(); 419 observer.OnAvailableNoteTakingAppsUpdated();
420 } 420 }
421 } 421 }
422 422
423 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { 423 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) {
424 extension_registry_observer_.Remove(registry); 424 extension_registry_observer_.Remove(registry);
425 } 425 }
426 426
427 } // namespace chromeos 427 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/note_taking_helper.h ('k') | chrome/browser/chromeos/note_taking_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698