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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_status.h

Issue 2129083002: Explicitly check various sync_file_system classes live on the IO thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests, remove unneeded check Created 4 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_ 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <utility>
12 13
13 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/threading/non_thread_safe.h"
18 #include "storage/browser/fileapi/file_system_url.h" 18 #include "storage/browser/fileapi/file_system_url.h"
19 19
20 namespace storage { 20 namespace storage {
21 class FileSystemURL; 21 class FileSystemURL;
22 } 22 }
23 23
24 namespace sync_file_system { 24 namespace sync_file_system {
25 25
26 // Represents local file sync status. 26 // Represents local file sync status.
27 // This class is supposed to run only on IO thread. 27 // This class is supposed to run only on IO thread.
28 // 28 //
29 // This class manages two important synchronization flags: writing (counter) 29 // This class manages two important synchronization flags: writing (counter)
30 // and syncing (flag). Writing counter keeps track of which URL is in 30 // and syncing (flag). Writing counter keeps track of which URL is in
31 // writing and syncing flag indicates which URL is in syncing. 31 // writing and syncing flag indicates which URL is in syncing.
32 // 32 //
33 // An entry can have multiple writers but sync is exclusive and cannot overwrap 33 // An entry can have multiple writers but sync is exclusive and cannot overwrap
34 // with any writes or syncs. 34 // with any writes or syncs.
35 class LocalFileSyncStatus 35 class LocalFileSyncStatus {
36 : public base::NonThreadSafe {
37 public: 36 public:
38 typedef std::pair<GURL, storage::FileSystemType> OriginAndType; 37 using OriginAndType = std::pair<GURL, storage::FileSystemType>;
39 38
40 class Observer { 39 class Observer {
41 public: 40 public:
42 Observer() {} 41 Observer() {}
43 virtual ~Observer() {} 42 virtual ~Observer() {}
44 virtual void OnSyncEnabled(const storage::FileSystemURL& url) = 0; 43 virtual void OnSyncEnabled(const storage::FileSystemURL& url) = 0;
45 virtual void OnWriteEnabled(const storage::FileSystemURL& url) = 0; 44 virtual void OnWriteEnabled(const storage::FileSystemURL& url) = 0;
46 45
47 private: 46 private:
48 DISALLOW_COPY_AND_ASSIGN(Observer); 47 DISALLOW_COPY_AND_ASSIGN(Observer);
(...skipping 26 matching lines...) Expand all
75 // syncing nor writing). 74 // syncing nor writing).
76 bool IsSyncable(const storage::FileSystemURL& url) const; 75 bool IsSyncable(const storage::FileSystemURL& url) const;
77 76
78 void AddObserver(Observer* observer); 77 void AddObserver(Observer* observer);
79 void RemoveObserver(Observer* observer); 78 void RemoveObserver(Observer* observer);
80 79
81 private: 80 private:
82 FRIEND_TEST_ALL_PREFIXES(LocalFileSyncStatusTest, WritingOnPathsWithPeriod); 81 FRIEND_TEST_ALL_PREFIXES(LocalFileSyncStatusTest, WritingOnPathsWithPeriod);
83 FRIEND_TEST_ALL_PREFIXES(LocalFileSyncStatusTest, SyncingOnPathsWithPeriod); 82 FRIEND_TEST_ALL_PREFIXES(LocalFileSyncStatusTest, SyncingOnPathsWithPeriod);
84 83
85 typedef std::set<base::FilePath> PathSet; 84 using PathSet = std::set<base::FilePath>;
86 typedef std::map<OriginAndType, PathSet> URLSet; 85 using URLSet = std::map<OriginAndType, PathSet>;
87 86
88 typedef std::map<base::FilePath, int64_t> PathBucket; 87 using PathBucket = std::map<base::FilePath, int64_t>;
89 typedef std::map<OriginAndType, PathBucket> URLBucket; 88 using URLBucket = std::map<OriginAndType, PathBucket>;
90 89
91 bool IsChildOrParentWriting(const storage::FileSystemURL& url) const; 90 bool IsChildOrParentWriting(const storage::FileSystemURL& url) const;
92 bool IsChildOrParentSyncing(const storage::FileSystemURL& url) const; 91 bool IsChildOrParentSyncing(const storage::FileSystemURL& url) const;
93 92
94 // If this count is non-zero positive there're ongoing write operations. 93 // If this count is non-zero, then there are ongoing write operations.
95 URLBucket writing_; 94 URLBucket writing_;
96 95
97 // If this flag is set sync process is running on the file. 96 // If this flag is set sync process is running on the file.
98 URLSet syncing_; 97 URLSet syncing_;
99 98
100 base::ObserverList<Observer> observer_list_; 99 base::ObserverList<Observer> observer_list_;
101 100
102 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncStatus); 101 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncStatus);
103 }; 102 };
104 103
105 } // namespace sync_file_system 104 } // namespace sync_file_system
106 105
107 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_ 106 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_STATUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698