local_file_sync_context.h revision 2385ea399aae016c0806a4f9ef3c9cfe3d2a39df
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Copyright 2013 The Chromium Authors. All rights reserved. 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Use of this source code is governed by a BSD-style license that can be 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// found in the LICENSE file. 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner#define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <deque> 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <map> 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <set> 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <string> 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/basictypes.h" 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/callback.h" 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/files/file_path.h" 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/logging.h" 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "base/memory/ref_counted.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/memory/scoped_ptr.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "base/memory/weak_ptr.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "base/observer_list.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "base/timer/timer.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "chrome/browser/sync_file_system/local/local_file_sync_status.h" 2371a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "chrome/browser/sync_file_system/sync_callbacks.h" 24409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "chrome/browser/sync_file_system/sync_status_code.h" 25f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "url/gurl.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattnernamespace base { 283b8d116703db8018f855cbb4733ace426422623bNate Begemanclass SingleThreadTaskRunner; 29b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar} 30403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace fileapi { 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileSystemContext; 33590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnerclass FileSystemURL; 34c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson} 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbarnamespace sync_file_system { 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar 388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregorclass FileChange; 39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbarclass LocalFileChangeTracker; 4056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffstruct LocalFileSyncInfo; 41409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlssonclass LocalOriginChangeObserver; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass SyncableFileOperationRunner; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 44f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall// This class works as a bridge between LocalFileSyncService (which is a 4556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall// per-profile object) and FileSystemContext's (which is a per-storage-partition 4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor// object and may exist multiple in a profile). 477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson// An instance of this class is shared by FileSystemContexts and outlives 48686775deca8b8685eb90801495880e3abdd844c2Chris Lattner// LocalFileSyncService. 497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlssonclass LocalFileSyncContext 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public base::RefCountedThreadSafe<LocalFileSyncContext>, 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer public LocalFileSyncStatus::Observer { 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer public: 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef base::Callback<void( 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SyncStatusCode status, const LocalFileSyncInfo& sync_file_info)> 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LocalFileSyncInfoCallback; 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall typedef base::Callback<void(SyncStatusCode status, 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool has_pending_changes)> 59561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor HasPendingLocalChangeCallback; 60561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 61561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, 628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall base::SingleThreadTaskRunner* io_task_runner); 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 64561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // Initializes |file_system_context| for syncable file operations 65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // and registers the it into the internal map. 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // Calling this multiple times for the same file_system_context is valid. 67bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // This method must be called on UI thread. 68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void MaybeInitializeFileSystemContext( 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor const GURL& source_url, 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fileapi::FileSystemContext* file_system_context, 710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor const SyncStatusCallback& callback); 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // Called when the corresponding LocalFileSyncService exits. 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // This method must be called on UI thread. 75f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor void ShutdownOnUIThread(); 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // Picks a file for next local sync and returns it after disabling writes 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // for the file. 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // This method must be called on UI thread. 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor void GetFileForLocalSync(fileapi::FileSystemContext* file_system_context, 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor const LocalFileSyncInfoCallback& callback); 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // Clears all pending local changes for |url|. |done_callback| is called 84905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor // when the changes are cleared. 858320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar // This method must be called on UI thread. 86f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor void ClearChangesForURL(fileapi::FileSystemContext* file_system_context, 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const fileapi::FileSystemURL& url, 889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor const base::Closure& done_callback); 8977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A local or remote sync has been finished (either successfully or 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // with an error). Clears the internal sync flag and enable writing for |url|. 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // This method must be called on UI thread. 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ClearSyncFlagForURL(const fileapi::FileSystemURL& url); 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Prepares for sync |url| by disabling writes on |url|. 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // If the target |url| is being written and cannot start sync it 978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall // returns SYNC_STATUS_WRITING status code via |callback|. 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Otherwise it disables writes, marks the |url| syncing and returns 990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // the current change set made on |url|. 100561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // This method must be called on UI thread. 101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void PrepareForSync(fileapi::FileSystemContext* file_system_context, 102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const fileapi::FileSystemURL& url, 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const LocalFileSyncInfoCallback& callback); 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // Registers |url| to wait until sync is enabled for |url|. 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // |on_syncable_callback| is to be called when |url| becomes syncable 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // (i.e. when we have no pending writes and the file is successfully locked 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // for sync). 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Calling this method again while this already has another URL waiting 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // for sync will overwrite the previously registered URL. 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // This method must be called on UI thread. 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void RegisterURLForWaitingSync(const fileapi::FileSystemURL& url, 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor const base::Closure& on_syncable_callback); 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall // Applies a remote change. 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // This method must be called on UI thread. 1190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void ApplyRemoteChange( 120561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fileapi::FileSystemContext* file_system_context, 121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const FileChange& change, 122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const base::FilePath& local_path, 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const fileapi::FileSystemURL& url, 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const SyncStatusCallback& callback); 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // Records a fake local change in the local change tracker. 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void RecordFakeLocalChange( 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fileapi::FileSystemContext* file_system_context, 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const fileapi::FileSystemURL& url, 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const FileChange& change, 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const SyncStatusCallback& callback); 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // This must be called on UI thread. 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void GetFileMetadata( 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fileapi::FileSystemContext* file_system_context, 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const fileapi::FileSystemURL& url, 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const SyncFileMetadataCallback& callback); 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // Returns true via |callback| if the given file |url| has local pending 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // changes. 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void HasPendingLocalChanges( 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fileapi::FileSystemContext* file_system_context, 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const fileapi::FileSystemURL& url, 144561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor const HasPendingLocalChangeCallback& callback); 145561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // They must be called on UI thread. 147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void AddOriginChangeObserver(LocalOriginChangeObserver* observer); 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void RemoveOriginChangeObserver(LocalOriginChangeObserver* observer); 149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // OperationRunner is accessible only on IO thread. 1510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor base::WeakPtr<SyncableFileOperationRunner> operation_runner() const; 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor // SyncContext is accessible only on IO thread. 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor LocalFileSyncStatus* sync_status() const; 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor // For testing; override the duration to notify changes from the 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor // default value. 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor void set_mock_notify_changes_duration_in_sec(int duration) { 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor mock_notify_changes_duration_in_sec_ = duration; 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor protected: 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor // LocalFileSyncStatus::Observer overrides. They are called on IO thread. 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor virtual void OnSyncEnabled(const fileapi::FileSystemURL& url) OVERRIDE; 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor virtual void OnWriteEnabled(const fileapi::FileSystemURL& url) OVERRIDE; 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor private: 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor typedef base::Callback<void(base::PlatformFileError result)> StatusCallback; 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor typedef std::deque<SyncStatusCallback> StatusCallbackQueue; 170bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class base::RefCountedThreadSafe<LocalFileSyncContext>; 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor friend class CannedSyncableFileSystem; 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor virtual ~LocalFileSyncContext(); 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void ShutdownOnIOThread(); 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Starts a timer to eventually call NotifyAvailableChangesOnIOThread. 17863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall // The caller is expected to update origins_with_pending_changes_ before 1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // calling this. 180026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner void ScheduleNotifyChangesUpdatedOnIOThread(); 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // Called by the internal timer on IO thread to notify changes to UI thread. 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner void NotifyAvailableChangesOnIOThread(); 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 185df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump // Called from NotifyAvailableChangesOnIOThread. 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void NotifyAvailableChanges(const std::set<GURL>& origins); 1877eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall // Helper routines for MaybeInitializeFileSystemContext. 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall void InitializeFileSystemContextOnIOThread( 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall const GURL& source_url, 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall fileapi::FileSystemContext* file_system_context); 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall SyncStatusCode InitializeChangeTrackerOnFileThread( 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer scoped_ptr<LocalFileChangeTracker>* tracker_ptr, 1947eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall fileapi::FileSystemContext* file_system_context, 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall std::set<GURL>* origins_with_changes); 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall void DidInitializeChangeTrackerOnIOThread( 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall scoped_ptr<LocalFileChangeTracker>* tracker_ptr, 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall const GURL& source_url, 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall fileapi::FileSystemContext* file_system_context, 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall std::set<GURL>* origins_with_changes, 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall SyncStatusCode status); 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall void DidInitialize( 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall const GURL& source_url, 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall fileapi::FileSystemContext* file_system_context, 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall SyncStatusCode status); 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helper routines for GetFileForLocalSync. 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void GetNextURLsForSyncOnFileThread( 209fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff fileapi::FileSystemContext* file_system_context, 21086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor std::deque<fileapi::FileSystemURL>* urls); 211077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian void TryPrepareForLocalSync( 2122514a309204341798f96912ce7a90841bea59727Fariborz Jahanian fileapi::FileSystemContext* file_system_context, 213e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian std::deque<fileapi::FileSystemURL>* urls, 214e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor const LocalFileSyncInfoCallback& callback); 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void DidTryPrepareForLocalSync( 2167eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall fileapi::FileSystemContext* file_system_context, 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall std::deque<fileapi::FileSystemURL>* remaining_urls, 21853202857c60214d80950a975e6e52aebf30bd16aEli Friedman const LocalFileSyncInfoCallback& callback, 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SyncStatusCode status, 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LocalFileSyncInfo& sync_file_info); 2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Callback routine for PrepareForSync and GetFileForLocalSync. 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void DidGetWritingStatusForSync( 22444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar fileapi::FileSystemContext* file_system_context, 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SyncStatusCode status, 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar const fileapi::FileSystemURL& url, 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar const LocalFileSyncInfoCallback& callback); 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helper routine for ClearSyncFlagForURL. 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnableWritingOnIOThread(const fileapi::FileSystemURL& url); 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 232fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff void DidRemoveExistingEntryForApplyRemoteChange( 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer fileapi::FileSystemContext* file_system_context, 234ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner const FileChange& change, 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const base::FilePath& local_path, 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const fileapi::FileSystemURL& url, 2374f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff const SyncStatusCallback& callback, 2385daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian base::PlatformFileError error); 239ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian 24086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // Callback routine for ApplyRemoteChange. 2412514a309204341798f96912ce7a90841bea59727Fariborz Jahanian void DidApplyRemoteChange( 242e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian const fileapi::FileSystemURL& url, 243077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian const SyncStatusCallback& callback_on_ui, 244e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor base::PlatformFileError file_error); 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar void DidGetFileMetadata( 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar const SyncFileMetadataCallback& callback, 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump base::PlatformFileError file_error, 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl const base::PlatformFileInfo& file_info); 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl base::TimeDelta NotifyChangesDuration(); 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl void DidCreateDirectoryForCopyIn( 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl fileapi::FileSystemContext* file_system_context, 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl const base::FilePath& local_file_path, 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl const fileapi::FileSystemURL& dest_url, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl const StatusCallback& callback, 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl base::PlatformFileError error); 2591c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Indicates if the sync service is shutdown on UI thread. 264077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian bool shutdown_on_ui_; 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // OperationRunner. This must be accessed only on IO thread. 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl scoped_ptr<SyncableFileOperationRunner> operation_runner_; 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Keeps track of writing/syncing status. 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // This must be accessed only on IO thread. 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl scoped_ptr<LocalFileSyncStatus> sync_status_; 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Pointers to file system contexts that have been initialized for 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // synchronization (i.e. that own this instance). 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // This must be accessed only on UI thread. 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl std::set<fileapi::FileSystemContext*> file_system_contexts_; 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Accessed only on UI thread. 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl std::map<fileapi::FileSystemContext*, StatusCallbackQueue> 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl pending_initialize_callbacks_; 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // A URL and associated callback waiting for sync is enabled. 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Accessed only on IO thread. 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl fileapi::FileSystemURL url_waiting_sync_on_io_; 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl base::Closure url_syncable_callback_; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl // Used only on IO thread for available changes notifications. 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl base::Time last_notified_changes_; 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl scoped_ptr<base::OneShotTimer<LocalFileSyncContext> > timer_on_io_; 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl std::set<GURL> origins_with_pending_changes_; 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ObserverList<LocalOriginChangeObserver> origin_change_observers_; 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl int mock_notify_changes_duration_in_sec_; 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl}; 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl} // namespace sync_file_system 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl