// Avoid trimming the cache for the first 5 minutes (10 timer ticks).
const int kTrimDelay = 10;
+#if BUILDFLAG(IS_TIZEN_TV)
+// tv needs minimum space to install and update apps, 90M
+const int kTVReservedSpace = 90 * 1024 * 1024;
+const int kMaxFileSizeLowerBound = 5 * 1024 * 1024;
+#endif
+
int DesiredIndexTableLen(int32_t storage_size) {
if (storage_size <= k64kEntriesStore)
return kBaseTableLen;
if (init_)
return net::ERR_FAILED;
+#if BUILDFLAG(IS_TIZEN_TV)
+ int life_time = disk_cache::GetMemoryLifeTime();
+ if (life_time <= 0 || life_time > 5) {
+ LOG(ERROR) << "MemoryLifeTime was dangerous for using cache";
+ return net::ERR_FAILED;
+ }
+#endif
+
bool create_files = false;
if (!InitBackingStore(&create_files)) {
ReportError(ERR_STORAGE_ERROR);
}
bool BackendImpl::SetMaxSize(int64_t max_bytes) {
- if (max_bytes < 0 || max_bytes > std::numeric_limits<int>::max())
+ if (max_bytes < 0 || max_bytes > std::numeric_limits<int>::max()) {
+#if BUILDFLAG(IS_TIZEN_TV)
+ max_size_ = max_bytes;
+#endif
return false;
+ }
// Zero size means use the default.
if (!max_bytes)
void BackendImpl::OnEntryDestroyEnd() {
DecreaseNumRefs();
+#if BUILDFLAG(IS_TIZEN_TV)
+ if (up_ticks_ > kTrimDelay && !already_update_) {
+ already_update_ = true;
+ UpdateMaxCacheSize();
+ LOG(INFO) << "Current real max cache size : " << max_size_;
+ }
+#endif
consider_evicting_at_op_end_ = true;
}
}
int64_t BackendImpl::MaxFileSize() const {
+#if BUILDFLAG(IS_TIZEN_TV)
+ if (GetCacheType() == net::PNACL_CACHE)
+ return max_size_;
+
+ return std::max(max_size_ / 8, kMaxFileSizeLowerBound);
+#else
return GetCacheType() == net::PNACL_CACHE ? max_size_ : max_size_ / 8;
+#endif
}
void BackendImpl::ModifyStorageSize(int32_t old_size, int32_t new_size) {
if (!base::CreateDirectory(path_))
return false;
+#if BUILDFLAG(IS_TIZEN_TV)
+ if (max_size_ && base::SysInfo::AmountOfFreeDiskSpace(path_) <
+ (max_size_ + kTVReservedSpace))
+ return false;
+#endif
+
base::FilePath index_name = path_.AppendASCII(kIndexName);
int flags = base::File::FLAG_READ | base::File::FLAG_WRITE |
// The maximum cache size will be either set explicitly by the caller, or
// calculated by this code.
void BackendImpl::AdjustMaxCacheSize(int table_len) {
+#if BUILDFLAG(IS_TIZEN_TV)
+ // if set cache size to zero not use the default.
+ if (max_size_ >= 0)
+ return;
+#else
if (max_size_)
return;
+#endif
// If table_len is provided, the index file exists.
DCHECK(!table_len || data_->header.magic);
return;
}
+#if BUILDFLAG(IS_TIZEN_TV)
+ if (available <= kTVReservedSpace)
+ return;
+ available -= kTVReservedSpace;
+#endif
+
if (table_len)
available += data_->header.num_bytes;
std::move(callback));
}
+#if BUILDFLAG(IS_TIZEN_TV)
+void BackendImpl::UpdateMaxCacheSize() {
+ int used_size = CalculateWebAppCacheSize(path_, GetCacheType());
+
+ if (used_size == -1)
+ return;
+
+ if (used_size < max_size_) {
+ max_size_ = max_size_ - used_size + data_->header.num_bytes;
+ return;
+ }
+
+ if (data_->header.num_bytes * 2 >= max_size_) {
+ max_size_ =
+ (data_->header.num_bytes > max_size_ ? max_size_
+ : data_->header.num_bytes) /
+ 2;
+ return;
+ }
+
+ max_size_ = data_->header.num_bytes;
+}
+#endif
+
} // namespace disk_cache
bool InitStats();
void StoreStats();
+#if BUILDFLAG(IS_TIZEN_TV)
+ void UpdateMaxCacheSize();
+#endif
+
// Deletes the cache and starts again.
void RestartCache(bool failure);
void PrepareForRestart();
bool first_timer_ = true; // True if the timer has not been called.
bool user_load_ =
false; // True if we see a high load coming from the caller.
+#if BUILDFLAG(IS_TIZEN_TV)
+ bool already_update_ = false;
+#endif
// True if we should consider doing eviction at end of current operation.
bool consider_evicting_at_op_end_ = false;
if (backend_->disabled_ || trimming_)
return;
+#if BUILDFLAG(IS_TIZEN_TV)
+ max_size_ = LowWaterAdjust(backend_->max_size_);
+#endif
+
if (!empty && !ShouldTrim())
return PostDelayedTrim();
int64_t available,
net::CacheType type = net::DISK_CACHE);
+#if BUILDFLAG(IS_TIZEN_TV)
+// Get the life time of device
+int GetMemoryLifeTime();
+
+// Calculate the total web apps disk cache size.
+int CalculateWebAppCacheSize(const base::FilePath& path, net::CacheType type);
+
+// Web apps disk cache path prefix.
+const char kTizenAppCache[] = "WebAppsCache";
+const char kIndexName[] = "index";
+#endif
+
// The default cache size should not ideally be exposed, but the blockfile
// backend uses it for reasons that include testing.
NET_EXPORT_PRIVATE extern const int kDefaultCacheSize;
#include "base/strings/string_util.h"
#include "build/chromeos_buildflags.h"
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "net/disk_cache/blockfile/disk_format.h"
+#endif
+
namespace disk_cache {
bool MoveCache(const base::FilePath& from_path, const base::FilePath& to_path) {
#endif
}
+#if BUILDFLAG(IS_TIZEN_TV)
+/*
+ Device life time table : return value of BSP API, life_time
+ 0x00 : Not defined
+ 0x01 : 0% - 10% device life time used
+ 0x02 : 10% - 20% device life time used
+ 0x03 : 20% - 30% device life time used
+ 0x04 : 30% - 40% device life time used
+ 0x05 : 40% - 50% device life time used
+ 0x06 : 50% - 60% device life time used
+ 0x07 : 60% - 70% device life time used
+ 0x08 : 70% - 80% device life time used
+ 0x09 : 80% - 90% device life time used
+ 0x0A : 90% - 100% device life time used
+ 0x0B : Exceeded its maximum estimated device life time
+ *IMPORTANT* The disk cache should be used having the device
+ life time value from 0x01 to 0x05.
+*/
+int GetMemoryLifeTime() {
+ base::FilePath file_path(FILE_PATH_LITERAL("/sys/block/mmcblk0/life_time"));
+
+ base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ if (!file.IsValid())
+ return -1;
+
+ std::string buffer;
+ if (!base::ReadFileToString(file_path, &buffer))
+ return -1;
+
+ int life_time = static_cast<int>(strtol(buffer.c_str(), 0, 16));
+ return life_time;
+}
+
+// Reads the |header_size| bytes from the beginning of file |name|.
+bool ReadHeader(const base::FilePath& name, char* header, int header_size) {
+ base::File file(name, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ if (!file.IsValid())
+ return false;
+
+ int read = file.Read(0, header, header_size);
+ if (read != header_size)
+ return false;
+
+ return true;
+}
+
+int CalculateWebAppCacheSize(const base::FilePath& path, net::CacheType type) {
+ if (type != net::DISK_CACHE)
+ return -1;
+
+ // Only need to calculate the web app cache size, so skip the non web app.
+ if (path.value().find(kTizenAppCache) == std::string::npos)
+ return -1;
+
+ int total = 0;
+ base::FileEnumerator iter(path.DirName(), false,
+ base::FileEnumerator::DIRECTORIES);
+ for (base::FilePath app_name = iter.Next(); !app_name.value().empty();
+ app_name = iter.Next()) {
+ base::FilePath index_path = app_name.Append(kIndexName);
+ disk_cache::IndexHeader header;
+ if (!ReadHeader(index_path, reinterpret_cast<char*>(&header),
+ sizeof(header)))
+ continue;
+ total += header.num_bytes;
+ }
+
+ return total;
+}
+#endif
+
} // namespace disk_cache
namespace {
+#if BUILDFLAG(IS_TIZEN_TV)
+const double kCacheSizeMagic = 0.7;
+#endif
+
using FileEnumerator = disk_cache::BackendFileOperations::FileEnumerator;
using ApplicationStatusListenerGetter =
disk_cache::ApplicationStatusListenerGetter;
/*cache_thread = */ nullptr, type_, net_log_);
disk_cache::BackendImpl* new_cache = cache.get();
created_cache_ = std::move(cache);
+#if BUILDFLAG(IS_TIZEN_TV)
+ // In disk cache case, the cached resource size is about equal to 0.7 *
+ // file.size which file store cached resource in disk.
+ new_cache->SetMaxSize((double)max_bytes_ * kCacheSizeMagic);
+#else
new_cache->SetMaxSize(max_bytes_);
+#endif
new_cache->Init(
base::BindOnce(&CacheCreator::OnIOComplete, base::Unretained(this)));
return net::ERR_IO_PENDING;
std::unique_ptr<BackendFactory> backend_factory)
: net_log_(nullptr),
backend_factory_(std::move(backend_factory)),
-
+#if BUILDFLAG(IS_TIZEN_TV)
+ mode_(DISABLE),
+#else
+ mode_(NORMAL),
+#endif
network_layer_(std::move(network_layer)),
clock_(base::DefaultClock::GetInstance()) {
g_init_cache = true;
NetLog* net_log,
base::OnceCallback<void(disk_cache::BackendResult)> callback) = 0;
+#if BUILDFLAG(IS_TIZEN_TV)
+ virtual void UpdateWebAppDiskCachePath(const base::FilePath& cache_path) {}
+#endif
+
#if BUILDFLAG(IS_ANDROID)
virtual void SetAppStatusListenerGetter(
disk_cache::ApplicationStatusListenerGetter
NetLog* net_log,
base::OnceCallback<void(disk_cache::BackendResult)> callback) override;
+#if BUILDFLAG(IS_TIZEN_TV)
+ void UpdateWebAppDiskCachePath(const base::FilePath& cache_path) override {
+ path_ = cache_path;
+ }
+#endif
+
#if BUILDFLAG(IS_ANDROID)
void SetAppStatusListenerGetter(disk_cache::ApplicationStatusListenerGetter
app_status_listener_getter) override;
BackendType backend_type_;
const scoped_refptr<disk_cache::BackendFileOperationsFactory>
file_operations_factory_;
+#if BUILDFLAG(IS_TIZEN_TV)
+ // Web apps will have separated disk cache under this directory once web app
+ // id has set.
+ base::FilePath path_;
+#else
const base::FilePath path_;
+#endif
int max_bytes_;
bool hard_reset_;
#if BUILDFLAG(IS_ANDROID)
void set_mode(Mode value) { mode_ = value; }
Mode mode() { return mode_; }
+#if BUILDFLAG(IS_TIZEN_TV)
+ void UpdateWebAppDiskCachePath(const base::FilePath& cache_path) {
+ if (backend_factory_.get())
+ backend_factory_->UpdateWebAppDiskCachePath(cache_path);
+ }
+#endif
+
// Get/Set the cache's clock. These are public only for testing.
void SetClockForTesting(base::Clock* clock) { clock_ = clock; }
base::Clock* clock() const { return clock_; }
cache->set_mode(enable ? net::HttpCache::NORMAL : net::HttpCache::DISABLE);
}
+void NetworkContext::UpdateWebAppDiskCachePath(
+ const base::FilePath& cache_path) {
+#if BUILDFLAG(IS_TIZEN_TV)
+ url_request_context_->http_transaction_factory()
+ ->GetCache()
+ ->UpdateWebAppDiskCachePath(cache_path);
+#endif
+}
+
void NetworkContext::CreateCookieManager(
mojom::NetworkContextParamsPtr params) {
base::FilePath cookie_path;
void CreateCookieManager(mojom::NetworkContextParamsPtr params) override;
void SetCacheMode(bool enable) override;
+ void UpdateWebAppDiskCachePath(const base::FilePath& cache_path) override;
private:
class NetworkContextHttpAuthPreferences : public net::HttpAuthPreferences {
// Disable/Enable diskcache
SetCacheMode(bool enable);
+ UpdateWebAppDiskCachePath(mojo_base.mojom.FilePath cache_path);
};
#include <dlfcn.h>
#endif
+#include "base/path_service.h"
#include "browser/favicon/favicon_database.h"
#include "browser/password_manager/password_helper_efl.h"
#include "browser/tizen_extensible_host.h"
network_context->SetCacheMode(enable);
}
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void UpdateWebAppDiskCachePathOnIOThread(
+ const std::string& app_id,
+ content::StoragePartition* storage_partition) {
+ base::FilePath cache_base_path;
+ if (!storage_partition)
+ return;
+
+ if (!base::PathService::Get(base::DIR_CACHE, &cache_base_path)) {
+ LOG(ERROR) << "Could not retrieve path to the cache directory";
+ return;
+ }
+
+ auto network_context = storage_partition->GetNetworkContext();
+ if (!network_context)
+ return;
+
+ network_context->UpdateWebAppDiskCachePath(
+ cache_base_path.AppendASCII(disk_cache::kTizenAppCache).Append(app_id));
+}
+#endif
/**
* @brief Helper class for obtaining WebStorage origins
*/
command_line.AppendSwitchASCII(switches::kTizenAppId, tizen_app_id_);
#endif // IS_TIZEN_TV
#endif // IS_TIZEN
+
+#if BUILDFLAG(IS_TIZEN_TV)
+ // Since Web Browser also called ewk_context_tizen_app_id_set,
+ // so need to check the application type here.
+ if (application_type_ == EWK_APPLICATION_TYPE_TIZENWRT)
+ UpdateWebAppDiskCachePath(tizen_app_id_);
+#endif
} // LCOV_EXCL_LINE
/* LCOV_EXCL_START */
bool EWebContext::SetAppVersion(const std::string& tizen_app_version) {
break;
case EWK_APPLICATION_TYPE_TIZENWRT:
content::SetApplicationType(content::ApplicationType::TIZENWRT);
+ if (!tizen_app_id_.empty())
+ UpdateWebAppDiskCachePath(tizen_app_id_);
// Now some wrt apps use RGBA mode show transparent background
// have black issue, only when set support RGBA true can use this
// RGBA mode
return content::DevToolsUtilManager::GetPort();
}
+void EWebContext::UpdateWebAppDiskCachePath(const std::string& app_id) {
+ content::GetIOThreadTaskRunner({})->PostTask(
+ FROM_HERE,
+ base::BindOnce(&UpdateWebAppDiskCachePathOnIOThread, app_id,
+ browser_context()->GetDefaultStoragePartition()));
+}
+
bool EWebContext::ShowInspectorPortInfoState() {
if (!is_showing_mapping_info_)
return false;
Ewk_Context* ewk_context,
Ewk_Context_Intercept_Request_Callback callback,
void* user_data);
+ void UpdateWebAppDiskCachePath(const std::string& app_id);
#endif
void EnableAppControl(bool enabled);