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