Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: net/disk_cache/cache_util.cc

Issue 2626163002: Revert of Use TaskScheduler instead of WorkerPool in cache_util.cc. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/disk_cache/cache_util.h" 5 #include "net/disk_cache/cache_util.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/task_scheduler/post_task.h"
16 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/threading/worker_pool.h"
17 17
18 namespace { 18 namespace {
19 19
20 const int kMaxOldFolders = 100; 20 const int kMaxOldFolders = 100;
21 21
22 // Returns a fully qualified name from path and name, using a given name prefix 22 // Returns a fully qualified name from path and name, using a given name prefix
23 // and index number. For instance, if the arguments are "/foo", "bar" and 5, it 23 // and index number. For instance, if the arguments are "/foo", "bar" and 5, it
24 // will return "/foo/old_bar_005". 24 // will return "/foo/old_bar_005".
25 base::FilePath GetPrefixedName(const base::FilePath& path, 25 base::FilePath GetPrefixedName(const base::FilePath& path,
26 const std::string& name, 26 const std::string& name,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 LOG(ERROR) << "Unable to get another cache folder"; 129 LOG(ERROR) << "Unable to get another cache folder";
130 return false; 130 return false;
131 } 131 }
132 132
133 if (!disk_cache::MoveCache(full_path, to_delete)) { 133 if (!disk_cache::MoveCache(full_path, to_delete)) {
134 LOG(ERROR) << "Unable to move cache folder " << full_path.value() << " to " 134 LOG(ERROR) << "Unable to move cache folder " << full_path.value() << " to "
135 << to_delete.value(); 135 << to_delete.value();
136 return false; 136 return false;
137 } 137 }
138 138
139 base::PostTaskWithTraits( 139 base::WorkerPool::PostTask(
140 FROM_HERE, base::TaskTraits() 140 FROM_HERE, base::Bind(&CleanupCallback, path, name_str), true);
141 .WithShutdownBehavior(
142 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
143 .WithPriority(base::TaskPriority::BACKGROUND)
144 .MayBlock(),
145 base::Bind(&CleanupCallback, path, name_str));
146 return true; 141 return true;
147 } 142 }
148 143
149 // Returns the preferred maximum number of bytes for the cache given the 144 // Returns the preferred maximum number of bytes for the cache given the
150 // number of available bytes. 145 // number of available bytes.
151 int PreferredCacheSize(int64_t available) { 146 int PreferredCacheSize(int64_t available) {
152 if (available < 0) 147 if (available < 0)
153 return kDefaultCacheSize; 148 return kDefaultCacheSize;
154 149
155 // Limit cache size to somewhat less than kint32max to avoid potential 150 // Limit cache size to somewhat less than kint32max to avoid potential
156 // integer overflows in cache backend implementations. 151 // integer overflows in cache backend implementations.
157 DCHECK_LT(kDefaultCacheSize * 4, std::numeric_limits<int32_t>::max()); 152 DCHECK_LT(kDefaultCacheSize * 4, std::numeric_limits<int32_t>::max());
158 return static_cast<int32_t>( 153 return static_cast<int32_t>(
159 std::min(PreferredCacheSizeInternal(available), 154 std::min(PreferredCacheSizeInternal(available),
160 static_cast<int64_t>(kDefaultCacheSize * 4))); 155 static_cast<int64_t>(kDefaultCacheSize * 4)));
161 } 156 }
162 157
163 } // namespace disk_cache 158 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698