| 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 = |
| 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 |
| 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 GetFile(URLResponsePtr response, |
| 34 const GetFileCallback& callback) override; | 40 const GetFileCallback& callback) override; |
| 41 void GetCachedResponse(const String& url, |
| 42 const GetCachedResponseCallback& callback) override; |
| 35 void GetExtractedContent( | 43 void GetExtractedContent( |
| 36 mojo::URLResponsePtr response, | 44 URLResponsePtr response, |
| 37 const GetExtractedContentCallback& callback) override; | 45 const GetExtractedContentCallback& callback) override; |
| 46 void UpdateCache(URLResponsePtr response) override; |
| 38 | 47 |
| 39 // As |GetFile|, but uses FilePath instead of mojo arrays. | 48 // As |GetFile|, but uses FilePath instead of mojo arrays. |
| 40 void GetFileInternal(mojo::URLResponsePtr response, | 49 void GetFileInternal(URLResponsePtr response, |
| 41 const FilePathPairCallback& callback); | 50 const FilePathPairCallback& callback); |
| 42 | 51 |
| 43 // Internal implementation of |GetExtractedContent|. The parameters are: | 52 // Internal implementation of |GetExtractedContent|. The parameters are: |
| 44 // |callback|: The callback to return values to the caller. It uses FilePath | 53 // |callback|: The callback to return values to the caller. It uses FilePath |
| 45 // instead of mojo arrays. | 54 // 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. | 55 // |content|: The content of the body of the response. |
| 50 // |cache_dir|: The directory the user can user to cache its own content. | 56 // |cache_directory|: The directory the user can user to cache its own |
| 51 void GetExtractedContentInternal(const FilePathPairCallback& callback, | 57 // content. |
| 52 const base::FilePath& base_dir, | 58 void GetExtractedContentInternal( |
| 53 const base::FilePath& extracted_dir, | 59 const FilePathPairCallback& callback, |
| 54 const base::FilePath& content, | 60 const base::FilePath& content_path, |
| 55 const base::FilePath& cache_dir); | 61 const base::FilePath& consumer_cache_directory); |
| 56 | 62 |
| 57 base::TaskRunner* task_runner_; | 63 scoped_refptr<base::TaskRunner> task_runner_; |
| 58 base::FilePath base_directory_; | 64 std::string request_origin_; |
| 65 base::FilePath cache_directory_; |
| 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 |