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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache.h

Issue 10698135: Revert 145933 - gdata: Remove sub_dir_type from CacheEntry for simplicity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/gdata_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // not evictable, hopefully. 73 // not evictable, hopefully.
74 CACHE_TYPE_TMP, // Files that don't meet criteria to be in 74 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
75 // persistent dir, and hence evictable. 75 // persistent dir, and hence evictable.
76 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files. 76 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
77 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents. 77 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
78 NUM_CACHE_TYPES, // This must be at the end. 78 NUM_CACHE_TYPES, // This must be at the end.
79 }; 79 };
80 80
81 // This is used as a bitmask for the cache state. 81 // This is used as a bitmask for the cache state.
82 enum CacheState { 82 enum CacheState {
83 CACHE_STATE_NONE = 0x0, 83 CACHE_STATE_NONE = 0x0,
84 CACHE_STATE_PINNED = 0x1 << 0, 84 CACHE_STATE_PINNED = 0x1 << 0,
85 CACHE_STATE_PRESENT = 0x1 << 1, 85 CACHE_STATE_PRESENT = 0x1 << 1,
86 CACHE_STATE_DIRTY = 0x1 << 2, 86 CACHE_STATE_DIRTY = 0x1 << 2,
87 CACHE_STATE_MOUNTED = 0x1 << 3, 87 CACHE_STATE_MOUNTED = 0x1 << 3,
88 CACHE_STATE_PERSISTENT = 0x1 << 4,
89 }; 88 };
90 89
91 // Enum defining origin of a cached file. 90 // Enum defining origin of a cached file.
92 enum CachedFileOrigin { 91 enum CachedFileOrigin {
93 CACHED_FILE_FROM_SERVER = 0, 92 CACHED_FILE_FROM_SERVER = 0,
94 CACHED_FILE_LOCALLY_MODIFIED, 93 CACHED_FILE_LOCALLY_MODIFIED,
95 CACHED_FILE_MOUNTED, 94 CACHED_FILE_MOUNTED,
96 }; 95 };
97 96
98 // Enum defining type of file operation e.g. copy or move, etc. 97 // Enum defining type of file operation e.g. copy or move, etc.
(...skipping 15 matching lines...) Expand all
114 113
115 // Triggered when a dirty file has been committed (saved) successfully. 114 // Triggered when a dirty file has been committed (saved) successfully.
116 virtual void OnCacheCommitted(const std::string& resource_id) {} 115 virtual void OnCacheCommitted(const std::string& resource_id) {}
117 116
118 protected: 117 protected:
119 virtual ~Observer() {} 118 virtual ~Observer() {}
120 }; 119 };
121 120
122 // Structure to store information of an existing cache file. 121 // Structure to store information of an existing cache file.
123 struct CacheEntry { 122 struct CacheEntry {
124 CacheEntry() : cache_state(0) {} 123 CacheEntry() : sub_dir_type(CACHE_TYPE_META),
124 cache_state(0) {}
125 125
126 CacheEntry(const std::string& md5, 126 CacheEntry(const std::string& md5,
127 CacheSubDirectoryType sub_dir_type,
127 int cache_state) 128 int cache_state)
128 : md5(md5), 129 : md5(md5),
130 sub_dir_type(sub_dir_type),
129 cache_state(cache_state) { 131 cache_state(cache_state) {
130 } 132 }
131 133
132 bool IsPresent() const { return IsCachePresent(cache_state); } 134 bool IsPresent() const { return IsCachePresent(cache_state); }
133 bool IsPinned() const { return IsCachePinned(cache_state); } 135 bool IsPinned() const { return IsCachePinned(cache_state); }
134 bool IsDirty() const { return IsCacheDirty(cache_state); } 136 bool IsDirty() const { return IsCacheDirty(cache_state); }
135 bool IsMounted() const { return IsCacheMounted(cache_state); } 137 bool IsMounted() const { return IsCacheMounted(cache_state); }
136 bool IsPersistent() const { return IsCachePersistent(cache_state); }
137
138 // Returns the type of the sub directory where the cache file is stored.
139 CacheSubDirectoryType GetSubDirectoryType() const {
140 return IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
141 }
142 138
143 // For debugging purposes. 139 // For debugging purposes.
144 std::string ToString() const; 140 std::string ToString() const;
145 141
146 std::string md5; 142 std::string md5;
143 CacheSubDirectoryType sub_dir_type;
147 int cache_state; 144 int cache_state;
148 }; 145 };
149 146
150 // Callback for GetCacheEntryOnUIThread. 147 // Callback for GetCacheEntryOnUIThread.
151 // |success| indicates if the operation was successful. 148 // |success| indicates if the operation was successful.
152 // |cache_entry| is the obtained cache entry. 149 // |cache_entry| is the obtained cache entry.
153 // 150 //
154 // TODO(satorux): Unlike other callback types, this has to be defined 151 // TODO(satorux): Unlike other callback types, this has to be defined
155 // inside GDataCache as CacheEntry is inside GDataCache. We should get them 152 // inside GDataCache as CacheEntry is inside GDataCache. We should get them
156 // outside of GDataCache. 153 // outside of GDataCache.
157 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)> 154 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)>
158 GetCacheEntryCallback; 155 GetCacheEntryCallback;
159 156
160 static bool IsCachePresent(int cache_state) { 157 static bool IsCachePresent(int cache_state) {
161 return cache_state & CACHE_STATE_PRESENT; 158 return cache_state & CACHE_STATE_PRESENT;
162 } 159 }
163 static bool IsCachePinned(int cache_state) { 160 static bool IsCachePinned(int cache_state) {
164 return cache_state & CACHE_STATE_PINNED; 161 return cache_state & CACHE_STATE_PINNED;
165 } 162 }
166 static bool IsCacheDirty(int cache_state) { 163 static bool IsCacheDirty(int cache_state) {
167 return cache_state & CACHE_STATE_DIRTY; 164 return cache_state & CACHE_STATE_DIRTY;
168 } 165 }
169 static bool IsCacheMounted(int cache_state) { 166 static bool IsCacheMounted(int cache_state) {
170 return cache_state & CACHE_STATE_MOUNTED; 167 return cache_state & CACHE_STATE_MOUNTED;
171 } 168 }
172 static bool IsCachePersistent(int cache_state) {
173 return cache_state & CACHE_STATE_PERSISTENT;
174 }
175 static int SetCachePresent(int cache_state) { 169 static int SetCachePresent(int cache_state) {
176 return cache_state |= CACHE_STATE_PRESENT; 170 return cache_state |= CACHE_STATE_PRESENT;
177 } 171 }
178 static int SetCachePinned(int cache_state) { 172 static int SetCachePinned(int cache_state) {
179 return cache_state |= CACHE_STATE_PINNED; 173 return cache_state |= CACHE_STATE_PINNED;
180 } 174 }
181 static int SetCacheDirty(int cache_state) { 175 static int SetCacheDirty(int cache_state) {
182 return cache_state |= CACHE_STATE_DIRTY; 176 return cache_state |= CACHE_STATE_DIRTY;
183 } 177 }
184 static int SetCacheMounted(int cache_state) { 178 static int SetCacheMounted(int cache_state) {
185 return cache_state |= CACHE_STATE_MOUNTED; 179 return cache_state |= CACHE_STATE_MOUNTED;
186 } 180 }
187 static int SetCachePersistent(int cache_state) {
188 return cache_state |= CACHE_STATE_PERSISTENT;
189 }
190 static int ClearCachePresent(int cache_state) { 181 static int ClearCachePresent(int cache_state) {
191 return cache_state &= ~CACHE_STATE_PRESENT; 182 return cache_state &= ~CACHE_STATE_PRESENT;
192 } 183 }
193 static int ClearCachePinned(int cache_state) { 184 static int ClearCachePinned(int cache_state) {
194 return cache_state &= ~CACHE_STATE_PINNED; 185 return cache_state &= ~CACHE_STATE_PINNED;
195 } 186 }
196 static int ClearCacheDirty(int cache_state) { 187 static int ClearCacheDirty(int cache_state) {
197 return cache_state &= ~CACHE_STATE_DIRTY; 188 return cache_state &= ~CACHE_STATE_DIRTY;
198 } 189 }
199 static int ClearCacheMounted(int cache_state) { 190 static int ClearCacheMounted(int cache_state) {
200 return cache_state &= ~CACHE_STATE_MOUNTED; 191 return cache_state &= ~CACHE_STATE_MOUNTED;
201 } 192 }
202 static int ClearCachePersistent(int cache_state) {
203 return cache_state &= ~CACHE_STATE_PERSISTENT;
204 }
205 193
206 // Returns the sub-directory under gdata cache directory for the given sub 194 // Returns the sub-directory under gdata cache directory for the given sub
207 // directory type. Example: <user_profile_dir>/GCache/v1/tmp 195 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
208 // 196 //
209 // Can be called on any thread. 197 // Can be called on any thread.
210 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const; 198 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
211 199
212 // Returns absolute path of the file if it were cached or to be cached. 200 // Returns absolute path of the file if it were cached or to be cached.
213 // 201 //
214 // Can be called on any thread. 202 // Can be called on any thread.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 const std::string& resource_id, 461 const std::string& resource_id,
474 const std::string& md5, 462 const std::string& md5,
475 const CacheOperationCallback& callback); 463 const CacheOperationCallback& callback);
476 464
477 // Helper function to implement GetCacheEntryOnUIThread(). 465 // Helper function to implement GetCacheEntryOnUIThread().
478 void GetCacheEntryHelper(const std::string& resource_id, 466 void GetCacheEntryHelper(const std::string& resource_id,
479 const std::string& md5, 467 const std::string& md5,
480 bool* success, 468 bool* success,
481 GDataCache::CacheEntry* cache_entry); 469 GDataCache::CacheEntry* cache_entry);
482 470
483 // Wrapper around GDataCacheMetadata::UpdateCache(). This function takes
484 // |sub_dir_type| and modifies |cache_state| per the sub directory type.
485 void UpdateCacheWithSubDirectoryType(const std::string& resource_id,
486 const std::string& md5,
487 CacheSubDirectoryType sub_dir_type,
488 int cache_state);
489
490 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). 471 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
491 const FilePath cache_root_path_; 472 const FilePath cache_root_path_;
492 // Paths for all subdirectories of GCache, one for each 473 // Paths for all subdirectories of GCache, one for each
493 // GDataCache::CacheSubDirectoryType enum. 474 // GDataCache::CacheSubDirectoryType enum.
494 const std::vector<FilePath> cache_paths_; 475 const std::vector<FilePath> cache_paths_;
495 base::SequencedWorkerPool* pool_; 476 base::SequencedWorkerPool* pool_;
496 const base::SequencedWorkerPool::SequenceToken sequence_token_; 477 const base::SequencedWorkerPool::SequenceToken sequence_token_;
497 478
498 // The cache state data. This member must be access only on the blocking pool. 479 // The cache state data. This member must be access only on the blocking pool.
499 scoped_ptr<GDataCacheMetadata> metadata_; 480 scoped_ptr<GDataCacheMetadata> metadata_;
(...skipping 25 matching lines...) Expand all
525 }; 506 };
526 507
527 // Sets the free disk space getter for testing. 508 // Sets the free disk space getter for testing.
528 // The existing getter is deleted. 509 // The existing getter is deleted.
529 void SetFreeDiskSpaceGetterForTesting( 510 void SetFreeDiskSpaceGetterForTesting(
530 FreeDiskSpaceGetterInterface* getter); 511 FreeDiskSpaceGetterInterface* getter);
531 512
532 } // namespace gdata 513 } // namespace gdata
533 514
534 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ 515 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/gdata_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698