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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_launcher.cc

Issue 2751913004: arc: Fix race conditon when Play Store is started too early. (Closed)
Patch Set: 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/ui/app_list/arc/arc_app_launcher.h" 5 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
10 10
11 ArcAppLauncher::ArcAppLauncher(content::BrowserContext* context, 11 ArcAppLauncher::ArcAppLauncher(content::BrowserContext* context,
12 const std::string& app_id, 12 const std::string& app_id,
13 bool landscape_layout) 13 bool landscape_layout,
14 : context_(context), app_id_(app_id), landscape_layout_(landscape_layout) { 14 bool deferred_launch_allowed)
15 : context_(context),
16 app_id_(app_id),
17 landscape_layout_(landscape_layout),
18 deferred_launch_allowed_(deferred_launch_allowed) {
15 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); 19 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
16 DCHECK(prefs); 20 DCHECK(prefs);
17 21
18 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id_); 22 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id_);
19 if (app_info && app_info->ready) 23 if (app_info && (app_info->ready || deferred_launch_allowed_))
20 LaunchApp(); 24 LaunchApp();
21 else 25 else
22 prefs->AddObserver(this); 26 prefs->AddObserver(this);
23 } 27 }
24 28
25 ArcAppLauncher::~ArcAppLauncher() { 29 ArcAppLauncher::~ArcAppLauncher() {
26 if (!app_launched_) { 30 if (!app_launched_) {
27 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); 31 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
28 if (prefs) 32 if (prefs)
29 prefs->RemoveObserver(this); 33 prefs->RemoveObserver(this);
30 VLOG(2) << "App " << app_id_ << "was not launched."; 34 VLOG(2) << "App " << app_id_ << "was not launched.";
31 } 35 }
32 } 36 }
33 37
34 void ArcAppLauncher::OnAppRegistered( 38 void ArcAppLauncher::OnAppRegistered(
35 const std::string& app_id, 39 const std::string& app_id,
36 const ArcAppListPrefs::AppInfo& app_info) { 40 const ArcAppListPrefs::AppInfo& app_info) {
37 if (app_id == app_id_ && app_info.ready) 41 if (app_id == app_id_ && (app_info.ready || deferred_launch_allowed_))
38 LaunchApp(); 42 LaunchApp();
39 } 43 }
40 44
41 void ArcAppLauncher::OnAppReadyChanged(const std::string& app_id, bool ready) { 45 void ArcAppLauncher::OnAppReadyChanged(const std::string& app_id, bool ready) {
42 if (app_id == app_id_ && ready) 46 if (app_id == app_id_ && (ready || deferred_launch_allowed_))
43 LaunchApp(); 47 LaunchApp();
44 } 48 }
45 49
46 void ArcAppLauncher::LaunchApp() { 50 void ArcAppLauncher::LaunchApp() {
47 DCHECK(!app_launched_); 51 DCHECK(!app_launched_);
48 52
49 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); 53 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
50 DCHECK(prefs && prefs->GetApp(app_id_)); 54 DCHECK(prefs && prefs->GetApp(app_id_));
51 prefs->RemoveObserver(this); 55 prefs->RemoveObserver(this);
52 56
53 if (!arc::LaunchApp(context_, app_id_, landscape_layout_)) 57 if (!arc::LaunchApp(context_, app_id_, landscape_layout_))
hidehiko 2017/03/16 01:05:39 (I know this is not a main focus of this CL, but..
khmel 2017/03/16 16:12:14 Nice catch! thanks
54 VLOG(2) << "Failed to launch app: " + app_id_ + "."; 58 VLOG(2) << "Failed to launch app: " + app_id_ + ".";
55 59
56 app_launched_ = true; 60 app_launched_ = true;
57 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698