OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_ENTRY_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_ENTRY_H_ | |
7 | |
8 #include <string> | |
9 | |
10 namespace gdata { | |
11 | |
12 // This is used as a bitmask for the cache state. | |
13 enum GDataCacheState { | |
14 CACHE_STATE_NONE = 0x0, | |
15 CACHE_STATE_PINNED = 0x1 << 0, | |
16 CACHE_STATE_PRESENT = 0x1 << 1, | |
17 CACHE_STATE_DIRTY = 0x1 << 2, | |
18 CACHE_STATE_MOUNTED = 0x1 << 3, | |
19 CACHE_STATE_PERSISTENT = 0x1 << 4, | |
20 }; | |
hshi1
2012/07/11 23:17:36
Nit: This enum GDataCacheState is directly defined
satorux1
2012/07/11 23:28:19
You are right. We should move CacheSubdirectoryTyp
| |
21 | |
22 // Structure to store information of an existing cache file. | |
23 // Cache files are stored in 'tmp' or 'persistent' directory. | |
24 class GDataCacheEntry { | |
25 public: | |
26 GDataCacheEntry() : cache_state_(CACHE_STATE_NONE) {} | |
27 | |
28 GDataCacheEntry(const std::string& md5, | |
29 int cache_state) | |
30 : md5_(md5), | |
31 cache_state_(cache_state) { | |
32 } | |
33 | |
34 // The MD5 of the cache file. This can be "local" if the file is | |
35 // locally modified. | |
36 const std::string& md5() const { return md5_; } | |
37 | |
38 // The cache state represented as a bitmask of GDataCacheState. | |
39 int cache_state() const { return cache_state_; } | |
40 | |
41 void set_md5(const std::string& md5) { md5_ = md5; } | |
42 void set_cache_state(int cache_state) { cache_state_ = cache_state; } | |
43 | |
44 // Returns true if the file is present locally. | |
45 bool IsPresent() const { return cache_state_ & CACHE_STATE_PRESENT; } | |
46 | |
47 // Returns true if the file is pinned (i.e. available offline). | |
48 bool IsPinned() const { return cache_state_ & CACHE_STATE_PINNED; } | |
49 | |
50 // Returns true if the file is dirty (i.e. modified locally). | |
51 bool IsDirty() const { return cache_state_ & CACHE_STATE_DIRTY; } | |
52 | |
53 // Returns true if the file is a mounted archive file. | |
54 bool IsMounted() const { return cache_state_ & CACHE_STATE_MOUNTED; } | |
55 | |
56 // Returns true if the file is in the persistent directory. | |
57 bool IsPersistent() const { return cache_state_ & CACHE_STATE_PERSISTENT; } | |
58 | |
59 // Setters for the states describe above. | |
60 void SetPresent(bool value) { | |
61 if (value) | |
62 cache_state_ |= CACHE_STATE_PRESENT; | |
63 else | |
64 cache_state_ &= ~CACHE_STATE_PRESENT; | |
65 } | |
66 void SetPinned(bool value) { | |
67 if (value) | |
68 cache_state_ |= CACHE_STATE_PINNED; | |
69 else | |
70 cache_state_ &= ~CACHE_STATE_PINNED; | |
71 } | |
72 void SetDirty(bool value) { | |
73 if (value) | |
74 cache_state_ |= CACHE_STATE_DIRTY; | |
75 else | |
76 cache_state_ &= ~CACHE_STATE_DIRTY; | |
77 } | |
78 void SetMounted(bool value) { | |
79 if (value) | |
80 cache_state_ |= CACHE_STATE_MOUNTED; | |
81 else | |
82 cache_state_ &= ~CACHE_STATE_MOUNTED; | |
83 } | |
84 void SetPersistent(bool value) { | |
85 if (value) | |
86 cache_state_ |= CACHE_STATE_PERSISTENT; | |
87 else | |
88 cache_state_ &= ~CACHE_STATE_PERSISTENT; | |
89 } | |
90 | |
91 // For debugging purposes. | |
92 std::string ToString() const; | |
93 | |
94 private: | |
95 std::string md5_; | |
96 int cache_state_; | |
97 }; | |
98 | |
99 } // namespace gdata | |
100 | |
101 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_ENTRY_H_ | |
OLD | NEW |