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

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

Issue 10702133: gdata: Remove sub_dir_type from CacheEntry for simplicity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: the fix 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,
88 }; 89 };
89 90
90 // Enum defining origin of a cached file. 91 // Enum defining origin of a cached file.
91 enum CachedFileOrigin { 92 enum CachedFileOrigin {
92 CACHED_FILE_FROM_SERVER = 0, 93 CACHED_FILE_FROM_SERVER = 0,
93 CACHED_FILE_LOCALLY_MODIFIED, 94 CACHED_FILE_LOCALLY_MODIFIED,
94 CACHED_FILE_MOUNTED, 95 CACHED_FILE_MOUNTED,
95 }; 96 };
96 97
97 // Enum defining type of file operation e.g. copy or move, etc. 98 // Enum defining type of file operation e.g. copy or move, etc.
(...skipping 15 matching lines...) Expand all
113 114
114 // Triggered when a dirty file has been committed (saved) successfully. 115 // Triggered when a dirty file has been committed (saved) successfully.
115 virtual void OnCacheCommitted(const std::string& resource_id) {} 116 virtual void OnCacheCommitted(const std::string& resource_id) {}
116 117
117 protected: 118 protected:
118 virtual ~Observer() {} 119 virtual ~Observer() {}
119 }; 120 };
120 121
121 // Structure to store information of an existing cache file. 122 // Structure to store information of an existing cache file.
122 struct CacheEntry { 123 struct CacheEntry {
123 CacheEntry() : sub_dir_type(CACHE_TYPE_META), 124 CacheEntry() : cache_state(0) {}
124 cache_state(0) {}
125 125
126 CacheEntry(const std::string& md5, 126 CacheEntry(const std::string& md5,
127 CacheSubDirectoryType sub_dir_type,
128 int cache_state) 127 int cache_state)
129 : md5(md5), 128 : md5(md5),
130 sub_dir_type(sub_dir_type),
131 cache_state(cache_state) { 129 cache_state(cache_state) {
132 } 130 }
133 131
134 bool IsPresent() const { return IsCachePresent(cache_state); } 132 bool IsPresent() const { return IsCachePresent(cache_state); }
135 bool IsPinned() const { return IsCachePinned(cache_state); } 133 bool IsPinned() const { return IsCachePinned(cache_state); }
136 bool IsDirty() const { return IsCacheDirty(cache_state); } 134 bool IsDirty() const { return IsCacheDirty(cache_state); }
137 bool IsMounted() const { return IsCacheMounted(cache_state); } 135 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 }
138 142
139 // For debugging purposes. 143 // For debugging purposes.
140 std::string ToString() const; 144 std::string ToString() const;
141 145
142 std::string md5; 146 std::string md5;
143 CacheSubDirectoryType sub_dir_type;
144 int cache_state; 147 int cache_state;
145 }; 148 };
146 149
147 // Callback for GetCacheEntryOnUIThread. 150 // Callback for GetCacheEntryOnUIThread.
148 // |success| indicates if the operation was successful. 151 // |success| indicates if the operation was successful.
149 // |cache_entry| is the obtained cache entry. 152 // |cache_entry| is the obtained cache entry.
150 // 153 //
151 // TODO(satorux): Unlike other callback types, this has to be defined 154 // TODO(satorux): Unlike other callback types, this has to be defined
152 // inside GDataCache as CacheEntry is inside GDataCache. We should get them 155 // inside GDataCache as CacheEntry is inside GDataCache. We should get them
153 // outside of GDataCache. 156 // outside of GDataCache.
154 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)> 157 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)>
155 GetCacheEntryCallback; 158 GetCacheEntryCallback;
156 159
157 static bool IsCachePresent(int cache_state) { 160 static bool IsCachePresent(int cache_state) {
158 return cache_state & CACHE_STATE_PRESENT; 161 return cache_state & CACHE_STATE_PRESENT;
159 } 162 }
160 static bool IsCachePinned(int cache_state) { 163 static bool IsCachePinned(int cache_state) {
161 return cache_state & CACHE_STATE_PINNED; 164 return cache_state & CACHE_STATE_PINNED;
162 } 165 }
163 static bool IsCacheDirty(int cache_state) { 166 static bool IsCacheDirty(int cache_state) {
164 return cache_state & CACHE_STATE_DIRTY; 167 return cache_state & CACHE_STATE_DIRTY;
165 } 168 }
166 static bool IsCacheMounted(int cache_state) { 169 static bool IsCacheMounted(int cache_state) {
167 return cache_state & CACHE_STATE_MOUNTED; 170 return cache_state & CACHE_STATE_MOUNTED;
168 } 171 }
172 static bool IsCachePersistent(int cache_state) {
173 return cache_state & CACHE_STATE_PERSISTENT;
174 }
169 static int SetCachePresent(int cache_state) { 175 static int SetCachePresent(int cache_state) {
170 return cache_state |= CACHE_STATE_PRESENT; 176 return cache_state |= CACHE_STATE_PRESENT;
171 } 177 }
172 static int SetCachePinned(int cache_state) { 178 static int SetCachePinned(int cache_state) {
173 return cache_state |= CACHE_STATE_PINNED; 179 return cache_state |= CACHE_STATE_PINNED;
174 } 180 }
175 static int SetCacheDirty(int cache_state) { 181 static int SetCacheDirty(int cache_state) {
176 return cache_state |= CACHE_STATE_DIRTY; 182 return cache_state |= CACHE_STATE_DIRTY;
177 } 183 }
178 static int SetCacheMounted(int cache_state) { 184 static int SetCacheMounted(int cache_state) {
179 return cache_state |= CACHE_STATE_MOUNTED; 185 return cache_state |= CACHE_STATE_MOUNTED;
180 } 186 }
187 static int SetCachePersistent(int cache_state) {
188 return cache_state |= CACHE_STATE_PERSISTENT;
189 }
181 static int ClearCachePresent(int cache_state) { 190 static int ClearCachePresent(int cache_state) {
182 return cache_state &= ~CACHE_STATE_PRESENT; 191 return cache_state &= ~CACHE_STATE_PRESENT;
183 } 192 }
184 static int ClearCachePinned(int cache_state) { 193 static int ClearCachePinned(int cache_state) {
185 return cache_state &= ~CACHE_STATE_PINNED; 194 return cache_state &= ~CACHE_STATE_PINNED;
186 } 195 }
187 static int ClearCacheDirty(int cache_state) { 196 static int ClearCacheDirty(int cache_state) {
188 return cache_state &= ~CACHE_STATE_DIRTY; 197 return cache_state &= ~CACHE_STATE_DIRTY;
189 } 198 }
190 static int ClearCacheMounted(int cache_state) { 199 static int ClearCacheMounted(int cache_state) {
191 return cache_state &= ~CACHE_STATE_MOUNTED; 200 return cache_state &= ~CACHE_STATE_MOUNTED;
192 } 201 }
202 static int ClearCachePersistent(int cache_state) {
203 return cache_state &= ~CACHE_STATE_PERSISTENT;
204 }
193 205
194 // Returns the sub-directory under gdata cache directory for the given sub 206 // Returns the sub-directory under gdata cache directory for the given sub
195 // directory type. Example: <user_profile_dir>/GCache/v1/tmp 207 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
196 // 208 //
197 // Can be called on any thread. 209 // Can be called on any thread.
198 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const; 210 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
199 211
200 // Returns absolute path of the file if it were cached or to be cached. 212 // Returns absolute path of the file if it were cached or to be cached.
201 // 213 //
202 // Can be called on any thread. 214 // Can be called on any thread.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 const std::string& resource_id, 473 const std::string& resource_id,
462 const std::string& md5, 474 const std::string& md5,
463 const CacheOperationCallback& callback); 475 const CacheOperationCallback& callback);
464 476
465 // Helper function to implement GetCacheEntryOnUIThread(). 477 // Helper function to implement GetCacheEntryOnUIThread().
466 void GetCacheEntryHelper(const std::string& resource_id, 478 void GetCacheEntryHelper(const std::string& resource_id,
467 const std::string& md5, 479 const std::string& md5,
468 bool* success, 480 bool* success,
469 GDataCache::CacheEntry* cache_entry); 481 GDataCache::CacheEntry* cache_entry);
470 482
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
471 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). 490 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
472 const FilePath cache_root_path_; 491 const FilePath cache_root_path_;
473 // Paths for all subdirectories of GCache, one for each 492 // Paths for all subdirectories of GCache, one for each
474 // GDataCache::CacheSubDirectoryType enum. 493 // GDataCache::CacheSubDirectoryType enum.
475 const std::vector<FilePath> cache_paths_; 494 const std::vector<FilePath> cache_paths_;
476 base::SequencedWorkerPool* pool_; 495 base::SequencedWorkerPool* pool_;
477 const base::SequencedWorkerPool::SequenceToken sequence_token_; 496 const base::SequencedWorkerPool::SequenceToken sequence_token_;
478 497
479 // The cache state data. This member must be access only on the blocking pool. 498 // The cache state data. This member must be access only on the blocking pool.
480 scoped_ptr<GDataCacheMetadata> metadata_; 499 scoped_ptr<GDataCacheMetadata> metadata_;
(...skipping 25 matching lines...) Expand all
506 }; 525 };
507 526
508 // Sets the free disk space getter for testing. 527 // Sets the free disk space getter for testing.
509 // The existing getter is deleted. 528 // The existing getter is deleted.
510 void SetFreeDiskSpaceGetterForTesting( 529 void SetFreeDiskSpaceGetterForTesting(
511 FreeDiskSpaceGetterInterface* getter); 530 FreeDiskSpaceGetterInterface* getter);
512 531
513 } // namespace gdata 532 } // namespace gdata
514 533
515 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ 534 #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