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

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

Issue 1756193008: Support uninstalling ARC app from Chrome launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 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 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" 15 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/crx_file/id_util.h" 17 #include "components/crx_file/id_util.h"
18 #include "components/pref_registry/pref_registry_syncable.h" 18 #include "components/pref_registry/pref_registry_syncable.h"
19 #include "components/prefs/scoped_user_pref_update.h" 19 #include "components/prefs/scoped_user_pref_update.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 21
22 namespace { 22 namespace {
23 23
24 const char kName[] = "name"; 24 const char kName[] = "name";
25 const char kPackageName[] = "package_name"; 25 const char kPackageName[] = "package_name";
26 const char kActivity[] = "activity"; 26 const char kActivity[] = "activity";
27 const char kSticky[] = "sticky";
27 const char kLastLaunchTime[] = "lastlaunchtime"; 28 const char kLastLaunchTime[] = "lastlaunchtime";
28 29
29 // Provider of write access to a dictionary storing ARC app prefs. 30 // Provider of write access to a dictionary storing ARC app prefs.
30 class ScopedArcAppListPrefUpdate : public DictionaryPrefUpdate { 31 class ScopedArcAppListPrefUpdate : public DictionaryPrefUpdate {
31 public: 32 public:
32 ScopedArcAppListPrefUpdate(PrefService* service, const std::string& id) 33 ScopedArcAppListPrefUpdate(PrefService* service, const std::string& id)
33 : DictionaryPrefUpdate(service, prefs::kArcApps), 34 : DictionaryPrefUpdate(service, prefs::kArcApps),
34 id_(id) {} 35 id_(id) {}
35 36
36 ~ScopedArcAppListPrefUpdate() override {} 37 ~ScopedArcAppListPrefUpdate() override {}
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 scoped_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetApp( 228 scoped_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetApp(
228 const std::string& app_id) const { 229 const std::string& app_id) const {
229 const base::DictionaryValue* app = nullptr; 230 const base::DictionaryValue* app = nullptr;
230 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); 231 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps);
231 if (!apps || !apps->GetDictionaryWithoutPathExpansion(app_id, &app)) 232 if (!apps || !apps->GetDictionaryWithoutPathExpansion(app_id, &app))
232 return scoped_ptr<AppInfo>(); 233 return scoped_ptr<AppInfo>();
233 234
234 std::string name; 235 std::string name;
235 std::string package_name; 236 std::string package_name;
236 std::string activity; 237 std::string activity;
238 bool sticky;
xiyuan 2016/03/08 16:40:11 Set a default value, in case kSticky does not exis
victorhsieh0 2016/03/08 18:02:52 Done.
237 app->GetString(kName, &name); 239 app->GetString(kName, &name);
238 app->GetString(kPackageName, &package_name); 240 app->GetString(kPackageName, &package_name);
239 app->GetString(kActivity, &activity); 241 app->GetString(kActivity, &activity);
242 app->GetBoolean(kSticky, &sticky);
240 243
241 base::Time last_launch_time; 244 base::Time last_launch_time;
242 std::string last_launch_time_str; 245 std::string last_launch_time_str;
243 if (app->GetString(kLastLaunchTime, &last_launch_time_str)) { 246 if (app->GetString(kLastLaunchTime, &last_launch_time_str)) {
244 int64_t last_launch_time_i64 = 0; 247 int64_t last_launch_time_i64 = 0;
245 if (base::StringToInt64(last_launch_time_str, &last_launch_time_i64)) { 248 if (base::StringToInt64(last_launch_time_str, &last_launch_time_i64)) {
246 last_launch_time = base::Time::FromInternalValue(last_launch_time_i64); 249 last_launch_time = base::Time::FromInternalValue(last_launch_time_i64);
247 } else { 250 } else {
248 NOTREACHED(); 251 NOTREACHED();
249 } 252 }
250 } 253 }
251 254
252 scoped_ptr<AppInfo> app_info(new AppInfo(name, 255 scoped_ptr<AppInfo> app_info(new AppInfo(name,
253 package_name, 256 package_name,
254 activity, 257 activity,
255 last_launch_time, 258 last_launch_time,
259 sticky,
256 ready_apps_.count(app_id) > 0)); 260 ready_apps_.count(app_id) > 0));
257 return app_info; 261 return app_info;
258 } 262 }
259 263
260 bool ArcAppListPrefs::IsRegistered(const std::string& app_id) const { 264 bool ArcAppListPrefs::IsRegistered(const std::string& app_id) const {
261 const base::DictionaryValue* app = nullptr; 265 const base::DictionaryValue* app = nullptr;
262 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); 266 const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps);
263 if (!apps || !apps->GetDictionary(app_id, &app)) 267 if (!apps || !apps->GetDictionary(app_id, &app))
264 return false; 268 return false;
265 269
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 FOR_EACH_OBSERVER(Observer, observer_list_, 329 FOR_EACH_OBSERVER(Observer, observer_list_,
326 OnAppNameUpdated(app_id, app.name)); 330 OnAppNameUpdated(app_id, app.name));
327 } 331 }
328 } 332 }
329 333
330 ScopedArcAppListPrefUpdate update(prefs_, app_id); 334 ScopedArcAppListPrefUpdate update(prefs_, app_id);
331 base::DictionaryValue* app_dict = update.Get(); 335 base::DictionaryValue* app_dict = update.Get();
332 app_dict->SetString(kName, app.name); 336 app_dict->SetString(kName, app.name);
333 app_dict->SetString(kPackageName, app.package_name); 337 app_dict->SetString(kPackageName, app.package_name);
334 app_dict->SetString(kActivity, app.activity); 338 app_dict->SetString(kActivity, app.activity);
339 app_dict->SetBoolean(kSticky, app.sticky);
335 340
336 // From now, app is available. 341 // From now, app is available.
337 if (!ready_apps_.count(app_id)) 342 if (!ready_apps_.count(app_id))
338 ready_apps_.insert(app_id); 343 ready_apps_.insert(app_id);
339 344
340 if (was_registered) { 345 if (was_registered) {
341 FOR_EACH_OBSERVER(Observer, 346 FOR_EACH_OBSERVER(Observer,
342 observer_list_, 347 observer_list_,
343 OnAppReadyChanged(app_id, true)); 348 OnAppReadyChanged(app_id, true));
344 } else { 349 } else {
345 AppInfo app_info(app.name, 350 AppInfo app_info(app.name,
346 app.package_name, 351 app.package_name,
347 app.activity, 352 app.activity,
348 base::Time(), 353 base::Time(),
354 app.sticky,
349 true); 355 true);
350 FOR_EACH_OBSERVER(Observer, 356 FOR_EACH_OBSERVER(Observer,
351 observer_list_, 357 observer_list_,
352 OnAppRegistered(app_id, app_info)); 358 OnAppRegistered(app_id, app_info));
353 } 359 }
354 360
355 std::map<std::string, uint32_t>::iterator deferred_icons = 361 std::map<std::string, uint32_t>::iterator deferred_icons =
356 request_icon_deferred_.find(app_id); 362 request_icon_deferred_.find(app_id);
357 if (deferred_icons != request_icon_deferred_.end()) { 363 if (deferred_icons != request_icon_deferred_.end()) {
358 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) { 364 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 480
475 FOR_EACH_OBSERVER(Observer, 481 FOR_EACH_OBSERVER(Observer,
476 observer_list_, 482 observer_list_,
477 OnAppIconUpdated(app_id, scale_factor)); 483 OnAppIconUpdated(app_id, scale_factor));
478 } 484 }
479 485
480 ArcAppListPrefs::AppInfo::AppInfo(const std::string& name, 486 ArcAppListPrefs::AppInfo::AppInfo(const std::string& name,
481 const std::string& package_name, 487 const std::string& package_name,
482 const std::string& activity, 488 const std::string& activity,
483 const base::Time& last_launch_time, 489 const base::Time& last_launch_time,
490 bool sticky,
484 bool ready) 491 bool ready)
485 : name(name), 492 : name(name),
486 package_name(package_name), 493 package_name(package_name),
487 activity(activity), 494 activity(activity),
488 last_launch_time(last_launch_time), 495 last_launch_time(last_launch_time),
496 sticky(sticky),
489 ready(ready) {} 497 ready(ready) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698