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

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 8572006: Add policies to control the disk cache size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed issues. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_number_conversions.h"
16 #include "base/string_util.h" 15 #include "base/string_util.h"
17 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
19 #include "chrome/browser/autocomplete/network_action_predictor.h" 18 #include "chrome/browser/autocomplete/network_action_predictor.h"
20 #include "chrome/browser/autofill/personal_data_manager.h" 19 #include "chrome/browser/autofill/personal_data_manager.h"
21 #include "chrome/browser/background/background_contents_service_factory.h" 20 #include "chrome/browser/background/background_contents_service_factory.h"
22 #include "chrome/browser/background/background_mode_manager.h" 21 #include "chrome/browser/background/background_mode_manager.h"
23 #include "chrome/browser/bookmarks/bookmark_model.h" 22 #include "chrome/browser/bookmarks/bookmark_model.h"
24 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browsing_data_remover.h" 24 #include "chrome/browser/browsing_data_remover.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 namespace { 145 namespace {
147 146
148 // Delay, in milliseconds, before we explicitly create the SessionService. 147 // Delay, in milliseconds, before we explicitly create the SessionService.
149 static const int kCreateSessionServiceDelayMS = 500; 148 static const int kCreateSessionServiceDelayMS = 500;
150 149
151 #if defined(OS_MACOSX) 150 #if defined(OS_MACOSX)
152 // Capacity for mock keychain used for testing. 151 // Capacity for mock keychain used for testing.
153 static const int kMockKeychainSize = 1000; 152 static const int kMockKeychainSize = 1000;
154 #endif 153 #endif
155 154
156 enum ContextType {
157 kNormalContext,
158 kMediaContext
159 };
160
161 // Helper method needed because PostTask cannot currently take a Callback 155 // Helper method needed because PostTask cannot currently take a Callback
162 // function with non-void return type. 156 // function with non-void return type.
163 // TODO(jhawkins): Remove once IgnoreReturn is fixed. 157 // TODO(jhawkins): Remove once IgnoreReturn is fixed.
164 void CreateDirectoryNoResult(const FilePath& path) { 158 void CreateDirectoryNoResult(const FilePath& path) {
165 file_util::CreateDirectory(path); 159 file_util::CreateDirectory(path);
166 } 160 }
167 161
168 // Gets the cache parameters from the command line. |type| is the type of
169 // request context that we need, |cache_path| will be set to the user provided
170 // path, or will not be touched if there is not an argument. |max_size| will
171 // be the user provided value or zero by default.
172 void GetCacheParameters(ContextType type, FilePath* cache_path,
173 int* max_size) {
174 DCHECK(cache_path);
175 DCHECK(max_size);
176
177 // Override the cache location if specified by the user.
178 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDiskCacheDir)) {
179 *cache_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
180 switches::kDiskCacheDir);
181 }
182 #if !defined(OS_CHROMEOS)
183 // And if a policy is set this should have even higher precedence.
184 PrefService* prefs = g_browser_process->local_state();
185 if (prefs && prefs->IsManagedPreference(prefs::kDiskCacheDir))
186 *cache_path = prefs->GetFilePath(prefs::kDiskCacheDir);
187 #endif
188
189 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
190 switches::kMediaCacheSize;
191 std::string value =
192 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
193
194 // By default we let the cache determine the right size.
195 *max_size = 0;
196 if (!base::StringToInt(value, max_size)) {
197 *max_size = 0;
198 } else if (*max_size < 0) {
199 *max_size = 0;
200 }
201 }
202
203 FilePath GetCachePath(const FilePath& base) { 162 FilePath GetCachePath(const FilePath& base) {
204 return base.Append(chrome::kCacheDirname); 163 return base.Append(chrome::kCacheDirname);
205 } 164 }
206 165
207 FilePath GetMediaCachePath(const FilePath& base) { 166 FilePath GetMediaCachePath(const FilePath& base) {
208 return base.Append(chrome::kMediaCacheDirname); 167 return base.Append(chrome::kMediaCacheDirname);
209 } 168 }
210 169
211 } // namespace 170 } // namespace
212 171
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 GetSpellCheckProfile()->StartRecordingMetrics( 336 GetSpellCheckProfile()->StartRecordingMetrics(
378 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); 337 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
379 338
380 FilePath cookie_path = GetPath(); 339 FilePath cookie_path = GetPath();
381 cookie_path = cookie_path.Append(chrome::kCookieFilename); 340 cookie_path = cookie_path.Append(chrome::kCookieFilename);
382 FilePath origin_bound_cert_path = GetPath(); 341 FilePath origin_bound_cert_path = GetPath();
383 origin_bound_cert_path = 342 origin_bound_cert_path =
384 origin_bound_cert_path.Append(chrome::kOBCertFilename); 343 origin_bound_cert_path.Append(chrome::kOBCertFilename);
385 FilePath cache_path = base_cache_path_; 344 FilePath cache_path = base_cache_path_;
386 int cache_max_size; 345 int cache_max_size;
387 GetCacheParameters(kNormalContext, &cache_path, &cache_max_size); 346 GetCacheParameters(false, &cache_path, &cache_max_size);
388 cache_path = GetCachePath(cache_path); 347 cache_path = GetCachePath(cache_path);
389 348
390 FilePath media_cache_path = base_cache_path_; 349 FilePath media_cache_path = base_cache_path_;
391 int media_cache_max_size; 350 int media_cache_max_size;
392 GetCacheParameters(kMediaContext, &media_cache_path, &media_cache_max_size); 351 GetCacheParameters(true, &media_cache_path, &media_cache_max_size);
393 media_cache_path = GetMediaCachePath(media_cache_path); 352 media_cache_path = GetMediaCachePath(media_cache_path);
394 353
395 FilePath extensions_cookie_path = GetPath(); 354 FilePath extensions_cookie_path = GetPath();
396 extensions_cookie_path = 355 extensions_cookie_path =
397 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); 356 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename);
398 357
399 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname); 358 FilePath app_path = GetPath().Append(chrome::kIsolatedAppStateDirname);
400 359
401 // Make sure we initialize the ProfileIOData after everything else has been 360 // Make sure we initialize the ProfileIOData after everything else has been
402 // initialized that we might be reading from the IO thread. 361 // initialized that we might be reading from the IO thread.
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 void ProfileImpl::UpdateProfileUserNameCache() { 1559 void ProfileImpl::UpdateProfileUserNameCache() {
1601 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1560 ProfileManager* profile_manager = g_browser_process->profile_manager();
1602 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1561 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1603 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1562 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1604 if (index != std::string::npos) { 1563 if (index != std::string::npos) {
1605 std::string user_name = 1564 std::string user_name =
1606 GetPrefs()->GetString(prefs::kGoogleServicesUsername); 1565 GetPrefs()->GetString(prefs::kGoogleServicesUsername);
1607 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); 1566 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name));
1608 } 1567 }
1609 } 1568 }
1569
1570 // Gets the cache parameters from the command line. If |is_media_context| is
1571 // set to true then settings for the media context type is what we need,
1572 // |cache_path| will be set to the user provided path, or will not be touched if
1573 // there is not an argument. |max_size| will be the user provided value or zero
1574 // by default.
1575 void ProfileImpl::GetCacheParameters(bool is_media_context,
1576 FilePath* cache_path,
1577 int* max_size) {
1578 DCHECK(cache_path);
1579 DCHECK(max_size);
1580 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1581 if (!path.empty())
1582 *cache_path = path;
1583 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1584 prefs_->GetInteger(prefs::kDiskCacheSize);
1585 }
1586
Joao da Silva 2011/11/16 16:10:42 Nit: remove newline at end of file
pastarmovj 2011/11/17 13:10:10 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698