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

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

Issue 2353213002: arc: Fix Android App resurrected by sync. (Closed)
Patch Set: Remove redundant pref observer. Created 4 years, 2 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
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_package_sync_data_type_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_package_syncable_service.h" 5 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h"
6 6
7 #include <unordered_set> 7 #include <unordered_set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/profile_sync_service_factory.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
14 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h" 13 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "components/prefs/scoped_user_pref_update.h" 15 #include "components/prefs/scoped_user_pref_update.h"
17 #include "components/sync/api/sync_change_processor.h" 16 #include "components/sync/api/sync_change_processor.h"
18 #include "components/sync/api/sync_data.h" 17 #include "components/sync/api/sync_data.h"
19 #include "components/sync/api/sync_merge_result.h" 18 #include "components/sync/api/sync_merge_result.h"
20 #include "components/sync/driver/pref_names.h"
21 #include "components/sync/driver/sync_prefs.h"
22 #include "components/sync/driver/sync_service.h"
23 #include "components/sync/protocol/sync.pb.h" 19 #include "components/sync/protocol/sync.pb.h"
24 20
25 namespace arc { 21 namespace arc {
26 22
27 namespace { 23 namespace {
28 24
29 using syncer::SyncChange; 25 using syncer::SyncChange;
30 using ArcSyncItem = ArcPackageSyncableService::SyncItem; 26 using ArcSyncItem = ArcPackageSyncableService::SyncItem;
31 27
32 constexpr int64_t kNoAndroidID = 0; 28 constexpr int64_t kNoAndroidID = 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 67
72 // Creates new syncItem from ArcAppListPrefs::PackageInfo 68 // Creates new syncItem from ArcAppListPrefs::PackageInfo
73 std::unique_ptr<ArcSyncItem> CreateSyncItemFromPrefs( 69 std::unique_ptr<ArcSyncItem> CreateSyncItemFromPrefs(
74 std::unique_ptr<ArcAppListPrefs::PackageInfo> package_info) { 70 std::unique_ptr<ArcAppListPrefs::PackageInfo> package_info) {
75 DCHECK(package_info); 71 DCHECK(package_info);
76 return base::MakeUnique<ArcSyncItem>( 72 return base::MakeUnique<ArcSyncItem>(
77 package_info->package_name, package_info->package_version, 73 package_info->package_name, package_info->package_version,
78 package_info->last_backup_android_id, package_info->last_backup_time); 74 package_info->last_backup_android_id, package_info->last_backup_time);
79 } 75 }
80 76
81 bool ValidateEnableArcPackageSyncPref(Profile* profile) {
82 PrefService* pref_service = profile->GetPrefs();
83 // If device is set to sync everything, Arc package should be synced.
84 if (pref_service->GetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced))
85 return true;
86
87 bool apps_sync_enable = pref_service->GetBoolean(
88 sync_driver::SyncPrefs::GetPrefNameForDataType(syncer::APPS));
89 // ArcPackage sync service is controlled by apps checkbox in sync settings.
90 // Update ArcPackage sync setting pref if it is different from apps sync
91 // setting pref.
92 const char* arc_sync_path =
93 sync_driver::SyncPrefs::GetPrefNameForDataType(syncer::ARC_PACKAGE);
94 if (apps_sync_enable != pref_service->GetBoolean(arc_sync_path)) {
95 pref_service->SetBoolean(arc_sync_path, apps_sync_enable);
96 }
97
98 return apps_sync_enable;
99 }
100
101 } // namespace 77 } // namespace
102 78
103 // ArcPackageSyncableService::SyncItem 79 // ArcPackageSyncableService::SyncItem
104 ArcSyncItem::SyncItem(const std::string& package_name, 80 ArcSyncItem::SyncItem(const std::string& package_name,
105 int32_t package_version, 81 int32_t package_version,
106 int64_t last_backup_android_id, 82 int64_t last_backup_android_id,
107 int64_t last_backup_time) 83 int64_t last_backup_time)
108 : package_name(package_name), 84 : package_name(package_name),
109 package_version(package_version), 85 package_version(package_version),
110 last_backup_android_id(last_backup_android_id), 86 last_backup_android_id(last_backup_android_id),
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 223 }
248 } 224 }
249 225
250 return syncer::SyncError(); 226 return syncer::SyncError();
251 } 227 }
252 228
253 bool ArcPackageSyncableService::SyncStarted() { 229 bool ArcPackageSyncableService::SyncStarted() {
254 if (sync_processor_.get()) 230 if (sync_processor_.get())
255 return true; 231 return true;
256 232
257 sync_driver::SyncService* sync_service =
258 ProfileSyncServiceFactory::GetSyncServiceForBrowserContext(profile_);
259 // ArcPackage sync service is controlled by apps checkbox in sync settings.
260 bool arc_package_sync_should_enable =
261 ValidateEnableArcPackageSyncPref(profile_);
262
263 if (!sync_service || !arc_package_sync_should_enable)
264 return false;
265
266 sync_service->ReenableDatatype(syncer::ARC_PACKAGE);
267
268 if (flare_.is_null()) { 233 if (flare_.is_null()) {
269 VLOG(2) << this << ": SyncStarted: Flare."; 234 VLOG(2) << this << ": SyncStarted: Flare.";
270 flare_ = sync_start_util::GetFlareForSyncableService(profile_->GetPath()); 235 flare_ = sync_start_util::GetFlareForSyncableService(profile_->GetPath());
271 flare_.Run(syncer::ARC_PACKAGE); 236 flare_.Run(syncer::ARC_PACKAGE);
272 } 237 }
273 return false; 238 return false;
274 } 239 }
275 240
276 // ArcPackageSyncableService private 241 // ArcPackageSyncableService private
277 void ArcPackageSyncableService::OnPackageRemoved( 242 void ArcPackageSyncableService::OnPackageRemoved(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 436
472 bool ArcPackageSyncableService::ShouldSyncPackage( 437 bool ArcPackageSyncableService::ShouldSyncPackage(
473 const std::string& package_name) const { 438 const std::string& package_name) const {
474 std::unique_ptr<ArcAppListPrefs::PackageInfo> package( 439 std::unique_ptr<ArcAppListPrefs::PackageInfo> package(
475 prefs_->GetPackage(package_name)); 440 prefs_->GetPackage(package_name));
476 DCHECK(package.get()); 441 DCHECK(package.get());
477 return package->should_sync; 442 return package->should_sync;
478 } 443 }
479 444
480 } // namespace arc 445 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_package_sync_data_type_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698