| 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() {
|
|
|