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

Unified Diff: shell/application_manager/network_fetcher.cc

Issue 1088533003: Adding URLResponse Disk Cache to mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove unused function Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: shell/application_manager/network_fetcher.cc
diff --git a/shell/application_manager/network_fetcher.cc b/shell/application_manager/network_fetcher.cc
index 50b9e11943438c865b401f077b27bbfecc574007..ff6a64fd9944dc64b433019c075ee543264ca43b 100644
--- a/shell/application_manager/network_fetcher.cc
+++ b/shell/application_manager/network_fetcher.cc
@@ -29,10 +29,12 @@ namespace shell {
NetworkFetcher::NetworkFetcher(bool disable_cache,
const GURL& url,
mojo::NetworkService* network_service,
+ mojo::service_cache::ServiceCache* service_cache,
const FetchCallback& loader_callback)
: Fetcher(loader_callback),
disable_cache_(false),
url_(url),
+ service_cache_(service_cache),
weak_ptr_factory_(this) {
StartNetworkRequest(url, network_service);
}
@@ -148,14 +150,17 @@ bool NetworkFetcher::RenameToAppId(const GURL& url,
return base::Move(old_path, *new_path);
}
-void NetworkFetcher::CopyCompleted(
+void NetworkFetcher::CacheFileRetrieved(
base::Callback<void(const base::FilePath&, bool)> callback,
- bool success) {
+ mojo::Array<uint8_t> path_as_array,
+ mojo::Array<uint8_t> cache_dir) {
+ bool success = !path_as_array.is_null();
if (success) {
+ path_ = base::FilePath(std::string(
+ reinterpret_cast<char*>(&path_as_array.front()), path_as_array.size()));
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kPredictableAppFilenames)) {
// The copy completed, now move to $TMP/$APP_ID.mojo before the dlopen.
- success = false;
base::FilePath new_path;
if (RenameToAppId(url_, path_, &new_path)) {
if (base::PathExists(new_path)) {
@@ -176,17 +181,18 @@ void NetworkFetcher::CopyCompleted(
void NetworkFetcher::AsPath(
base::TaskRunner* task_runner,
base::Callback<void(const base::FilePath&, bool)> callback) {
+ // TODO(qsr) Test is not enough anymore -> we do not have anything while
+ // waiting for the service cache. This is fine for now, as AsPath is never
+ // called more than once.
if (!path_.empty() || !response_) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
return;
}
- base::CreateTemporaryFile(&path_);
- mojo::common::CopyToFile(
- response_->body.Pass(), path_, task_runner,
- base::Bind(&NetworkFetcher::CopyCompleted, weak_ptr_factory_.GetWeakPtr(),
- callback));
+ service_cache_->GetFile(response_.Pass(),
+ base::Bind(&NetworkFetcher::CacheFileRetrieved,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
std::string NetworkFetcher::MimeType() {

Powered by Google App Engine
This is Rietveld 408576698