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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 483883003: [Sync] Fix backup/rollback tests race conditions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
21 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
22 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 26 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/browsing_data/browsing_data_helper.h" 28 #include "chrome/browser/browsing_data/browsing_data_helper.h"
29 #include "chrome/browser/browsing_data/browsing_data_remover.h"
30 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
31 #include "chrome/browser/defaults.h" 30 #include "chrome/browser/defaults.h"
32 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" 31 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
33 #include "chrome/browser/net/chrome_cookie_notification_details.h" 32 #include "chrome/browser/net/chrome_cookie_notification_details.h"
34 #include "chrome/browser/password_manager/password_store_factory.h" 33 #include "chrome/browser/password_manager/password_store_factory.h"
35 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 34 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
36 #include "chrome/browser/prefs/pref_service_syncable.h" 35 #include "chrome/browser/prefs/pref_service_syncable.h"
37 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/services/gcm/gcm_profile_service.h" 37 #include "chrome/browser/services/gcm/gcm_profile_service.h"
39 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 38 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 }; 163 };
165 164
166 static const base::FilePath::CharType kSyncDataFolderName[] = 165 static const base::FilePath::CharType kSyncDataFolderName[] =
167 FILE_PATH_LITERAL("Sync Data"); 166 FILE_PATH_LITERAL("Sync Data");
168 167
169 static const base::FilePath::CharType kSyncBackupDataFolderName[] = 168 static const base::FilePath::CharType kSyncBackupDataFolderName[] =
170 FILE_PATH_LITERAL("Sync Data Backup"); 169 FILE_PATH_LITERAL("Sync Data Backup");
171 170
172 namespace { 171 namespace {
173 172
174 void ClearBrowsingData(Profile* profile, base::Time start, base::Time end) { 173 void ClearBrowsingData(BrowsingDataRemover::Observer* observer,
174 Profile* profile,
175 base::Time start,
176 base::Time end) {
175 // BrowsingDataRemover deletes itself when it's done. 177 // BrowsingDataRemover deletes itself when it's done.
176 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForRange( 178 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForRange(
177 profile, start, end); 179 profile, start, end);
180 if (observer)
181 remover->AddObserver(observer);
178 remover->Remove(BrowsingDataRemover::REMOVE_ALL, 182 remover->Remove(BrowsingDataRemover::REMOVE_ALL,
179 BrowsingDataHelper::ALL); 183 BrowsingDataHelper::ALL);
180 184
181 password_manager::PasswordStore* password = 185 password_manager::PasswordStore* password =
182 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); 186 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
183 password->RemoveLoginsSyncedBetween(start, end); 187 password->RemoveLoginsSyncedBetween(start, end);
184 } 188 }
185 189
186 } // anonymous namespace 190 } // anonymous namespace
187 191
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 signin_.get(), 240 signin_.get(),
237 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 241 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
238 startup_controller_weak_factory_.GetWeakPtr(), 242 startup_controller_weak_factory_.GetWeakPtr(),
239 BACKUP), 243 BACKUP),
240 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 244 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
241 startup_controller_weak_factory_.GetWeakPtr(), 245 startup_controller_weak_factory_.GetWeakPtr(),
242 ROLLBACK)), 246 ROLLBACK)),
243 backend_mode_(IDLE), 247 backend_mode_(IDLE),
244 need_backup_(false), 248 need_backup_(false),
245 backup_finished_(false), 249 backup_finished_(false),
246 clear_browsing_data_(base::Bind(&ClearBrowsingData)) { 250 clear_browsing_data_(base::Bind(&ClearBrowsingData)),
251 browsing_data_remover_observer_(NULL) {
247 DCHECK(profile); 252 DCHECK(profile);
248 syncer::SyncableService::StartSyncFlare flare( 253 syncer::SyncableService::StartSyncFlare flare(
249 sync_start_util::GetFlareForSyncableService(profile->GetPath())); 254 sync_start_util::GetFlareForSyncableService(profile->GetPath()));
250 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 255 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
251 new NotificationServiceSessionsRouter(profile, flare)); 256 new NotificationServiceSessionsRouter(profile, flare));
252 257
253 DCHECK(factory_.get()); 258 DCHECK(factory_.get());
254 local_device_ = factory_->CreateLocalDeviceInfoProvider(); 259 local_device_ = factory_->CreateLocalDeviceInfoProvider();
255 sessions_sync_manager_.reset( 260 sessions_sync_manager_.reset(
256 new SessionsSyncManager(profile, local_device_.get(), router.Pass())); 261 new SessionsSyncManager(profile, local_device_.get(), router.Pass()));
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 invalidator, 723 invalidator,
719 sync_prefs_.AsWeakPtr(), 724 sync_prefs_.AsWeakPtr(),
720 sync_folder)); 725 sync_folder));
721 726
722 // Initialize the backend. Every time we start up a new SyncBackendHost, 727 // Initialize the backend. Every time we start up a new SyncBackendHost,
723 // we'll want to start from a fresh SyncDB, so delete any old one that might 728 // we'll want to start from a fresh SyncDB, so delete any old one that might
724 // be there. 729 // be there.
725 InitializeBackend(ShouldDeleteSyncFolder()); 730 InitializeBackend(ShouldDeleteSyncFolder());
726 731
727 UpdateFirstSyncTimePref(); 732 UpdateFirstSyncTimePref();
733
734 NotifyObservers();
728 } 735 }
729 736
730 void ProfileSyncService::OnGetTokenSuccess( 737 void ProfileSyncService::OnGetTokenSuccess(
731 const OAuth2TokenService::Request* request, 738 const OAuth2TokenService::Request* request,
732 const std::string& access_token, 739 const std::string& access_token,
733 const base::Time& expiration_time) { 740 const base::Time& expiration_time) {
734 DCHECK_EQ(access_token_request_, request); 741 DCHECK_EQ(access_token_request_, request);
735 access_token_request_.reset(); 742 access_token_request_.reset();
736 access_token_ = access_token; 743 access_token_ = access_token;
737 token_receive_time_ = base::Time::Now(); 744 token_receive_time_ = base::Time::Now();
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 // Set if not set before and it's syncing now. 2670 // Set if not set before and it's syncing now.
2664 sync_prefs_.SetFirstSyncTime(base::Time::Now()); 2671 sync_prefs_.SetFirstSyncTime(base::Time::Now());
2665 } 2672 }
2666 } 2673 }
2667 2674
2668 void ProfileSyncService::ClearBrowsingDataSinceFirstSync() { 2675 void ProfileSyncService::ClearBrowsingDataSinceFirstSync() {
2669 base::Time first_sync_time = sync_prefs_.GetFirstSyncTime(); 2676 base::Time first_sync_time = sync_prefs_.GetFirstSyncTime();
2670 if (first_sync_time.is_null()) 2677 if (first_sync_time.is_null())
2671 return; 2678 return;
2672 2679
2673 clear_browsing_data_.Run(profile_, first_sync_time, base::Time::Now()); 2680 clear_browsing_data_.Run(browsing_data_remover_observer_,
2681 profile_,
2682 first_sync_time,
2683 base::Time::Now());
2684 }
2685
2686 void ProfileSyncService::SetBrowsingDataRemoverObserverForTesting(
2687 BrowsingDataRemover::Observer* observer) {
2688 browsing_data_remover_observer_ = observer;
2674 } 2689 }
2675 2690
2676 void ProfileSyncService::SetClearingBrowseringDataForTesting( 2691 void ProfileSyncService::SetClearingBrowseringDataForTesting(
2677 base::Callback<void(Profile*, base::Time, base::Time)> c) { 2692 base::Callback<void(BrowsingDataRemover::Observer* observer,
2693 Profile*,
2694 base::Time,
2695 base::Time)> c) {
2678 clear_browsing_data_ = c; 2696 clear_browsing_data_ = c;
2679 } 2697 }
2680 2698
2681 GURL ProfileSyncService::GetSyncServiceURL( 2699 GURL ProfileSyncService::GetSyncServiceURL(
2682 const base::CommandLine& command_line) { 2700 const base::CommandLine& command_line) {
2683 // By default, dev, canary, and unbranded Chromium users will go to the 2701 // By default, dev, canary, and unbranded Chromium users will go to the
2684 // development servers. Development servers have more features than standard 2702 // development servers. Development servers have more features than standard
2685 // sync servers. Users with officially-branded Chrome stable and beta builds 2703 // sync servers. Users with officially-branded Chrome stable and beta builds
2686 // will go to the standard sync servers. 2704 // will go to the standard sync servers.
2687 GURL result(kDevServerUrl); 2705 GURL result(kDevServerUrl);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 true)); 2785 true));
2768 } 2786 }
2769 2787
2770 bool ProfileSyncService::NeedBackup() const { 2788 bool ProfileSyncService::NeedBackup() const {
2771 return need_backup_; 2789 return need_backup_;
2772 } 2790 }
2773 2791
2774 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { 2792 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2775 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); 2793 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime();
2776 } 2794 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698