OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_POLICY_CLOUD_RESOURCE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_RESOURCE_CACHE_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_RESOURCE_CACHE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_RESOURCE_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/memory/ref_counted.h" |
| 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } |
15 | 19 |
16 namespace policy { | 20 namespace policy { |
17 | 21 |
18 // Manages storage of data at a given path. The data is keyed by a key and | 22 // Manages storage of data at a given path. The data is keyed by a key and |
19 // a subkey, and can be queried by (key, subkey) or (key) lookups. | 23 // a subkey, and can be queried by (key, subkey) or (key) lookups. |
20 // The contents of the cache have to be manually cleared using Delete() or | 24 // The contents of the cache have to be manually cleared using Delete() or |
21 // PurgeOtherSubkeys(). | 25 // PurgeOtherSubkeys(). |
22 // Instances of this class can be created on any thread, but from then on must | 26 // The class can be instantiated on any thread but from then on, it must be |
23 // be always used from the same thread, and it must support file I/O. | 27 // accessed via the |task_runner| only. The |task_runner| must support file I/O. |
24 class ResourceCache : public base::NonThreadSafe { | 28 class ResourceCache { |
25 public: | 29 public: |
26 explicit ResourceCache(const base::FilePath& cache_path); | 30 explicit ResourceCache(const base::FilePath& cache_path, |
| 31 scoped_refptr<base::SequencedTaskRunner> task_runner); |
27 virtual ~ResourceCache(); | 32 virtual ~ResourceCache(); |
28 | 33 |
29 // Stores |data| under (key, subkey). Returns true if the store suceeded, and | 34 // Stores |data| under (key, subkey). Returns true if the store suceeded, and |
30 // false otherwise. | 35 // false otherwise. |
31 bool Store(const std::string& key, | 36 bool Store(const std::string& key, |
32 const std::string& subkey, | 37 const std::string& subkey, |
33 const std::string& data); | 38 const std::string& data); |
34 | 39 |
35 // Loads the contents of (key, subkey) into |data| and returns true. Returns | 40 // Loads the contents of (key, subkey) into |data| and returns true. Returns |
36 // false if (key, subkey) isn't found or if there is a problem reading the | 41 // false if (key, subkey) isn't found or if there is a problem reading the |
(...skipping 28 matching lines...) Expand all Loading... |
65 // and returns whether the parent directory of this file exists. If | 70 // and returns whether the parent directory of this file exists. If |
66 // |allow_create_key| is |true|, the directory is created if it did not exist | 71 // |allow_create_key| is |true|, the directory is created if it did not exist |
67 // yet. This method does not check whether the file at |path| exists or not. | 72 // yet. This method does not check whether the file at |path| exists or not. |
68 bool VerifyKeyPathAndGetSubkeyPath(const std::string& key, | 73 bool VerifyKeyPathAndGetSubkeyPath(const std::string& key, |
69 bool allow_create_key, | 74 bool allow_create_key, |
70 const std::string& subkey, | 75 const std::string& subkey, |
71 base::FilePath* subkey_path); | 76 base::FilePath* subkey_path); |
72 | 77 |
73 base::FilePath cache_dir_; | 78 base::FilePath cache_dir_; |
74 | 79 |
| 80 // Task runner that |this| runs on. |
| 81 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 82 |
75 DISALLOW_COPY_AND_ASSIGN(ResourceCache); | 83 DISALLOW_COPY_AND_ASSIGN(ResourceCache); |
76 }; | 84 }; |
77 | 85 |
78 } // namespace policy | 86 } // namespace policy |
79 | 87 |
80 #endif // CHROME_BROWSER_POLICY_CLOUD_RESOURCE_CACHE_H_ | 88 #endif // CHROME_BROWSER_POLICY_CLOUD_RESOURCE_CACHE_H_ |
OLD | NEW |