OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/macros.h" |
6 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
7 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "net/base/cache_type.h" | 10 #include "net/base/cache_type.h" |
10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
11 #include "net/disk_cache/blockfile/backend_impl.h" | 12 #include "net/disk_cache/blockfile/backend_impl.h" |
12 #include "net/disk_cache/cache_util.h" | 13 #include "net/disk_cache/cache_util.h" |
13 #include "net/disk_cache/disk_cache.h" | 14 #include "net/disk_cache/disk_cache.h" |
14 #include "net/disk_cache/memory/mem_backend_impl.h" | 15 #include "net/disk_cache/memory/mem_backend_impl.h" |
15 #include "net/disk_cache/simple/simple_backend_impl.h" | 16 #include "net/disk_cache/simple/simple_backend_impl.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Builds an instance of the backend depending on platform, type, experiments | 20 // Builds an instance of the backend depending on platform, type, experiments |
20 // etc. Takes care of the retry state. This object will self-destroy when | 21 // etc. Takes care of the retry state. This object will self-destroy when |
21 // finished. | 22 // finished. |
22 class CacheCreator { | 23 class CacheCreator { |
23 public: | 24 public: |
24 CacheCreator(const base::FilePath& path, | 25 CacheCreator(const base::FilePath& path, |
25 bool force, | 26 bool force, |
26 int max_bytes, | 27 int max_bytes, |
27 net::CacheType type, | 28 net::CacheType type, |
28 net::BackendType backend_type, | 29 net::BackendType backend_type, |
29 uint32 flags, | 30 uint32_t flags, |
30 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 31 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
31 net::NetLog* net_log, | 32 net::NetLog* net_log, |
32 scoped_ptr<disk_cache::Backend>* backend, | 33 scoped_ptr<disk_cache::Backend>* backend, |
33 const net::CompletionCallback& callback); | 34 const net::CompletionCallback& callback); |
34 | 35 |
35 // Creates the backend. | 36 // Creates the backend. |
36 int Run(); | 37 int Run(); |
37 | 38 |
38 private: | 39 private: |
39 ~CacheCreator(); | 40 ~CacheCreator(); |
40 | 41 |
41 void DoCallback(int result); | 42 void DoCallback(int result); |
42 | 43 |
43 void OnIOComplete(int result); | 44 void OnIOComplete(int result); |
44 | 45 |
45 const base::FilePath path_; | 46 const base::FilePath path_; |
46 bool force_; | 47 bool force_; |
47 bool retry_; | 48 bool retry_; |
48 int max_bytes_; | 49 int max_bytes_; |
49 net::CacheType type_; | 50 net::CacheType type_; |
50 net::BackendType backend_type_; | 51 net::BackendType backend_type_; |
51 uint32 flags_; | 52 uint32_t flags_; |
52 scoped_refptr<base::SingleThreadTaskRunner> thread_; | 53 scoped_refptr<base::SingleThreadTaskRunner> thread_; |
53 scoped_ptr<disk_cache::Backend>* backend_; | 54 scoped_ptr<disk_cache::Backend>* backend_; |
54 net::CompletionCallback callback_; | 55 net::CompletionCallback callback_; |
55 scoped_ptr<disk_cache::Backend> created_cache_; | 56 scoped_ptr<disk_cache::Backend> created_cache_; |
56 net::NetLog* net_log_; | 57 net::NetLog* net_log_; |
57 | 58 |
58 DISALLOW_COPY_AND_ASSIGN(CacheCreator); | 59 DISALLOW_COPY_AND_ASSIGN(CacheCreator); |
59 }; | 60 }; |
60 | 61 |
61 CacheCreator::CacheCreator( | 62 CacheCreator::CacheCreator( |
62 const base::FilePath& path, | 63 const base::FilePath& path, |
63 bool force, | 64 bool force, |
64 int max_bytes, | 65 int max_bytes, |
65 net::CacheType type, | 66 net::CacheType type, |
66 net::BackendType backend_type, | 67 net::BackendType backend_type, |
67 uint32 flags, | 68 uint32_t flags, |
68 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 69 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
69 net::NetLog* net_log, | 70 net::NetLog* net_log, |
70 scoped_ptr<disk_cache::Backend>* backend, | 71 scoped_ptr<disk_cache::Backend>* backend, |
71 const net::CompletionCallback& callback) | 72 const net::CompletionCallback& callback) |
72 : path_(path), | 73 : path_(path), |
73 force_(force), | 74 force_(force), |
74 retry_(false), | 75 retry_(false), |
75 max_bytes_(max_bytes), | 76 max_bytes_(max_bytes), |
76 type_(type), | 77 type_(type), |
77 backend_type_(backend_type), | 78 backend_type_(backend_type), |
78 flags_(flags), | 79 flags_(flags), |
79 thread_(thread), | 80 thread_(thread), |
80 backend_(backend), | 81 backend_(backend), |
81 callback_(callback), | 82 callback_(callback), |
82 net_log_(net_log) { | 83 net_log_(net_log) {} |
83 } | |
84 | 84 |
85 CacheCreator::~CacheCreator() { | 85 CacheCreator::~CacheCreator() { |
86 } | 86 } |
87 | 87 |
88 int CacheCreator::Run() { | 88 int CacheCreator::Run() { |
89 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
90 static const bool kSimpleBackendIsDefault = true; | 90 static const bool kSimpleBackendIsDefault = true; |
91 #else | 91 #else |
92 static const bool kSimpleBackendIsDefault = false; | 92 static const bool kSimpleBackendIsDefault = false; |
93 #endif | 93 #endif |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 backend_type, | 177 backend_type, |
178 kNone, | 178 kNone, |
179 thread, | 179 thread, |
180 net_log, | 180 net_log, |
181 backend, | 181 backend, |
182 callback); | 182 callback); |
183 return creator->Run(); | 183 return creator->Run(); |
184 } | 184 } |
185 | 185 |
186 } // namespace disk_cache | 186 } // namespace disk_cache |
OLD | NEW |