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

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: Follow review 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
« no previous file with comments | « shell/application_manager/network_fetcher.h ('k') | shell/background_application_loader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ca5fdd80814cea315b885f59c4392a415f7602e1 100644
--- a/shell/application_manager/network_fetcher.cc
+++ b/shell/application_manager/network_fetcher.cc
@@ -26,13 +26,16 @@
namespace shell {
-NetworkFetcher::NetworkFetcher(bool disable_cache,
- const GURL& url,
- mojo::NetworkService* network_service,
- const FetchCallback& loader_callback)
+NetworkFetcher::NetworkFetcher(
+ bool disable_cache,
+ const GURL& url,
+ mojo::NetworkService* network_service,
+ mojo::URLResponseDiskCache* url_response_disk_cache,
+ const FetchCallback& loader_callback)
: Fetcher(loader_callback),
disable_cache_(false),
url_(url),
+ url_response_disk_cache_(url_response_disk_cache),
weak_ptr_factory_(this) {
StartNetworkRequest(url, network_service);
}
@@ -148,14 +151,17 @@ bool NetworkFetcher::RenameToAppId(const GURL& url,
return base::Move(old_path, *new_path);
}
-void NetworkFetcher::CopyCompleted(
+void NetworkFetcher::OnFileRetrievedFromCache(
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 +182,12 @@ void NetworkFetcher::CopyCompleted(
void NetworkFetcher::AsPath(
base::TaskRunner* task_runner,
base::Callback<void(const base::FilePath&, bool)> callback) {
- if (!path_.empty() || !response_) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
- return;
- }
+ // This should only called once, when we have a response.
+ DCHECK(response_.get());
- base::CreateTemporaryFile(&path_);
- mojo::common::CopyToFile(
- response_->body.Pass(), path_, task_runner,
- base::Bind(&NetworkFetcher::CopyCompleted, weak_ptr_factory_.GetWeakPtr(),
- callback));
+ url_response_disk_cache_->GetFile(
+ response_.Pass(), base::Bind(&NetworkFetcher::OnFileRetrievedFromCache,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
std::string NetworkFetcher::MimeType() {
« no previous file with comments | « shell/application_manager/network_fetcher.h ('k') | shell/background_application_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698