| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/profile.h" | 5 #include "chrome/browser/profile.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/browser_theme_provider.h" | 16 #include "chrome/browser/browser_theme_provider.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 17 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/extensions/extension_devtools_manager.h" | 18 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 18 #include "chrome/browser/extensions/extension_message_service.h" | 19 #include "chrome/browser/extensions/extension_message_service.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 // By default we let the cache determine the right size. | 99 // By default we let the cache determine the right size. |
| 99 *max_size = 0; | 100 *max_size = 0; |
| 100 if (!StringToInt(value, max_size)) { | 101 if (!StringToInt(value, max_size)) { |
| 101 *max_size = 0; | 102 *max_size = 0; |
| 102 } else if (max_size < 0) { | 103 } else if (max_size < 0) { |
| 103 *max_size = 0; | 104 *max_size = 0; |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 108 FilePath GetCachePath(const FilePath& base) { |
| 109 return base.Append(chrome::kCacheDirname); |
| 110 } |
| 111 |
| 112 FilePath GetMediaCachePath(const FilePath& base) { |
| 113 return base.Append(chrome::kMediaCacheDirname); |
| 114 } |
| 115 |
| 116 bool HasACacheSubdir(const FilePath &dir) { |
| 117 return file_util::PathExists(GetCachePath(dir)) || |
| 118 file_util::PathExists(GetMediaCachePath(dir)); |
| 119 } |
| 120 |
| 107 } // namespace | 121 } // namespace |
| 108 | 122 |
| 109 // A pointer to the request context for the default profile. See comments on | 123 // A pointer to the request context for the default profile. See comments on |
| 110 // Profile::GetDefaultRequestContext. | 124 // Profile::GetDefaultRequestContext. |
| 111 URLRequestContext* Profile::default_request_context_; | 125 URLRequestContext* Profile::default_request_context_; |
| 112 | 126 |
| 113 static void CleanupRequestContext(ChromeURLRequestContext* context) { | 127 static void CleanupRequestContext(ChromeURLRequestContext* context) { |
| 114 if (context) { | 128 if (context) { |
| 115 context->CleanupOnUIThread(); | 129 context->CleanupOnUIThread(); |
| 116 | 130 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue( | 592 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 579 switches::kPrivacyBlacklist); | 593 switches::kPrivacyBlacklist); |
| 580 #if defined(OS_POSIX) | 594 #if defined(OS_POSIX) |
| 581 FilePath path(WideToUTF8(option)); | 595 FilePath path(WideToUTF8(option)); |
| 582 #else | 596 #else |
| 583 FilePath path(option); | 597 FilePath path(option); |
| 584 #endif | 598 #endif |
| 585 blacklist_ = new Blacklist(path); | 599 blacklist_ = new Blacklist(path); |
| 586 } | 600 } |
| 587 | 601 |
| 602 #if defined(OS_MACOSX) |
| 603 // If the profile directory doesn't already have a cache directory and it |
| 604 // is under ~/Library/Application Support, use a suitable cache directory |
| 605 // under ~/Library/Caches. For example, a profile directory of |
| 606 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't |
| 607 // have a "Cache" or "MediaCache" subdirectory would use the cache directory |
| 608 // ~/Library/Caches/Google/Chrome/MyProfileName. |
| 609 // |
| 610 // TODO(akalin): Come up with unit tests for this. |
| 611 // TODO(akalin): Use for Linux, too? |
| 612 if (!HasACacheSubdir(path_)) { |
| 613 FilePath app_data_path, user_cache_path; |
| 614 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) && |
| 615 PathService::Get(base::DIR_CACHE, &user_cache_path) && |
| 616 app_data_path.AppendRelativePath(path_, &user_cache_path)) { |
| 617 base_cache_path_ = user_cache_path; |
| 618 } |
| 619 } |
| 620 #else |
| 588 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) | 621 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) |
| 589 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_); | 622 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_); |
| 623 #endif |
| 590 if (base_cache_path_.empty()) | 624 if (base_cache_path_.empty()) |
| 591 base_cache_path_ = path_; | 625 base_cache_path_ = path_; |
| 592 | 626 |
| 593 // Listen for theme installation. | 627 // Listen for theme installation. |
| 594 registrar_.Add(this, NotificationType::THEME_INSTALLED, | 628 registrar_.Add(this, NotificationType::THEME_INSTALLED, |
| 595 NotificationService::AllSources()); | 629 NotificationService::AllSources()); |
| 596 | 630 |
| 597 // Listen for bookmark model load, to bootstrap the sync service. | 631 // Listen for bookmark model load, to bootstrap the sync service. |
| 598 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, | 632 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, |
| 599 Source<Profile>(this)); | 633 Source<Profile>(this)); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 } | 917 } |
| 884 | 918 |
| 885 URLRequestContext* ProfileImpl::GetRequestContext() { | 919 URLRequestContext* ProfileImpl::GetRequestContext() { |
| 886 if (!request_context_) { | 920 if (!request_context_) { |
| 887 FilePath cookie_path = GetPath(); | 921 FilePath cookie_path = GetPath(); |
| 888 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 922 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| 889 FilePath cache_path = base_cache_path_; | 923 FilePath cache_path = base_cache_path_; |
| 890 int max_size; | 924 int max_size; |
| 891 GetCacheParameters(kNormalContext, &cache_path, &max_size); | 925 GetCacheParameters(kNormalContext, &cache_path, &max_size); |
| 892 | 926 |
| 893 cache_path = cache_path.Append(chrome::kCacheDirname); | 927 cache_path = GetCachePath(cache_path); |
| 894 request_context_ = ChromeURLRequestContext::CreateOriginal( | 928 request_context_ = ChromeURLRequestContext::CreateOriginal( |
| 895 this, cookie_path, cache_path, max_size); | 929 this, cookie_path, cache_path, max_size); |
| 896 request_context_->AddRef(); | 930 request_context_->AddRef(); |
| 897 | 931 |
| 898 // The first request context is always a normal (non-OTR) request context. | 932 // The first request context is always a normal (non-OTR) request context. |
| 899 // Even when Chromium is started in OTR mode, a normal profile is always | 933 // Even when Chromium is started in OTR mode, a normal profile is always |
| 900 // created first. | 934 // created first. |
| 901 if (!default_request_context_) { | 935 if (!default_request_context_) { |
| 902 default_request_context_ = request_context_; | 936 default_request_context_ = request_context_; |
| 903 NotificationService::current()->Notify( | 937 NotificationService::current()->Notify( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 914 | 948 |
| 915 return request_context_; | 949 return request_context_; |
| 916 } | 950 } |
| 917 | 951 |
| 918 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { | 952 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { |
| 919 if (!media_request_context_) { | 953 if (!media_request_context_) { |
| 920 FilePath cache_path = base_cache_path_; | 954 FilePath cache_path = base_cache_path_; |
| 921 int max_size; | 955 int max_size; |
| 922 GetCacheParameters(kMediaContext, &cache_path, &max_size); | 956 GetCacheParameters(kMediaContext, &cache_path, &max_size); |
| 923 | 957 |
| 924 cache_path = cache_path.Append(chrome::kMediaCacheDirname); | 958 cache_path = GetMediaCachePath(cache_path); |
| 925 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( | 959 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( |
| 926 this, cache_path, max_size); | 960 this, cache_path, max_size); |
| 927 media_request_context_->AddRef(); | 961 media_request_context_->AddRef(); |
| 928 | 962 |
| 929 DCHECK(media_request_context_->cookie_store()); | 963 DCHECK(media_request_context_->cookie_store()); |
| 930 } | 964 } |
| 931 | 965 |
| 932 return media_request_context_; | 966 return media_request_context_; |
| 933 } | 967 } |
| 934 | 968 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 #endif | 1370 #endif |
| 1337 return NULL; | 1371 return NULL; |
| 1338 } | 1372 } |
| 1339 | 1373 |
| 1340 void ProfileImpl::InitSyncService() { | 1374 void ProfileImpl::InitSyncService() { |
| 1341 #ifdef CHROME_PERSONALIZATION | 1375 #ifdef CHROME_PERSONALIZATION |
| 1342 sync_service_.reset(new ProfileSyncService(this)); | 1376 sync_service_.reset(new ProfileSyncService(this)); |
| 1343 sync_service_->Initialize(); | 1377 sync_service_->Initialize(); |
| 1344 #endif | 1378 #endif |
| 1345 } | 1379 } |
| OLD | NEW |