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

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

Issue 10690028: gdata: Get rid of GDataFileSystem::GetCacheState() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 }; 115 };
116 116
117 // Structure to store information of an existing cache file. 117 // Structure to store information of an existing cache file.
118 struct CacheEntry { 118 struct CacheEntry {
119 CacheEntry() : sub_dir_type(CACHE_TYPE_META), 119 CacheEntry() : sub_dir_type(CACHE_TYPE_META),
120 cache_state(0) {} 120 cache_state(0) {}
121 121
122 CacheEntry(const std::string& md5, 122 CacheEntry(const std::string& md5,
123 CacheSubDirectoryType sub_dir_type, 123 CacheSubDirectoryType sub_dir_type,
124 int cache_state) 124 int cache_state)
125 : md5(md5), 125 : md5(md5),
126 sub_dir_type(sub_dir_type), 126 sub_dir_type(sub_dir_type),
127 cache_state(cache_state) { 127 cache_state(cache_state) {
128 } 128 }
129 129
130 bool IsPresent() const { return IsCachePresent(cache_state); } 130 bool IsPresent() const { return IsCachePresent(cache_state); }
131 bool IsPinned() const { return IsCachePinned(cache_state); } 131 bool IsPinned() const { return IsCachePinned(cache_state); }
132 bool IsDirty() const { return IsCacheDirty(cache_state); } 132 bool IsDirty() const { return IsCacheDirty(cache_state); }
133 bool IsMounted() const { return IsCacheMounted(cache_state); } 133 bool IsMounted() const { return IsCacheMounted(cache_state); }
134 134
135 // For debugging purposes. 135 // For debugging purposes.
136 std::string ToString() const; 136 std::string ToString() const;
137 137
138 std::string md5; 138 std::string md5;
139 CacheSubDirectoryType sub_dir_type; 139 CacheSubDirectoryType sub_dir_type;
140 int cache_state; 140 int cache_state;
141 }; 141 };
142 142
143 // Callback for GetCacheEntryOnUIThread.
144 // |success| indicates if the operation was successful.
145 // |cache_entry| is the obtained cache entry.
146 //
147 // TODO(satorux): Unlike other callback types, this has to be defined
148 // inside GDataCache as CacheEntry is inside GDataCache. We should get them
149 // outside of GDataCache.
hshi1 2012/06/28 22:11:21 Maybe gdata_params.h is a good place to define cal
satorux1 2012/06/28 22:41:17 Well, I plan to get rid of gdata_params.h. Callbac
150 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)>
151 GetCacheEntryCallback;
152
143 static bool IsCachePresent(int cache_state) { 153 static bool IsCachePresent(int cache_state) {
144 return cache_state & CACHE_STATE_PRESENT; 154 return cache_state & CACHE_STATE_PRESENT;
145 } 155 }
146 static bool IsCachePinned(int cache_state) { 156 static bool IsCachePinned(int cache_state) {
147 return cache_state & CACHE_STATE_PINNED; 157 return cache_state & CACHE_STATE_PINNED;
148 } 158 }
149 static bool IsCacheDirty(int cache_state) { 159 static bool IsCacheDirty(int cache_state) {
150 return cache_state & CACHE_STATE_DIRTY; 160 return cache_state & CACHE_STATE_DIRTY;
151 } 161 }
152 static bool IsCacheMounted(int cache_state) { 162 static bool IsCacheMounted(int cache_state) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool IsUnderGDataCacheDirectory(const FilePath& path) const; 208 bool IsUnderGDataCacheDirectory(const FilePath& path) const;
199 209
200 // Adds observer. 210 // Adds observer.
201 // Must be called on UI thread. 211 // Must be called on UI thread.
202 void AddObserver(Observer* observer); 212 void AddObserver(Observer* observer);
203 213
204 // Removes observer. 214 // Removes observer.
205 // Must be called on UI thread. 215 // Must be called on UI thread.
206 void RemoveObserver(Observer* observer); 216 void RemoveObserver(Observer* observer);
207 217
218 // Gets the cache entry by the given resource ID and MD5.
219 // See also GetCacheEntry().
220 //
221 // Must be called on UI thread. |callback| is run on UI thread.
222 void GetCacheEntryOnUIThread(
223 const std::string& resource_id,
224 const std::string& md5,
225 const GetCacheEntryCallback& callback);
226
208 // Gets the resource IDs of pinned-but-not-fetched files and 227 // Gets the resource IDs of pinned-but-not-fetched files and
209 // dirty-but-not-uploaded files. 228 // dirty-but-not-uploaded files.
210 // 229 //
211 // Must be called on UI thread. |callback| is run on UI thread. 230 // Must be called on UI thread. |callback| is run on UI thread.
212 void GetResourceIdsOfBacklogOnUIThread( 231 void GetResourceIdsOfBacklogOnUIThread(
213 const GetResourceIdsCallback& callback); 232 const GetResourceIdsCallback& callback);
214 233
215 // Frees up disk space to store the given number of bytes, while keeping 234 // Frees up disk space to store the given number of bytes, while keeping
216 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is 235 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is
217 // updated to indicate if we have enough space. 236 // updated to indicate if we have enough space.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 const std::string& resource_id, 430 const std::string& resource_id,
412 const std::string& md5, 431 const std::string& md5,
413 const CacheOperationCallback& callback); 432 const CacheOperationCallback& callback);
414 433
415 // Runs callback and notifies the observers when file is committed. 434 // Runs callback and notifies the observers when file is committed.
416 void OnCommitDirty(base::PlatformFileError* error, 435 void OnCommitDirty(base::PlatformFileError* error,
417 const std::string& resource_id, 436 const std::string& resource_id,
418 const std::string& md5, 437 const std::string& md5,
419 const CacheOperationCallback& callback); 438 const CacheOperationCallback& callback);
420 439
440 // Helper function to implement GetCacheEntryOnUIThread().
441 void GetCacheEntryHelper(const std::string& resource_id,
442 const std::string& md5,
443 bool* success,
444 GDataCache::CacheEntry* cache_entry);
445
421 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). 446 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
422 const FilePath cache_root_path_; 447 const FilePath cache_root_path_;
423 // Paths for all subdirectories of GCache, one for each 448 // Paths for all subdirectories of GCache, one for each
424 // GDataCache::CacheSubDirectoryType enum. 449 // GDataCache::CacheSubDirectoryType enum.
425 const std::vector<FilePath> cache_paths_; 450 const std::vector<FilePath> cache_paths_;
426 base::SequencedWorkerPool* pool_; 451 base::SequencedWorkerPool* pool_;
427 const base::SequencedWorkerPool::SequenceToken sequence_token_; 452 const base::SequencedWorkerPool::SequenceToken sequence_token_;
428 453
429 // The cache state data. This member must be access only on the blocking pool. 454 // The cache state data. This member must be access only on the blocking pool.
430 scoped_ptr<GDataCacheMetadata> metadata_; 455 scoped_ptr<GDataCacheMetadata> metadata_;
(...skipping 25 matching lines...) Expand all
456 }; 481 };
457 482
458 // Sets the free disk space getter for testing. 483 // Sets the free disk space getter for testing.
459 // The existing getter is deleted. 484 // The existing getter is deleted.
460 void SetFreeDiskSpaceGetterForTesting( 485 void SetFreeDiskSpaceGetterForTesting(
461 FreeDiskSpaceGetterInterface* getter); 486 FreeDiskSpaceGetterInterface* getter);
462 487
463 } // namespace gdata 488 } // namespace gdata
464 489
465 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ 490 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698