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 FilePathPairCallback = |
ppi
2015/09/15 15:21:23
nit: wdyt about calling this by meaning, ie. Respo
qsr
2015/09/16 11:46:38
Done.
| |
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 // Create the disk cache database. If |force_clean| is true, or the database |
ppi
2015/09/15 15:21:23
nit: Creates
qsr
2015/09/16 11:46:39
Done.
| |
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 // As |UpdateAndGet|, but uses FilePath instead of mojo arrays. |
ppi
2015/09/15 15:21:23
nit: this comment forces the reader to go back all
qsr
2015/09/16 11:46:38
Done.
| |
40 void GetFileInternal(mojo::URLResponsePtr response, | 48 void UpdateAndGetInternal(URLResponsePtr response, |
41 const FilePathPairCallback& callback); | 49 const FilePathPairCallback& callback); |
42 | 50 |
43 // Internal implementation of |GetExtractedContent|. The parameters are: | 51 // Internal implementation of |UpdateAndGetExtracted|. The parameters are: |
44 // |callback|: The callback to return values to the caller. It uses FilePath | 52 // |callback|: The callback to return values to the caller. It uses FilePath |
45 // instead of mojo arrays. | 53 // instead of mojo arrays. |
46 // |base_dir|: The base directory for caching data associated to the response. | |
47 // |extracted_dir|: The directory where the file content must be extracted. It | |
48 // will be returned to the consumer. | |
49 // |content|: The content of the body of the response. | 54 // |content|: The content of the body of the response. |
50 // |cache_dir|: The directory the user can user to cache its own content. | 55 // |cache_directory|: The directory the user can user to cache its own |
51 void GetExtractedContentInternal(const FilePathPairCallback& callback, | 56 // content. |
52 const base::FilePath& base_dir, | 57 void UpdateAndGetExtractedInternal( |
53 const base::FilePath& extracted_dir, | 58 const FilePathPairCallback& callback, |
54 const base::FilePath& content, | 59 const base::FilePath& content_path, |
55 const base::FilePath& cache_dir); | 60 const base::FilePath& consumer_cache_directory); |
56 | 61 |
57 base::TaskRunner* task_runner_; | 62 scoped_refptr<base::TaskRunner> task_runner_; |
58 base::FilePath base_directory_; | 63 std::string request_origin_; |
64 base::FilePath cache_directory_; | |
65 scoped_refptr<URLResponseDiskCacheDB> db_; | |
59 StrongBinding<URLResponseDiskCache> binding_; | 66 StrongBinding<URLResponseDiskCache> binding_; |
60 | 67 |
61 DISALLOW_COPY_AND_ASSIGN(URLResponseDiskCacheImpl); | 68 DISALLOW_COPY_AND_ASSIGN(URLResponseDiskCacheImpl); |
62 }; | 69 }; |
63 | 70 |
64 } // namespace mojo | 71 } // namespace mojo |
65 | 72 |
66 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ | 73 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_IMPL_H_ |
OLD | NEW |