OLD | NEW |
---|---|
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/ash/launcher/arc_app_deferred_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 7 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
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 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_item_controll er.h" | 10 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_item_controll er.h" |
11 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 11 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/image/canvas_image_source.h" | 14 #include "ui/gfx/image/canvas_image_source.h" |
15 #include "ui/gfx/image/image_skia_operations.h" | 15 #include "ui/gfx/image/image_skia_operations.h" |
16 #include "ui/gfx/paint_throbber.h" | 16 #include "ui/gfx/paint_throbber.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | |
19 constexpr int kUpdateIconIntervalMs = 40; // 40ms for 25 frames per second. | 20 constexpr int kUpdateIconIntervalMs = 40; // 40ms for 25 frames per second. |
20 constexpr int kSpinningGapPercent = 25; | 21 constexpr int kSpinningGapPercent = 25; |
21 | 22 |
22 class SpinningEffectSource : public gfx::CanvasImageSource { | 23 class SpinningEffectSource : public gfx::CanvasImageSource { |
23 public: | 24 public: |
24 SpinningEffectSource( | 25 SpinningEffectSource( |
25 const base::WeakPtr<ArcAppDeferredLauncherController>& host, | 26 const base::WeakPtr<ArcAppDeferredLauncherController>& host, |
26 const std::string& shelf_app_id, | 27 const std::string& shelf_app_id, |
27 const gfx::ImageSkia& image) | 28 const gfx::ImageSkia& image) |
28 : gfx::CanvasImageSource(image.size(), false /* is opaque */), | 29 : gfx::CanvasImageSource(image.size(), false /* is opaque */), |
(...skipping 26 matching lines...) Expand all Loading... | |
55 }; | 56 }; |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 ArcAppDeferredLauncherController::ArcAppDeferredLauncherController( | 59 ArcAppDeferredLauncherController::ArcAppDeferredLauncherController( |
59 ChromeLauncherControllerImpl* owner) | 60 ChromeLauncherControllerImpl* owner) |
60 : owner_(owner), weak_ptr_factory_(this) { | 61 : owner_(owner), weak_ptr_factory_(this) { |
61 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { | 62 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { |
62 observed_profile_ = owner->GetProfile(); | 63 observed_profile_ = owner->GetProfile(); |
63 ArcAppListPrefs::Get(observed_profile_)->AddObserver(this); | 64 ArcAppListPrefs::Get(observed_profile_)->AddObserver(this); |
64 } | 65 } |
66 arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); | |
67 if (auth_service) | |
68 auth_service->AddObserver(this); | |
Mr4D (OOO till 08-26)
2016/08/30 20:21:46
Just checking - is it guaranteed that the lifetime
khmel
2016/08/30 21:22:11
Actually we have unit tests were ArcAuthService mi
| |
65 } | 69 } |
66 | 70 |
67 ArcAppDeferredLauncherController::~ArcAppDeferredLauncherController() { | 71 ArcAppDeferredLauncherController::~ArcAppDeferredLauncherController() { |
72 arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); | |
73 if (auth_service) | |
74 auth_service->RemoveObserver(this); | |
68 if (observed_profile_) | 75 if (observed_profile_) |
69 ArcAppListPrefs::Get(observed_profile_)->RemoveObserver(this); | 76 ArcAppListPrefs::Get(observed_profile_)->RemoveObserver(this); |
70 } | 77 } |
71 | 78 |
72 void ArcAppDeferredLauncherController::MaybeApplySpinningEffect( | 79 void ArcAppDeferredLauncherController::MaybeApplySpinningEffect( |
73 const std::string& shelf_app_id, | 80 const std::string& shelf_app_id, |
74 gfx::ImageSkia* image) { | 81 gfx::ImageSkia* image) { |
75 DCHECK(image); | 82 DCHECK(image); |
76 if (app_controller_map_.find(shelf_app_id) == app_controller_map_.end()) | 83 if (app_controller_map_.find(shelf_app_id) == app_controller_map_.end()) |
77 return; | 84 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 129 |
123 Close(app_id); | 130 Close(app_id); |
124 | 131 |
125 arc::LaunchApp(owner_->GetProfile(), app_id); | 132 arc::LaunchApp(owner_->GetProfile(), app_id); |
126 } | 133 } |
127 | 134 |
128 void ArcAppDeferredLauncherController::OnAppRemoved(const std::string& app_id) { | 135 void ArcAppDeferredLauncherController::OnAppRemoved(const std::string& app_id) { |
129 Close(app_id); | 136 Close(app_id); |
130 } | 137 } |
131 | 138 |
139 void ArcAppDeferredLauncherController::OnOptInEnabled(bool enabled) { | |
140 // If Arc was disabled, remove all deferred launch requests. | |
Mr4D (OOO till 08-26)
2016/08/30 20:21:46
I suppose you want to move this comment to line 14
khmel
2016/08/30 21:22:11
Right, that the better place
| |
141 if (enabled) | |
142 return; | |
143 | |
144 while (!app_controller_map_.empty()) | |
145 Close(app_controller_map_.begin()->first); | |
146 } | |
147 | |
148 bool ArcAppDeferredLauncherController::HasApp(const std::string& app_id) const { | |
149 const std::string shelf_app_id = | |
150 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | |
151 return app_controller_map_.count(shelf_app_id); | |
152 } | |
153 | |
132 base::TimeDelta ArcAppDeferredLauncherController::GetActiveTime( | 154 base::TimeDelta ArcAppDeferredLauncherController::GetActiveTime( |
133 const std::string& shelf_app_id) const { | 155 const std::string& shelf_app_id) const { |
134 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); | 156 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); |
135 if (it == app_controller_map_.end()) | 157 if (it == app_controller_map_.end()) |
136 return base::TimeDelta(); | 158 return base::TimeDelta(); |
137 | 159 |
138 return it->second->GetActiveTime(); | 160 return it->second->GetActiveTime(); |
139 } | 161 } |
140 | 162 |
141 void ArcAppDeferredLauncherController::UpdateApps() { | 163 void ArcAppDeferredLauncherController::UpdateApps() { |
142 if (app_controller_map_.empty()) | 164 if (app_controller_map_.empty()) |
143 return; | 165 return; |
144 | 166 |
145 RegisterNextUpdate(); | 167 RegisterNextUpdate(); |
146 for (const auto pair : app_controller_map_) | 168 for (const auto pair : app_controller_map_) |
147 owner_->OnAppUpdated(owner_->GetProfile(), pair.first); | 169 owner_->OnAppUpdated(owner_->GetProfile(), pair.first); |
148 } | 170 } |
149 | 171 |
150 void ArcAppDeferredLauncherController::RegisterNextUpdate() { | 172 void ArcAppDeferredLauncherController::RegisterNextUpdate() { |
151 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 173 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
152 FROM_HERE, base::Bind(&ArcAppDeferredLauncherController::UpdateApps, | 174 FROM_HERE, base::Bind(&ArcAppDeferredLauncherController::UpdateApps, |
153 weak_ptr_factory_.GetWeakPtr()), | 175 weak_ptr_factory_.GetWeakPtr()), |
154 base::TimeDelta::FromMilliseconds(kUpdateIconIntervalMs)); | 176 base::TimeDelta::FromMilliseconds(kUpdateIconIntervalMs)); |
155 } | 177 } |
156 | 178 |
157 void ArcAppDeferredLauncherController::RegisterDeferredLaunch( | 179 void ArcAppDeferredLauncherController::RegisterDeferredLaunch( |
158 const std::string& app_id) { | 180 const std::string& app_id) { |
181 const arc::ArcAuthService* auth_service = arc::ArcAuthService::Get(); | |
182 DCHECK(auth_service); | |
183 DCHECK(auth_service->state() != arc::ArcAuthService::State::STOPPED); | |
184 DCHECK(auth_service->state() != arc::ArcAuthService::State::NOT_INITIALIZED); | |
185 | |
159 const std::string shelf_app_id = | 186 const std::string shelf_app_id = |
160 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 187 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
161 const ash::ShelfID shelf_id = owner_->GetShelfIDForAppID(shelf_app_id); | 188 const ash::ShelfID shelf_id = owner_->GetShelfIDForAppID(shelf_app_id); |
162 | 189 |
163 if (shelf_id) { | 190 if (shelf_id) { |
164 LauncherItemController* controller = | 191 LauncherItemController* controller = |
165 owner_->GetLauncherItemController(shelf_id); | 192 owner_->GetLauncherItemController(shelf_id); |
166 if (controller && | 193 if (controller && |
167 controller->type() != LauncherItemController::TYPE_SHORTCUT) { | 194 controller->type() != LauncherItemController::TYPE_SHORTCUT) { |
168 // We are allowed to apply new deferred controller only over shortcut. | 195 // We are allowed to apply new deferred controller only over shortcut. |
(...skipping 10 matching lines...) Expand all Loading... | |
179 } else { | 206 } else { |
180 owner_->SetItemController(shelf_id, controller); | 207 owner_->SetItemController(shelf_id, controller); |
181 owner_->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 208 owner_->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
182 } | 209 } |
183 | 210 |
184 if (app_controller_map_.empty()) | 211 if (app_controller_map_.empty()) |
185 RegisterNextUpdate(); | 212 RegisterNextUpdate(); |
186 | 213 |
187 app_controller_map_[shelf_app_id] = controller; | 214 app_controller_map_[shelf_app_id] = controller; |
188 } | 215 } |
OLD | NEW |