OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ | 5 #ifndef SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ |
6 #define SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ | 6 #define SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
10 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
11 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
12 #include "mojo/services/url_response_disk_cache/public/interfaces/url_response_d
isk_cache.mojom.h" | 13 #include "mojo/services/url_response_disk_cache/public/interfaces/url_response_d
isk_cache.mojom.h" |
| 14 #include "services/url_response_disk_cache/url_response_disk_cache_db.h" |
13 | 15 |
14 namespace mojo { | 16 namespace mojo { |
15 | 17 |
16 class URLResponseDiskCacheImpl : public URLResponseDiskCache { | 18 class URLResponseDiskCacheImpl : public URLResponseDiskCache { |
17 public: | 19 public: |
18 using FilePathPairCallback = | 20 using ResponseFileAndCacheDirCallback = |
19 base::Callback<void(const base::FilePath&, const base::FilePath&)>; | 21 base::Callback<void(const base::FilePath&, const base::FilePath&)>; |
20 | 22 |
21 // Cleares the cached content. The actual deletion will be performed using the | 23 // Creates the disk cache database. If |force_clean| is true, or the database |
22 // given task runner, but cache appears as cleared immediately after the | 24 // is outdated, it will clear the cached content. The actual deletion will be |
23 // function returns. | 25 // performed using the given task runner, but cache appears as cleared |
24 static void ClearCache(base::TaskRunner* task_runner); | 26 // immediately after the function returns. |
| 27 static scoped_refptr<URLResponseDiskCacheDB> CreateDB( |
| 28 scoped_refptr<base::TaskRunner> task_runner, |
| 29 bool force_clean); |
25 | 30 |
26 URLResponseDiskCacheImpl(base::TaskRunner* task_runner, | 31 URLResponseDiskCacheImpl(scoped_refptr<base::TaskRunner> task_runner, |
| 32 scoped_refptr<URLResponseDiskCacheDB> db, |
27 const std::string& remote_application_url, | 33 const std::string& remote_application_url, |
28 InterfaceRequest<URLResponseDiskCache> request); | 34 InterfaceRequest<URLResponseDiskCache> request); |
29 ~URLResponseDiskCacheImpl() override; | 35 ~URLResponseDiskCacheImpl() override; |
30 | 36 |
31 private: | 37 private: |
32 // URLResponseDiskCache | 38 // URLResponseDiskCache |
33 void GetFile(mojo::URLResponsePtr response, | 39 void Get(const String& url, const GetCallback& callback) override; |
34 const GetFileCallback& callback) override; | 40 void Update(URLResponsePtr response) override; |
35 void GetExtractedContent( | 41 void UpdateAndGet(URLResponsePtr response, |
36 mojo::URLResponsePtr response, | 42 const UpdateAndGetCallback& callback) override; |
37 const GetExtractedContentCallback& callback) override; | 43 void UpdateAndGetExtracted( |
| 44 URLResponsePtr response, |
| 45 const UpdateAndGetExtractedCallback& callback) override; |
38 | 46 |
39 // As |GetFile|, but uses FilePath instead of mojo arrays. | 47 // Internal implementation of |UpdateAndGet| using a pair of base::FilePath to |
40 void GetFileInternal(mojo::URLResponsePtr response, | 48 // represent the paths the the response body and to the per-response client |
41 const FilePathPairCallback& callback); | 49 // cache directory. |
| 50 void UpdateAndGetInternal(URLResponsePtr response, |
| 51 const ResponseFileAndCacheDirCallback& callback); |
42 | 52 |
43 // Internal implementation of |GetExtractedContent|. The parameters are: | 53 // Internal implementation of |UpdateAndGetExtracted|. The parameters are: |
44 // |callback|: The callback to return values to the caller. It uses FilePath | 54 // |callback|: The callback to return values to the caller. It uses FilePath |
45 // instead of mojo arrays. | 55 // instead of mojo arrays. |
46 // |base_dir|: The base directory for caching data associated to the response. | 56 // |response_body_path|: The path to the content of the body of the response. |
47 // |extracted_dir|: The directory where the file content must be extracted. It | 57 // |consumer_cache_directory|: The directory the user can user to cache its |
48 // will be returned to the consumer. | 58 // own content. |
49 // |content|: The content of the body of the response. | 59 void UpdateAndGetExtractedInternal( |
50 // |cache_dir|: The directory the user can user to cache its own content. | 60 const ResponseFileAndCacheDirCallback& callback, |
51 void GetExtractedContentInternal(const FilePathPairCallback& callback, | 61 const base::FilePath& response_body_path, |
52 const base::FilePath& base_dir, | 62 const base::FilePath& consumer_cache_directory); |
53 const base::FilePath& extracted_dir, | |
54 const base::FilePath& content, | |
55 const base::FilePath& cache_dir); | |
56 | 63 |
57 base::TaskRunner* task_runner_; | 64 scoped_refptr<base::TaskRunner> task_runner_; |
58 base::FilePath base_directory_; | 65 std::string request_origin_; |
| 66 scoped_refptr<URLResponseDiskCacheDB> db_; |
59 StrongBinding<URLResponseDiskCache> binding_; | 67 StrongBinding<URLResponseDiskCache> binding_; |
60 | 68 |
61 DISALLOW_COPY_AND_ASSIGN(URLResponseDiskCacheImpl); | 69 DISALLOW_COPY_AND_ASSIGN(URLResponseDiskCacheImpl); |
62 }; | 70 }; |
63 | 71 |
64 } // namespace mojo | 72 } // namespace mojo |
65 | 73 |
66 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ | 74 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ |
OLD | NEW |