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

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

Issue 2610503002: Use TaskScheduler instead of WorkerPool in cache_util.cc. (Closed)
Patch Set: add ScopedTaskScheduler 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"
15 #include "base/threading/thread_restrictions.h" 16 #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::WorkerPool::PostTask( 139 base::PostTaskWithTraits(
140 FROM_HERE, base::Bind(&CleanupCallback, path, name_str), true); 140 FROM_HERE, base::TaskTraits()
141 .WithShutdownBehavior(
142 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
143 .WithPriority(base::TaskPriority::BACKGROUND)
144 .MayBlock(),
145 base::Bind(&CleanupCallback, path, name_str));
141 return true; 146 return true;
142 } 147 }
143 148
144 // Returns the preferred maximum number of bytes for the cache given the 149 // Returns the preferred maximum number of bytes for the cache given the
145 // number of available bytes. 150 // number of available bytes.
146 int PreferredCacheSize(int64_t available) { 151 int PreferredCacheSize(int64_t available) {
147 if (available < 0) 152 if (available < 0)
148 return kDefaultCacheSize; 153 return kDefaultCacheSize;
149 154
150 // Limit cache size to somewhat less than kint32max to avoid potential 155 // Limit cache size to somewhat less than kint32max to avoid potential
151 // integer overflows in cache backend implementations. 156 // integer overflows in cache backend implementations.
152 DCHECK_LT(kDefaultCacheSize * 4, std::numeric_limits<int32_t>::max()); 157 DCHECK_LT(kDefaultCacheSize * 4, std::numeric_limits<int32_t>::max());
153 return static_cast<int32_t>( 158 return static_cast<int32_t>(
154 std::min(PreferredCacheSizeInternal(available), 159 std::min(PreferredCacheSizeInternal(available),
155 static_cast<int64_t>(kDefaultCacheSize * 4))); 160 static_cast<int64_t>(kDefaultCacheSize * 4)));
156 } 161 }
157 162
158 } // namespace disk_cache 163 } // 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