OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/app_list/arc/arc_app_list_prefs.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 bool InstallIconFromFileThread(const std::string& app_id, | 102 bool InstallIconFromFileThread(const std::string& app_id, |
103 ui::ScaleFactor scale_factor, | 103 ui::ScaleFactor scale_factor, |
104 const base::FilePath& icon_path, | 104 const base::FilePath& icon_path, |
105 const std::vector<uint8_t>& content_png) { | 105 const std::vector<uint8_t>& content_png) { |
106 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 106 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
107 DCHECK(!content_png.empty()); | 107 DCHECK(!content_png.empty()); |
108 | 108 |
109 base::CreateDirectory(icon_path.DirName()); | 109 base::CreateDirectory(icon_path.DirName()); |
110 | 110 |
111 int wrote = base::WriteFile(icon_path, | 111 int wrote = |
112 reinterpret_cast<const char*>(&content_png[0]), | 112 base::WriteFile(icon_path, reinterpret_cast<const char*>(&content_png[0]), |
113 content_png.size()); | 113 content_png.size()); |
114 if (wrote != static_cast<int>(content_png.size())) { | 114 if (wrote != static_cast<int>(content_png.size())) { |
115 VLOG(2) << "Failed to write ARC icon file: " << icon_path.MaybeAsASCII() | 115 VLOG(2) << "Failed to write ARC icon file: " << icon_path.MaybeAsASCII() |
116 << "."; | 116 << "."; |
117 if (!base::DeleteFile(icon_path, false)) | 117 if (!base::DeleteFile(icon_path, false)) |
118 VLOG(2) << "Couldn't delete broken icon file" << icon_path.MaybeAsASCII() | 118 VLOG(2) << "Couldn't delete broken icon file" << icon_path.MaybeAsASCII() |
119 << "."; | 119 << "."; |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 return true; | 123 return true; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (!auth_service) | 227 if (!auth_service) |
228 return; | 228 return; |
229 | 229 |
230 if (auth_service->state() != arc::ArcAuthService::State::NOT_INITIALIZED) | 230 if (auth_service->state() != arc::ArcAuthService::State::NOT_INITIALIZED) |
231 OnOptInEnabled(auth_service->IsArcEnabled()); | 231 OnOptInEnabled(auth_service->IsArcEnabled()); |
232 auth_service->AddObserver(this); | 232 auth_service->AddObserver(this); |
233 | 233 |
234 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 234 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
235 DCHECK(bridge_service); | 235 DCHECK(bridge_service); |
236 | 236 |
| 237 bridge_service->app()->AddObserver(this); |
237 bridge_service->AddObserver(this); | 238 bridge_service->AddObserver(this); |
238 if (!bridge_service->ready()) | 239 if (!bridge_service->ready()) |
239 OnBridgeStopped(); | 240 OnBridgeStopped(); |
240 } | 241 } |
241 | 242 |
242 ArcAppListPrefs::~ArcAppListPrefs() { | 243 ArcAppListPrefs::~ArcAppListPrefs() { |
243 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 244 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
244 if (bridge_service) | 245 if (bridge_service) { |
245 bridge_service->RemoveObserver(this); | 246 bridge_service->RemoveObserver(this); |
| 247 bridge_service->app()->RemoveObserver(this); |
| 248 } |
246 | 249 |
247 arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); | 250 arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); |
248 if (auth_service) | 251 if (auth_service) |
249 auth_service->RemoveObserver(this); | 252 auth_service->RemoveObserver(this); |
250 } | 253 } |
251 | 254 |
252 base::FilePath ArcAppListPrefs::GetAppPath(const std::string& app_id) const { | 255 base::FilePath ArcAppListPrefs::GetAppPath(const std::string& app_id) const { |
253 return base_path_.AppendASCII(app_id); | 256 return base_path_.AppendASCII(app_id); |
254 } | 257 } |
255 | 258 |
256 base::FilePath ArcAppListPrefs::GetIconPath( | 259 base::FilePath ArcAppListPrefs::GetIconPath( |
257 const std::string& app_id, | 260 const std::string& app_id, |
258 ui::ScaleFactor scale_factor) const { | 261 ui::ScaleFactor scale_factor) const { |
259 const base::FilePath app_path = GetAppPath(app_id); | 262 const base::FilePath app_path = GetAppPath(app_id); |
260 switch (scale_factor) { | 263 switch (scale_factor) { |
261 case ui::SCALE_FACTOR_100P: | 264 case ui::SCALE_FACTOR_100P: |
262 return app_path.AppendASCII("icon_100p.png"); | 265 return app_path.AppendASCII("icon_100p.png"); |
263 case ui::SCALE_FACTOR_125P: | 266 case ui::SCALE_FACTOR_125P: |
264 return app_path.AppendASCII("icon_125p.png"); | 267 return app_path.AppendASCII("icon_125p.png"); |
265 case ui::SCALE_FACTOR_133P: | 268 case ui::SCALE_FACTOR_133P: |
266 return app_path.AppendASCII("icon_133p.png"); | 269 return app_path.AppendASCII("icon_133p.png"); |
267 case ui::SCALE_FACTOR_140P: | 270 case ui::SCALE_FACTOR_140P: |
268 return app_path.AppendASCII("icon_140p.png"); | 271 return app_path.AppendASCII("icon_140p.png"); |
269 case ui::SCALE_FACTOR_150P: | 272 case ui::SCALE_FACTOR_150P: |
270 return app_path.AppendASCII("icon_150p.png"); | 273 return app_path.AppendASCII("icon_150p.png"); |
271 case ui::SCALE_FACTOR_180P: | 274 case ui::SCALE_FACTOR_180P: |
272 return app_path.AppendASCII("icon_180p.png"); | 275 return app_path.AppendASCII("icon_180p.png"); |
273 case ui::SCALE_FACTOR_200P: | 276 case ui::SCALE_FACTOR_200P: |
274 return app_path.AppendASCII("icon_200p.png"); | 277 return app_path.AppendASCII("icon_200p.png"); |
275 case ui::SCALE_FACTOR_250P: | 278 case ui::SCALE_FACTOR_250P: |
276 return app_path.AppendASCII("icon_250p.png"); | 279 return app_path.AppendASCII("icon_250p.png"); |
277 case ui::SCALE_FACTOR_300P: | 280 case ui::SCALE_FACTOR_300P: |
278 return app_path.AppendASCII("icon_300p.png"); | 281 return app_path.AppendASCII("icon_300p.png"); |
279 default: | 282 default: |
280 NOTREACHED(); | 283 NOTREACHED(); |
281 return base::FilePath(); | 284 return base::FilePath(); |
282 } | 285 } |
283 } | 286 } |
284 | 287 |
285 void ArcAppListPrefs::RequestIcon(const std::string& app_id, | 288 void ArcAppListPrefs::RequestIcon(const std::string& app_id, |
286 ui::ScaleFactor scale_factor) { | 289 ui::ScaleFactor scale_factor) { |
287 if (!IsRegistered(app_id)) { | 290 if (!IsRegistered(app_id)) { |
288 VLOG(2) << "Request to load icon for non-registered app: " | 291 VLOG(2) << "Request to load icon for non-registered app: " << app_id << "."; |
289 << app_id << "."; | |
290 return; | 292 return; |
291 } | 293 } |
292 | 294 |
293 // In case app is not ready, defer this request. | 295 // In case app is not ready, defer this request. |
294 if (!ready_apps_.count(app_id)) { | 296 if (!ready_apps_.count(app_id)) { |
295 request_icon_deferred_[app_id] = | 297 request_icon_deferred_[app_id] = |
296 request_icon_deferred_[app_id] | 1 << scale_factor; | 298 request_icon_deferred_[app_id] | 1 << scale_factor; |
297 return; | 299 return; |
298 } | 300 } |
299 | 301 |
300 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 302 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
301 if (!bridge_service) { | 303 if (!bridge_service) { |
302 NOTREACHED(); | 304 NOTREACHED(); |
303 return; | 305 return; |
304 } | 306 } |
305 arc::mojom::AppInstance* app_instance = bridge_service->app_instance(); | 307 arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
306 if (!app_instance) { | 308 if (!app_instance) { |
307 // AppInstance should be ready since we have app_id in ready_apps_. | 309 // AppInstance should be ready since we have app_id in ready_apps_. |
308 NOTREACHED(); | 310 NOTREACHED(); |
309 return; | 311 return; |
310 } | 312 } |
311 | 313 |
312 std::unique_ptr<AppInfo> app_info = GetApp(app_id); | 314 std::unique_ptr<AppInfo> app_info = GetApp(app_id); |
313 if (!app_info) { | 315 if (!app_info) { |
314 VLOG(2) << "Failed to get app info: " << app_id << "."; | 316 VLOG(2) << "Failed to get app info: " << app_id << "."; |
315 return; | 317 return; |
316 } | 318 } |
317 | 319 |
318 if (app_info->icon_resource_id.empty()) { | 320 if (app_info->icon_resource_id.empty()) { |
319 app_instance->RequestAppIcon( | 321 app_instance->RequestAppIcon( |
320 app_info->package_name, app_info->activity, | 322 app_info->package_name, app_info->activity, |
321 static_cast<arc::mojom::ScaleFactor>(scale_factor)); | 323 static_cast<arc::mojom::ScaleFactor>(scale_factor)); |
322 } else { | 324 } else { |
323 app_instance->RequestIcon( | 325 app_instance->RequestIcon( |
324 app_info->icon_resource_id, | 326 app_info->icon_resource_id, |
(...skipping 13 matching lines...) Expand all Loading... |
338 | 340 |
339 std::unique_ptr<AppInfo> app_info = GetApp(app_id); | 341 std::unique_ptr<AppInfo> app_info = GetApp(app_id); |
340 if (!app_info) { | 342 if (!app_info) { |
341 VLOG(2) << "Failed to get app info: " << app_id << "."; | 343 VLOG(2) << "Failed to get app info: " << app_id << "."; |
342 return; | 344 return; |
343 } | 345 } |
344 | 346 |
345 // In case app is not ready, defer this request. | 347 // In case app is not ready, defer this request. |
346 if (!ready_apps_.count(app_id)) { | 348 if (!ready_apps_.count(app_id)) { |
347 SetNotificationsEnabledDeferred(prefs_).Put(app_id, enabled); | 349 SetNotificationsEnabledDeferred(prefs_).Put(app_id, enabled); |
348 FOR_EACH_OBSERVER(Observer, observer_list_, | 350 FOR_EACH_OBSERVER( |
349 OnNotificationsEnabledChanged( | 351 Observer, observer_list_, |
350 app_info->package_name, enabled)); | 352 OnNotificationsEnabledChanged(app_info->package_name, enabled)); |
351 return; | 353 return; |
352 } | 354 } |
353 | 355 |
354 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 356 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
355 if (!bridge_service) { | 357 if (!bridge_service) { |
356 NOTREACHED(); | 358 NOTREACHED(); |
357 return; | 359 return; |
358 } | 360 } |
359 | 361 |
360 arc::mojom::AppInstance* app_instance = bridge_service->app_instance(); | 362 arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
361 if (!app_instance) { | 363 if (!app_instance) { |
362 // AppInstance should be ready since we have app_id in ready_apps_. | 364 // AppInstance should be ready since we have app_id in ready_apps_. |
363 NOTREACHED(); | 365 NOTREACHED(); |
364 return; | 366 return; |
365 } | 367 } |
366 | 368 |
367 if (bridge_service->app_version() < kSetNotificationsEnabledMinVersion) { | 369 if (bridge_service->app()->version() < kSetNotificationsEnabledMinVersion) { |
368 VLOG(2) << "app version is too small to set notifications enabled."; | 370 VLOG(2) << "app version is too small to set notifications enabled."; |
369 return; | 371 return; |
370 } | 372 } |
371 | 373 |
372 SetNotificationsEnabledDeferred(prefs_).Remove(app_id); | 374 SetNotificationsEnabledDeferred(prefs_).Remove(app_id); |
373 app_instance->SetNotificationsEnabled(app_info->package_name, enabled); | 375 app_instance->SetNotificationsEnabled(app_info->package_name, enabled); |
374 } | 376 } |
375 | 377 |
376 void ArcAppListPrefs::AddObserver(Observer* observer) { | 378 void ArcAppListPrefs::AddObserver(Observer* observer) { |
377 observer_list_.AddObserver(observer); | 379 observer_list_.AddObserver(observer); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (!IsArcEnabled()) | 420 if (!IsArcEnabled()) |
419 return std::vector<std::string>(); | 421 return std::vector<std::string>(); |
420 return GetAppIdsNoArcEnabledCheck(); | 422 return GetAppIdsNoArcEnabledCheck(); |
421 } | 423 } |
422 | 424 |
423 std::vector<std::string> ArcAppListPrefs::GetAppIdsNoArcEnabledCheck() const { | 425 std::vector<std::string> ArcAppListPrefs::GetAppIdsNoArcEnabledCheck() const { |
424 std::vector<std::string> ids; | 426 std::vector<std::string> ids; |
425 | 427 |
426 // crx_file::id_util is de-facto utility for id generation. | 428 // crx_file::id_util is de-facto utility for id generation. |
427 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); | 429 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); |
428 for (base::DictionaryValue::Iterator app_id(*apps); | 430 for (base::DictionaryValue::Iterator app_id(*apps); !app_id.IsAtEnd(); |
429 !app_id.IsAtEnd(); app_id.Advance()) { | 431 app_id.Advance()) { |
430 if (!crx_file::id_util::IdIsValid(app_id.key())) | 432 if (!crx_file::id_util::IdIsValid(app_id.key())) |
431 continue; | 433 continue; |
432 | 434 |
433 ids.push_back(app_id.key()); | 435 ids.push_back(app_id.key()); |
434 } | 436 } |
435 | 437 |
436 return ids; | 438 return ids; |
437 } | 439 } |
438 | 440 |
439 std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetApp( | 441 std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetApp( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 ScopedArcPrefUpdate update(prefs_, app_id, prefs::kArcApps); | 519 ScopedArcPrefUpdate update(prefs_, app_id, prefs::kArcApps); |
518 base::DictionaryValue* app_dict = update.Get(); | 520 base::DictionaryValue* app_dict = update.Get(); |
519 const std::string string_value = base::Int64ToString(time.ToInternalValue()); | 521 const std::string string_value = base::Int64ToString(time.ToInternalValue()); |
520 app_dict->SetString(kLastLaunchTime, string_value); | 522 app_dict->SetString(kLastLaunchTime, string_value); |
521 } | 523 } |
522 | 524 |
523 void ArcAppListPrefs::DisableAllApps() { | 525 void ArcAppListPrefs::DisableAllApps() { |
524 std::set<std::string> old_ready_apps; | 526 std::set<std::string> old_ready_apps; |
525 old_ready_apps.swap(ready_apps_); | 527 old_ready_apps.swap(ready_apps_); |
526 for (auto& app_id : old_ready_apps) { | 528 for (auto& app_id : old_ready_apps) { |
527 FOR_EACH_OBSERVER(Observer, | 529 FOR_EACH_OBSERVER(Observer, observer_list_, |
528 observer_list_, | |
529 OnAppReadyChanged(app_id, false)); | 530 OnAppReadyChanged(app_id, false)); |
530 } | 531 } |
531 } | 532 } |
532 | 533 |
533 void ArcAppListPrefs::NotifyRegisteredApps() { | 534 void ArcAppListPrefs::NotifyRegisteredApps() { |
534 if (apps_restored_) | 535 if (apps_restored_) |
535 return; | 536 return; |
536 | 537 |
537 DCHECK(ready_apps_.empty()); | 538 DCHECK(ready_apps_.empty()); |
538 std::vector<std::string> app_ids = GetAppIdsNoArcEnabledCheck(); | 539 std::vector<std::string> app_ids = GetAppIdsNoArcEnabledCheck(); |
539 for (const auto& app_id : app_ids) { | 540 for (const auto& app_id : app_ids) { |
540 std::unique_ptr<AppInfo> app_info = GetApp(app_id); | 541 std::unique_ptr<AppInfo> app_info = GetApp(app_id); |
541 if (!app_info) { | 542 if (!app_info) { |
542 NOTREACHED(); | 543 NOTREACHED(); |
543 continue; | 544 continue; |
544 } | 545 } |
545 FOR_EACH_OBSERVER(Observer, | 546 FOR_EACH_OBSERVER(Observer, observer_list_, |
546 observer_list_, | |
547 OnAppRegistered(app_id, *app_info)); | 547 OnAppRegistered(app_id, *app_info)); |
548 } | 548 } |
549 | 549 |
550 apps_restored_ = true; | 550 apps_restored_ = true; |
551 } | 551 } |
552 | 552 |
553 void ArcAppListPrefs::RemoveAllApps() { | 553 void ArcAppListPrefs::RemoveAllApps() { |
554 std::vector<std::string> app_ids = GetAppIdsNoArcEnabledCheck(); | 554 std::vector<std::string> app_ids = GetAppIdsNoArcEnabledCheck(); |
555 for (const auto& app_id : app_ids) | 555 for (const auto& app_id : app_ids) |
556 RemoveApp(app_id); | 556 RemoveApp(app_id); |
557 } | 557 } |
558 | 558 |
559 void ArcAppListPrefs::OnOptInEnabled(bool enabled) { | 559 void ArcAppListPrefs::OnOptInEnabled(bool enabled) { |
560 if (enabled) | 560 if (enabled) |
561 NotifyRegisteredApps(); | 561 NotifyRegisteredApps(); |
562 else | 562 else |
563 RemoveAllApps(); | 563 RemoveAllApps(); |
564 } | 564 } |
565 | 565 |
566 void ArcAppListPrefs::OnBridgeStopped() { | 566 void ArcAppListPrefs::OnBridgeStopped() { |
567 DisableAllApps(); | 567 DisableAllApps(); |
568 } | 568 } |
569 | 569 |
570 void ArcAppListPrefs::OnAppInstanceReady() { | 570 void ArcAppListPrefs::OnInstanceReady() { |
571 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 571 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
572 if (!bridge_service) { | 572 if (!bridge_service) { |
573 NOTREACHED(); | 573 NOTREACHED(); |
574 return; | 574 return; |
575 } | 575 } |
576 arc::mojom::AppInstance* app_instance = bridge_service->app_instance(); | 576 arc::mojom::AppInstance* app_instance = bridge_service->app()->instance(); |
577 if (!app_instance) { | 577 if (!app_instance) { |
578 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | 578 VLOG(2) << "Request to refresh app list when bridge service is not ready."; |
579 return; | 579 return; |
580 } | 580 } |
581 | 581 |
582 app_instance->Init(binding_.CreateInterfacePtrAndBind()); | 582 app_instance->Init(binding_.CreateInterfacePtrAndBind()); |
583 app_instance->RefreshAppList(); | 583 app_instance->RefreshAppList(); |
584 } | 584 } |
585 | 585 |
586 void ArcAppListPrefs::OnAppInstanceClosed() { | 586 void ArcAppListPrefs::OnInstanceClosed() { |
587 ready_apps_.clear(); | 587 ready_apps_.clear(); |
588 } | 588 } |
589 | 589 |
590 void ArcAppListPrefs::AddAppAndShortcut( | 590 void ArcAppListPrefs::AddAppAndShortcut( |
591 const std::string& name, | 591 const std::string& name, |
592 const std::string& package_name, | 592 const std::string& package_name, |
593 const std::string& activity, | 593 const std::string& activity, |
594 const std::string& intent_uri, | 594 const std::string& intent_uri, |
595 const std::string& icon_resource_id, | 595 const std::string& icon_resource_id, |
596 const bool sticky, | 596 const bool sticky, |
(...skipping 22 matching lines...) Expand all Loading... |
619 app_dict->SetBoolean(kSticky, sticky); | 619 app_dict->SetBoolean(kSticky, sticky); |
620 app_dict->SetBoolean(kNotificationsEnabled, notifications_enabled); | 620 app_dict->SetBoolean(kNotificationsEnabled, notifications_enabled); |
621 app_dict->SetBoolean(kShortcut, shortcut); | 621 app_dict->SetBoolean(kShortcut, shortcut); |
622 app_dict->SetInteger(kOrientationLock, static_cast<int>(orientation_lock)); | 622 app_dict->SetInteger(kOrientationLock, static_cast<int>(orientation_lock)); |
623 | 623 |
624 // From now, app is available. | 624 // From now, app is available. |
625 if (!ready_apps_.count(app_id)) | 625 if (!ready_apps_.count(app_id)) |
626 ready_apps_.insert(app_id); | 626 ready_apps_.insert(app_id); |
627 | 627 |
628 if (was_registered) { | 628 if (was_registered) { |
629 FOR_EACH_OBSERVER(Observer, | 629 FOR_EACH_OBSERVER(Observer, observer_list_, |
630 observer_list_, | |
631 OnAppReadyChanged(app_id, true)); | 630 OnAppReadyChanged(app_id, true)); |
632 } else { | 631 } else { |
633 AppInfo app_info(name, package_name, activity, intent_uri, icon_resource_id, | 632 AppInfo app_info(name, package_name, activity, intent_uri, icon_resource_id, |
634 base::Time(), sticky, notifications_enabled, true, | 633 base::Time(), sticky, notifications_enabled, true, |
635 arc::ShouldShowInLauncher(app_id), shortcut, | 634 arc::ShouldShowInLauncher(app_id), shortcut, |
636 orientation_lock); | 635 orientation_lock); |
637 FOR_EACH_OBSERVER(Observer, | 636 FOR_EACH_OBSERVER(Observer, |
638 observer_list_, | 637 observer_list_, |
639 OnAppRegistered(app_id, app_info)); | 638 OnAppRegistered(app_id, app_info)); |
640 } | 639 } |
(...skipping 26 matching lines...) Expand all Loading... |
667 ready_apps_.erase(app_id); | 666 ready_apps_.erase(app_id); |
668 | 667 |
669 // Remove from prefs. | 668 // Remove from prefs. |
670 DictionaryPrefUpdate update(prefs_, prefs::kArcApps); | 669 DictionaryPrefUpdate update(prefs_, prefs::kArcApps); |
671 base::DictionaryValue* apps = update.Get(); | 670 base::DictionaryValue* apps = update.Get(); |
672 const bool removed = apps->Remove(app_id, nullptr); | 671 const bool removed = apps->Remove(app_id, nullptr); |
673 DCHECK(removed); | 672 DCHECK(removed); |
674 // app_id may be released by observers, get the path first. | 673 // app_id may be released by observers, get the path first. |
675 const base::FilePath app_path = GetAppPath(app_id); | 674 const base::FilePath app_path = GetAppPath(app_id); |
676 | 675 |
677 FOR_EACH_OBSERVER(Observer, | 676 FOR_EACH_OBSERVER(Observer, observer_list_, OnAppRemoved(app_id)); |
678 observer_list_, | |
679 OnAppRemoved(app_id)); | |
680 | 677 |
681 // Remove local data on file system. | 678 // Remove local data on file system. |
682 content::BrowserThread::GetBlockingPool()->PostTask( | 679 content::BrowserThread::GetBlockingPool()->PostTask( |
683 FROM_HERE, | 680 FROM_HERE, base::Bind(&DeleteAppFolderFromFileThread, app_path)); |
684 base::Bind(&DeleteAppFolderFromFileThread, app_path)); | |
685 } | 681 } |
686 | 682 |
687 void ArcAppListPrefs::OnAppListRefreshed( | 683 void ArcAppListPrefs::OnAppListRefreshed( |
688 mojo::Array<arc::mojom::AppInfoPtr> apps) { | 684 mojo::Array<arc::mojom::AppInfoPtr> apps) { |
689 DCHECK(IsArcEnabled()); | 685 DCHECK(IsArcEnabled()); |
690 std::vector<std::string> old_apps = GetAppIds(); | 686 std::vector<std::string> old_apps = GetAppIds(); |
691 | 687 |
692 ready_apps_.clear(); | 688 ready_apps_.clear(); |
693 for (const auto& app : apps) { | 689 for (const auto& app : apps) { |
694 // TODO(oshima): Do we have to update orientation? | 690 // TODO(oshima): Do we have to update orientation? |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 AddAppAndShortcut(shortcut->name, shortcut->package_name, | 744 AddAppAndShortcut(shortcut->name, shortcut->package_name, |
749 std::string() /* activity */, shortcut->intent_uri, | 745 std::string() /* activity */, shortcut->intent_uri, |
750 shortcut->icon_resource_id, false /* sticky */, | 746 shortcut->icon_resource_id, false /* sticky */, |
751 false /* notifications_enabled */, true /* shortcut */, | 747 false /* notifications_enabled */, true /* shortcut */, |
752 arc::mojom::OrientationLock::NONE); | 748 arc::mojom::OrientationLock::NONE); |
753 } | 749 } |
754 | 750 |
755 void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { | 751 void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { |
756 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); | 752 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); |
757 std::vector<std::string> apps_to_remove; | 753 std::vector<std::string> apps_to_remove; |
758 for (base::DictionaryValue::Iterator app_it(*apps); | 754 for (base::DictionaryValue::Iterator app_it(*apps); !app_it.IsAtEnd(); |
759 !app_it.IsAtEnd(); app_it.Advance()) { | 755 app_it.Advance()) { |
760 const base::Value* value = &app_it.value(); | 756 const base::Value* value = &app_it.value(); |
761 const base::DictionaryValue* app; | 757 const base::DictionaryValue* app; |
762 if (!value->GetAsDictionary(&app)) { | 758 if (!value->GetAsDictionary(&app)) { |
763 NOTREACHED(); | 759 NOTREACHED(); |
764 continue; | 760 continue; |
765 } | 761 } |
766 | 762 |
767 std::string app_package; | 763 std::string app_package; |
768 if (!app->GetString(kPackageName, &app_package)) { | 764 if (!app->GetString(kPackageName, &app_package)) { |
769 NOTREACHED(); | 765 NOTREACHED(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 return; | 806 return; |
811 } | 807 } |
812 | 808 |
813 InstallIcon(app_id, static_cast<ui::ScaleFactor>(scale_factor), | 809 InstallIcon(app_id, static_cast<ui::ScaleFactor>(scale_factor), |
814 icon_png_data.To<std::vector<uint8_t>>()); | 810 icon_png_data.To<std::vector<uint8_t>>()); |
815 } | 811 } |
816 | 812 |
817 void ArcAppListPrefs::OnTaskCreated(int32_t task_id, | 813 void ArcAppListPrefs::OnTaskCreated(int32_t task_id, |
818 const mojo::String& package_name, | 814 const mojo::String& package_name, |
819 const mojo::String& activity) { | 815 const mojo::String& activity) { |
820 FOR_EACH_OBSERVER(Observer, | 816 FOR_EACH_OBSERVER(Observer, observer_list_, |
821 observer_list_, | |
822 OnTaskCreated(task_id, package_name, activity)); | 817 OnTaskCreated(task_id, package_name, activity)); |
823 } | 818 } |
824 | 819 |
825 void ArcAppListPrefs::OnTaskDestroyed(int32_t task_id) { | 820 void ArcAppListPrefs::OnTaskDestroyed(int32_t task_id) { |
826 FOR_EACH_OBSERVER(Observer, observer_list_, OnTaskDestroyed(task_id)); | 821 FOR_EACH_OBSERVER(Observer, observer_list_, OnTaskDestroyed(task_id)); |
827 } | 822 } |
828 | 823 |
829 void ArcAppListPrefs::OnTaskSetActive(int32_t task_id) { | 824 void ArcAppListPrefs::OnTaskSetActive(int32_t task_id) { |
830 FOR_EACH_OBSERVER(Observer, observer_list_, OnTaskSetActive(task_id)); | 825 FOR_EACH_OBSERVER(Observer, observer_list_, OnTaskSetActive(task_id)); |
831 } | 826 } |
832 | 827 |
833 void ArcAppListPrefs::OnNotificationsEnabledChanged( | 828 void ArcAppListPrefs::OnNotificationsEnabledChanged( |
834 const mojo::String& package_name, bool enabled) { | 829 const mojo::String& package_name, |
| 830 bool enabled) { |
835 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); | 831 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); |
836 for (base::DictionaryValue::Iterator app(*apps); | 832 for (base::DictionaryValue::Iterator app(*apps); !app.IsAtEnd(); |
837 !app.IsAtEnd(); app.Advance()) { | 833 app.Advance()) { |
838 const base::DictionaryValue* app_dict; | 834 const base::DictionaryValue* app_dict; |
839 std::string app_package_name; | 835 std::string app_package_name; |
840 if (!app.value().GetAsDictionary(&app_dict) || | 836 if (!app.value().GetAsDictionary(&app_dict) || |
841 !app_dict->GetString(kPackageName, &app_package_name)) { | 837 !app_dict->GetString(kPackageName, &app_package_name)) { |
842 NOTREACHED(); | 838 NOTREACHED(); |
843 continue; | 839 continue; |
844 } | 840 } |
845 if (app_package_name != package_name) { | 841 if (app_package_name != package_name) { |
846 continue; | 842 continue; |
847 } | 843 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 packages.push_back(package.key()); | 891 packages.push_back(package.key()); |
896 } | 892 } |
897 | 893 |
898 return packages; | 894 return packages; |
899 } | 895 } |
900 | 896 |
901 void ArcAppListPrefs::InstallIcon(const std::string& app_id, | 897 void ArcAppListPrefs::InstallIcon(const std::string& app_id, |
902 ui::ScaleFactor scale_factor, | 898 ui::ScaleFactor scale_factor, |
903 const std::vector<uint8_t>& content_png) { | 899 const std::vector<uint8_t>& content_png) { |
904 base::FilePath icon_path = GetIconPath(app_id, scale_factor); | 900 base::FilePath icon_path = GetIconPath(app_id, scale_factor); |
905 base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(), | 901 base::PostTaskAndReplyWithResult( |
906 FROM_HERE, | 902 content::BrowserThread::GetBlockingPool(), FROM_HERE, |
907 base::Bind(&InstallIconFromFileThread, | 903 base::Bind(&InstallIconFromFileThread, app_id, scale_factor, icon_path, |
908 app_id, | 904 content_png), |
909 scale_factor, | 905 base::Bind(&ArcAppListPrefs::OnIconInstalled, |
910 icon_path, | 906 weak_ptr_factory_.GetWeakPtr(), app_id, scale_factor)); |
911 content_png), | |
912 base::Bind(&ArcAppListPrefs::OnIconInstalled, | |
913 weak_ptr_factory_.GetWeakPtr(), | |
914 app_id, | |
915 scale_factor)); | |
916 } | 907 } |
917 | 908 |
918 void ArcAppListPrefs::OnIconInstalled(const std::string& app_id, | 909 void ArcAppListPrefs::OnIconInstalled(const std::string& app_id, |
919 ui::ScaleFactor scale_factor, | 910 ui::ScaleFactor scale_factor, |
920 bool install_succeed) { | 911 bool install_succeed) { |
921 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 912 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
922 if (!install_succeed) | 913 if (!install_succeed) |
923 return; | 914 return; |
924 | 915 |
925 FOR_EACH_OBSERVER(Observer, | 916 FOR_EACH_OBSERVER(Observer, observer_list_, |
926 observer_list_, | |
927 OnAppIconUpdated(app_id, scale_factor)); | 917 OnAppIconUpdated(app_id, scale_factor)); |
928 } | 918 } |
929 | 919 |
930 ArcAppListPrefs::AppInfo::AppInfo(const std::string& name, | 920 ArcAppListPrefs::AppInfo::AppInfo(const std::string& name, |
931 const std::string& package_name, | 921 const std::string& package_name, |
932 const std::string& activity, | 922 const std::string& activity, |
933 const std::string& intent_uri, | 923 const std::string& intent_uri, |
934 const std::string& icon_resource_id, | 924 const std::string& icon_resource_id, |
935 const base::Time& last_launch_time, | 925 const base::Time& last_launch_time, |
936 bool sticky, | 926 bool sticky, |
(...skipping 24 matching lines...) Expand all Loading... |
961 int64_t last_backup_android_id, | 951 int64_t last_backup_android_id, |
962 int64_t last_backup_time, | 952 int64_t last_backup_time, |
963 bool should_sync, | 953 bool should_sync, |
964 bool system) | 954 bool system) |
965 : package_name(package_name), | 955 : package_name(package_name), |
966 package_version(package_version), | 956 package_version(package_version), |
967 last_backup_android_id(last_backup_android_id), | 957 last_backup_android_id(last_backup_android_id), |
968 last_backup_time(last_backup_time), | 958 last_backup_time(last_backup_time), |
969 should_sync(should_sync), | 959 should_sync(should_sync), |
970 system(system) {} | 960 system(system) {} |
OLD | NEW |